# Is it double speak?

In an earlier challenge I asked code golfers to produce strings which copy each character in a string. For example:

TThhiiss  iiss  ddoouubbllee  ssppeeaakk!!


This challenge is simply to detect if some text meets the definition of a double speak string.

• There is an even number of characters.
• When split into pairs, every pair consists of two of the same character.

The challenge

• It's code golf, do it in few bytes.
• Use any language you choose.
• The code will accept some text.
• For simplicity, the input will only consist of printable ASCII characters
• It will return an indication of whether or not the input is double speak. It could be:
• A boolean
• Strings ('true', 'false', 'yes', 'no' etc)
• Integers 0 or 1

Test Cases:

• aba - false
• abba - false
• aabb - true
• aaabb - false
• tthhiiss - true
• ttthhhiiisss - false
• May we error on inputs of length < 2? – cole Aug 6 '19 at 16:06
• Suggested test case: abba which should be falsey – Giuseppe Aug 6 '19 at 16:29
• Suggested test case: aabbbb which should be truthy – Khuldraeseth na'Barya Aug 6 '19 at 17:30
• @val Well, I'm not going to argue with standard I/O – AJFaraday Aug 7 '19 at 8:27
• Suggested test case: 0 which should be falsey. – 640KB Aug 7 '19 at 16:06

# Python 3, 24 bytes

lambda s:s[::2]==s[1::2]


Try it online!

# brainfuck, 20 bytes

Saved 1 byte thanks to Jo King.

+>,[>,[-<->]<[<],]<.


Try it online!

Takes input two characters at a time, and moves away from the 1 on the tape if any pair doesn't match. EOF is treated as 0 and thus handled automatically.

Output is a null byte if the string is not double speak, and 0x01 if it is. The readable version outputs these as characters at a cost of 14 bytes.

• If I could downvote comments I would downvote the above comment. – user85052 Nov 3 '19 at 10:59
• @PerpetualJ A) It's a super popular esolang, I can't believe you haven't already heard of it B) That's not a reason to upvote – Redwolf Programs Nov 7 '19 at 15:18
• @RedwolfPrograms Per SE rules, you should upvote if the post was helpful, and it was helpful in teaching me the name of a language I had never heard of. Plus, it’s a great solution deserving of an upvote. – Candleshark Nov 7 '19 at 15:21
• @PerpetualJ Agreed that it's a great solution, but there are lots of esolangs with funny names and boring solutions (mostly BF variants) – Redwolf Programs Nov 7 '19 at 15:24

# MATL, 4 bytes

Heda


Input is a string, enclosed with single qoutes. Output is 0 for double speak, 1 otherwise.

Try it online!

### Explanation

Consider input 'TThhiiss iiss ddoouubbllee ssppeeaakk!!' as an example.

H    % Push 2
% STACK: 2
% Implicit input (triggered because the next function requires two inputs): string
% STACK: 'TThhiiss  iiss  ddoouubbllee  ssppeeaakk!!', 2
e    % Reshape as a 2-column matrix of chars, in column-major order. Pads with char(0)
% if needed. Note that char(0) cannot be present in the input
% STACK: ['This is double speak!';
'This is double speak!']
d    % Difference of each column
% STACK: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
a    % Any: gives 0 if and only if all elements are 0
% STACK: 0
% Implicit display

• Um... who is "Heda"? :D – Erik the Outgolfer Aug 6 '19 at 16:01
• "Heda" is German for "Hey! You!" – QBrute Aug 9 '19 at 12:47

# 05AB1E, 65 2 bytes

ιË


Input as a list of characters.

-3 bytes by porting @Shaggy's Japt answer, so make sure to upvote him!

Explanation:

ι   # Uninterleave the (implicit) input-list of characters
#  i.e. ["t","t","t","t","e","e","s","s","t","t","!","!","!"]
#   → [["t","t","e","s","t","!","!"],["t","t","e","s","t","!"]]
Ë  # Check if both inner lists are equal
#  → 0 (falsey)
# (after which the result is output implicitly)


# Japt, 4 bytes

ó r¶


Try it

ó r¶     :Implicit input of string
ó        :Uniterleave
r      :Reduce by
¶     :  Testing equality


## Alternative

ó
¥o


Try it

# Retina, 9 bytes

(.)\1

^$ Try it online. Explanation: Remove all pair of the same characters: (.)\1  Check if there are no characters left: ^$

• You can provide a more traditional output by using ^$ as your final stage. – Neil Aug 6 '19 at 16:38 • @Neil Ah of course, thanks! That indeed looks better. I always think it's strange outputting false as truthy and true as falsey (but if it saves a byte and it's allowed, I will still use it). ;) But since this is an equal bytes solution outputting the expected results, this is better. – Kevin Cruijssen Aug 6 '19 at 16:42 # Jelly, 3 bytes ŒœE  Try it online! • Hey I like this! It took me 80mns to do the same lol, I was like "hey let's learn Jelly now" then I learned. I was about to post this but looked if Jelly answers were already there... and then saw this ^^ My steps: ¹©s2L€=2Ạa®s2E€Ạ... ḢƝs2E€Ạ... but I couldn't manage to get what I wanted, and then I saw Œœ lol – V. Courtois Aug 7 '19 at 14:21 # Stax, 5 bytes ■◄┼$Δ


Run and debug it

Procedure:

• Calculate run-lengths.
• Get GCD of array.
• Is even?
• Ahh, you got one that packs. Nice. – Khuldraeseth na'Barya Aug 6 '19 at 18:20
• i like this algorithm! – Jonah Aug 6 '19 at 18:51

# PHP, 58 56 bytes

function f($s){return!$s?:$s[0]==$s[1]&f(substr($s,2));}  Try it online! As a recursive function. # PHP, 6156 52 bytes while(''<$l=$argn[$i++])$r|=$l!=$argn[$i++];echo!$r;  Try it online! Or standalone program. Input string via STDIN, output is truthy (1) if it is double speak, and falsey (0) if it is not double speak. -4 bytes thx to @Night2! • This appears to output 1 for a non-double speak string, as well as a double speak string. – AJFaraday Aug 6 '19 at 16:01 • @AJFaraday try now - is double speak, is not double speak – 640KB Aug 6 '19 at 16:07 # x86 machine code, 9 7 bytes D1 E9 SHR CX, 1 ; divide length in half AD LODSW ; load next two chars into AH/AL 3A E0 CMP AH, AL ; compare AH and AL E1 FB LOOPE -5 ; if equal, continue loop  Input string in SI, input string length in CX. Output ZF if is double speak. ### Or 14 bytes as a complete PC DOS executable: B4 01 MOV AH, 01H ; DOS read char from STDIN (with echo) CD 21 INT 21H ; read first char into AL 92 XCHG DX, AX ; put first char into DL B4 08 MOV AH, 08H ; DOS read char from STDIN (no echo) CD 21 INT 21H ; read second char into AL 3A C2 CMP AL, DL ; compare first and second char 74 F3 JE -13 ; if the same, continue loop C3 RET ; otherwise exit to DOS  Input is via STDIN, either pipe or interactive. Will echo the "de-doubled" input until a non-doubled character is detected, at which point will exit (maybe bending I/O rules a little bit, but this is just a bonus answer). Build and test ISDBL2.COM using xxd -r: 00000000: b401 cd21 92b4 08cd 213a c274 f3c3 ...!....!:.t..  ### Original 24 bytes complete PC DOS executable: D1 EE SHR SI, 1 ; SI to DOS PSP (080H) AD LODSW ; load string length into AL D0 E8 SHR AL, 1 ; divide length in half 8A C8 MOV CL, AL ; put string length into BL CLOOP: AD LODSW ; load next two chars into AH/AL 3A E0 CMP AH, AL ; compare AH and AL E1 FB LOOPE CLOOP ; if equal, continue loop DONE: B8 0E59 MOV AX, 0E59H ; BIOS tty function in AH, 'Y' in AL 74 02 JZ DISP ; if ZF, result was valid double B0 4E MOV AL, 'N' ; if not, change output char to N DISP: B4 0E MOV AH, 0EH CD 10 INT 10H C3 RET ; return to DOS  Input from command line, output to screen 'Y' if double, 'N' if not. Build and test ISDBL.COM using xxd -r: 00000000: d1ee add0 e88a c8ad 3ae0 e1fb b859 0e74 ........:....Y.t 00000010: 02b0 4eb4 0ecd 10c3 ..N.....  ### Credits: • -2 bytes thx to @ErikF! • Suggest using LOOPE instead of JNZ/LOOP to save 2 bytes. – ErikF Aug 7 '19 at 16:11 • @ErikF, brilliant! Completely forgot about that! – 640KB Aug 7 '19 at 16:17 # Lua, 6766635933 32 bytes -25 bytes thanks to Giuseppe -1 byte thanks to val print(#(...):gsub("(.)%1","")<1)  Try it online! Removes every doubled character, then checks if the result is empty. • why not just i:gsub("(.)%1","") and check if i==""? – Giuseppe Aug 8 '19 at 16:26 • this is 34 bytes, not totally sure it's valid since I've never written Lua before, but it appears to work. – Giuseppe Aug 8 '19 at 16:27 • welcome to Code Golf Stack Exchange though! – Giuseppe Aug 8 '19 at 16:28 • I assumed that "(.)%1" by itself included collisions, but it didn't occur to me that by replacing it once for all captures would be enough. Should I implement your solution or should you write your own answer? And thanks! – HugoBDesigner Aug 8 '19 at 17:03 • Nice idea! arg[1] can be replaced with (...) to save one byte. – val says Reinstate Monica Aug 12 '19 at 10:44 # Perl 5, 15 bytes $_=/^((.)\2)*$/  Try it online! Outputs 1 for double-speak, nothing for non-double-speak. # MathGolf, 2 bytes ½=  Try it online! Basically the same as the 05AB1E answer, ½ splits the string into even and odd characters, then check for equality. Passes for the empty string. # JavaScript, 28 bytes s=>s.every((x,y)=>x==s[y|1])  Try it online! 23 bytes using wastl's regex s=>/^((.)\2)*$/.test(s)


Try it online!

f(x:y:z)|x==y=f z
f[]=1


Try it online!

Very straightforward. Double speak is only empty or a repeated character prepended to double speak.

Less straightforward now. Outputs via presence or absence of an error, per meta consensus; no error means double speak. Pattern matching fails when the first two characters differ or when there are an odd number of characters. Thanks to Laikoni for these savings!

# V (vim), 7 bytes

Óˆ±
ø^$ Hexdump: 00000000: d388 b10a d85e 24 .....^$


Just two regexes. Explanation:

Ó   " Remove all occurrences...
ˆ  "   Any character
± "   Followed by itself
"   This regex is actually just the compressed form of (.)\1
ø   " Count the number of matches
^$" An empty line  # Brachylog, 5 bytes ġ₂z₂=  Try it online! Succeeds or fails. ġ₂ The at-most-length-2 chunks of the input, z₂ which have equal length, zipped together, = are equal.  # PowerShell, 39 38 bytes !$($args|?{+$p*($p="$_"[$p-eq$_])};$p)  Try it online! where $p contains a previous char.

No recursion, no regex :). Takes input as a char-array via a splatting string (see TIO link).

for(;$b-eq$a-and$args){$a,$b,$args=$args}$b-eq$a  Try it online! No recursion, no regex and no pipe :D. It also takes input as a char-array via a splatting string. It uses $b-eq$a instead $a-eq$b for a case when a last char has #0 code. # PowerShell, 64 59 bytes filter f($n){$a,$b,$r=$n;$a-eq$b-and$(if($r){f $r}else{1})}  Try it online! Recursive function, no regex. Takes input as a char-array (see TIO link). Peels off the first two elements into $a and $b, stores the remaining into $r. If we still have elements remaining, recurse along with $a -eq$b. Otherwise just check whether $a -eq$b. Output is implicit.

-5 bytes thanks to mazzy

• de-duplicate Try it online! – mazzy Aug 7 '19 at 4:19
• @mazzy Thanks! I was missing the $ before the statement block and couldn't figure out why it wasn't working. – AdmBorkBork Aug 7 '19 at 12:37 # Julia 1.0, 25 bytes s->s[1:2:end]==s[2:2:end]  Try it online! • It's shorter to use a symbol instead of f, e.g !a=.... Or to use an anonymous function: s->... – H.PWiz Aug 6 '19 at 15:54 • Yes, you're right. I fixed it – Simeon Schaub Aug 7 '19 at 15:15 # J, 1311 10 bytes -:2#_2{.\]  Try it online! -2 bytes thanks to Adám -1 byte thanks to miles TLDR explanation: Is the input the same as every other character of the input doubled? • -:]#~2 0$~# – Adám Aug 6 '19 at 19:03
• -:2#_2{.\] should save another byte – miles Aug 7 '19 at 22:51
• very nice, thanks @miles – Jonah Aug 7 '19 at 22:56

# Shakespeare Programming Language, 204 156 bytes

-48 bytes thanks to Jo King (mostly by changing the output method)

A.Ajax,.Puck,.Act I:.Scene I:.[Exeunt][Enter Ajax and Puck]Ajax:Open mind.Puck:Open
mind.Is I worse zero?If soSpeak thy.Is you as big as I?If soLet usAct I.


Try it online!

Exits with error if the input is double speak, and with warning if it is not double speak (which is allowed by default).

# Keg, 19 17 characters

?{!1<|=[|0.(_)]}1


Explanation:

?             # read input

{             # while
!1<       # stack length greater than 1?
|             # end of while condition and beginning of while block
=         # compare the 2 top values in the stack
[         # if (the condition is the top of stack)
|         # end of then block and beginning of else block
0.    # output 0
(_)   # clear stack (discard top of stack in for loop stack length times)
]         # end if
}             # end while

1             # stack is already empty, push a truthy value

# implicitly output the stack content if there was no explicit output


Try it online!

# R, 53 34 bytes

-19 bytes thanks to Giuseppe

function(a)gsub("(.)\\1","",a)==""


Try it online!

• I think gsub("(.)\\1","",a)=="" would do the trick as well; many others use the same regex. – Giuseppe Aug 6 '19 at 18:05
• @Giuseppe This whole regex thing is pretty new to me. Thanks. – Robert S. Aug 6 '19 at 18:10
• R + pryr gets you a 32-byter trivially modified from this answer. – Khuldraeseth na'Barya Aug 6 '19 at 18:19
• If input can be taken as a vector, then function(a)!sum(rle(a)$l%%2) for 28 – MickyT Aug 6 '19 at 19:55 # Brain-Flak, 26, 22 bytes ({<({}[{}])>{()<>}{}})  Try it online! Outputs 1 for false and 0 for true. Readable version: ({ <({}[{}])> { () <> } {} })  I originally had this: { ({}[{}]) { <>([()])<>{{}} }{} } <>({}())  Which is 10 bytes longer. • Does 0/non0 count as a boolean? If so, you can do ({({}[{}]){{}}{}}) – Riley Aug 6 '19 at 18:15 • lol at the "Readable version" - its so very readable :P – Quinn Aug 6 '19 at 18:32 • @riley No that's not valid. However, I found a better trick. – James Aug 6 '19 at 18:42 • @quinn Looks readable to me :P – James Aug 6 '19 at 18:42 # QuadR, 11 bytes ''≡⍵ (.)\1  Try it online! ''≡⍵ the result is an empty string when (.)\1 a character followed by itself is replaced by nothing # JavaScript, 26 23 bytes s=>/^((.)\2)+$/.test(s)


Try it online!

## Recursive Solution, 30 bytes

Thanks to Arnauld for a fix at the cost of 0 bytes.

f=([x,y,...s])=>x?x==y&f(s):!y


Try it online!

• – Arnauld Aug 6 '19 at 18:34
• Thanks, @Arnauld :) – Shaggy Aug 6 '19 at 18:50
• @Oliver, crap; only saw your original solution before posting mine. I'm happy to roll back to 26 if you got to that 23 before me - let me know. – Shaggy Aug 6 '19 at 18:51

# Red, 36 bytes

func[s][parse s[any[copy t skip t]]]


Try it online!

# Red, 40 bytes

func[s][(extract s 2)= extract next s 2]


Try it online!

# Zsh, 36 bytes

My Zsh answer to the previous challenge can be found here.

Exits truthy (0) if NOT double speak, and falsy (1) if double speak. (As allowed in a comment.)

for a b (${(s::)1})r+=${a#$b} [$r ]


for a b (${(s::)1})r+=${a#$b}${(s::)1}             # split $1 characterwise for a b ( ) # take pairs of characters from${(s::)1}, assign to $a and$b
${a } # first character${ #$b} # remove second character as prefix r+= # append to$r as string
[ $r ] # exit truthy if$r is non-empty


Try it online!

# Prolog (SWI), 60 45 bytes

thanks to Unrelated String

+[].
+[A,A|T]:- +T.
-X:-string_chars(X,Y),+Y.


Try it online!

Converting it from a string to a list of atoms kind of ruined the score, but well..

• 45 bytes – Unrelated String Aug 7 '19 at 8:08
• ...it looks like you can also use atom_chars instead of string_chars, even though you're taking a string as input, and not an atom. But that may be irrelevant if you can take a backtick-delimited string--that is, a list of char codes. – Unrelated String Aug 7 '19 at 8:17