Is it double speak?

47

9

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.
  • Please include a link to an online interpreter.
  • 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

AJFaraday

Posted 2019-08-06T15:31:47.907

Reputation: 10 466

1Can the Booleans or integers be (consistently) reversed? 1 for non-double speak, 0 for double speak – Luis Mendo – 2019-08-06T15:33:30.490

1@LuisMendo Unusual, but sounds okay to me. – AJFaraday – 2019-08-06T15:34:37.837

6May we error on inputs of length < 2? – cole – 2019-08-06T16:06:17.480

3Suggested test case: abba which should be falsey – Giuseppe – 2019-08-06T16:29:11.277

2Suggested test case: aabbbb which should be truthy – Khuldraeseth na'Barya – 2019-08-06T17:30:04.397

I guess correct spelling is not an issue, so something like "lleetteerr" would be considered truthy, right? Even though this could come from a program that says "double all characters except 't'". – Corak – 2019-08-07T06:21:41.530

1@Corak that’s correct. We’re not interested in the validity of words, just whether the characters all repeat. – AJFaraday – 2019-08-07T06:23:24.110

1Can I use exit code (0/1) to output? Standard I/O rules allow that. – val says Reinstate Monica – 2019-08-07T08:26:16.307

2@val Well, I'm not going to argue with standard I/O – AJFaraday – 2019-08-07T08:27:01.467

2Suggested test case: 0 which should be falsey. – 640KB – 2019-08-07T16:06:26.637

1What about the empty string? – PieCot – 2019-08-07T21:04:17.770

Answers

58

Python 3, 24 bytes

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

Try it online!

Jitse

Posted 2019-08-06T15:31:47.907

Reputation: 3 566

25

brainfuck, 20 bytes

Saved 1 byte thanks to Jo King.

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

Try it online!

Readable output!

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.

Nitrodon

Posted 2019-08-06T15:31:47.907

Reputation: 9 181

If I could downvote comments I would downvote the above comment. – None – 2019-11-03T10:59:55.817

@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 – 2019-11-07T15:18:43.397

@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. – Emma - PerpetualJ – 2019-11-07T15:21:43.423

1@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 – 2019-11-07T15:24:33.190

17

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

Luis Mendo

Posted 2019-08-06T15:31:47.907

Reputation: 87 464

12Um... who is "Heda"? :D – Erik the Outgolfer – 2019-08-06T16:01:17.127

8"Heda" is German for "Hey! You!" – QBrute – 2019-08-09T12:47:45.067

14

05AB1E, 6 5 2 bytes

ιË

Input as a list of characters.

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

Try it online or verify a few more test cases.

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)

Kevin Cruijssen

Posted 2019-08-06T15:31:47.907

Reputation: 67 575

11

Japt, 4 bytes

ó r¶

Try it

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

Alternative

ó
¥o

Try it

Shaggy

Posted 2019-08-06T15:31:47.907

Reputation: 24 623

10

Retina, 9 bytes

(.)\1

^$

Try it online.

Explanation:

Remove all pair of the same characters:

(.)\1

Check if there are no characters left:

^$

Kevin Cruijssen

Posted 2019-08-06T15:31:47.907

Reputation: 67 575

1You can provide a more traditional output by using ^$ as your final stage. – Neil – 2019-08-06T16:38:00.103

@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 – 2019-08-06T16:42:36.783

8

Jelly, 3 bytes

ŒœE

Try it online!

Erik the Outgolfer

Posted 2019-08-06T15:31:47.907

Reputation: 38 134

1Hey 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 – 2019-08-07T14:21:19.237

8

Stax, 5 bytes

■◄┼$Δ

Run and debug it

Procedure:

  • Calculate run-lengths.
  • Get GCD of array.
  • Is even?

recursive

Posted 2019-08-06T15:31:47.907

Reputation: 8 616

Ahh, you got one that packs. Nice. – Khuldraeseth na'Barya – 2019-08-06T18:20:06.153

i like this algorithm! – Jonah – 2019-08-06T18:51:27.387

6

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, 61 56 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!

640KB

Posted 2019-08-06T15:31:47.907

Reputation: 7 149

1This appears to output 1 for a non-double speak string, as well as a double speak string. – AJFaraday – 2019-08-06T16:01:10.047

@AJFaraday try now - is double speak, is not double speak

– 640KB – 2019-08-06T16:07:59.577

6

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).

enter image description here

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.

enter image description here

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!

640KB

Posted 2019-08-06T15:31:47.907

Reputation: 7 149

2Suggest using LOOPE instead of JNZ/LOOP to save 2 bytes. – ErikF – 2019-08-07T16:11:16.807

@ErikF, brilliant! Completely forgot about that! – 640KB – 2019-08-07T16:17:27.907

6

Lua, 67 66 63 59 33 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.

HugoBDesigner

Posted 2019-08-06T15:31:47.907

Reputation: 161

1why not just i:gsub("(.)%1","") and check if i==""? – Giuseppe – 2019-08-08T16:26:52.163

1this is 34 bytes, not totally sure it's valid since I've never written Lua before, but it appears to work. – Giuseppe – 2019-08-08T16:27:46.303

welcome to Code Golf Stack Exchange though! – Giuseppe – 2019-08-08T16:28:10.370

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 – 2019-08-08T17:03:11.187

@Giuseppe Managed to chisel out one extra byte from your solution – HugoBDesigner – 2019-08-08T17:14:50.457

Very nice! I only asked since the R solution takes a similar gsub approach; glad to help you golf it down :-) – Giuseppe – 2019-08-08T17:48:29.690

1Nice idea! arg[1] can be replaced with (...) to save one byte. – val says Reinstate Monica – 2019-08-12T10:44:47.910

5

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!

Oliver

Posted 2019-08-06T15:31:47.907

Reputation: 7 160

24 bytes, but outputs an array for true, null for false: Try it online!

– wastl – 2019-08-06T16:52:52.157

27 bytes s=>!s.some((x,y)=>x>s[y|1]) – tsh – 2019-08-07T05:51:09.233

@tsh Unfortunately, that would only work if you replaced > with !=

– Oliver – 2019-08-07T15:48:18.220

5

Perl 5, 15 bytes

$_=/^((.)\2)*$/

Try it online!

Outputs 1 for double-speak, nothing for non-double-speak.

wastl

Posted 2019-08-06T15:31:47.907

Reputation: 3 089

5

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.

maxb

Posted 2019-08-06T15:31:47.907

Reputation: 5 754

5

Haskell, 28 23 bytes

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!

Khuldraeseth na'Barya

Posted 2019-08-06T15:31:47.907

Reputation: 2 608

4

Julia 1.0, 25 bytes

s->s[1:2:end]==s[2:2:end]

Try it online!

user3263164

Posted 2019-08-06T15:31:47.907

Reputation: 381

3It's shorter to use a symbol instead of f, e.g !a=.... Or to use an anonymous function: s->... – H.PWiz – 2019-08-06T15:54:42.317

Yes, you're right. I fixed it – user3263164 – 2019-08-07T15:15:36.627

4

V (vim), 7 bytes

ӈ±
ø^$

Try it online! or Verify test cases

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

James

Posted 2019-08-06T15:31:47.907

Reputation: 54 537

4

J, 13 11 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?

Jonah

Posted 2019-08-06T15:31:47.907

Reputation: 8 729

-:]#~2 0$~# – Adám – 2019-08-06T19:03:17.707

-:2#_2{.\] should save another byte – miles – 2019-08-07T22:51:10.177

very nice, thanks @miles – Jonah – 2019-08-07T22:56:37.263

4

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

AdmBorkBork

Posted 2019-08-06T15:31:47.907

Reputation: 41 581

1

de-duplicate Try it online!

– mazzy – 2019-08-07T04:19:10.460

1@mazzy Thanks! I was missing the $ before the statement block and couldn't figure out why it wasn't working. – AdmBorkBork – 2019-08-07T12:37:33.717

4

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.

Unrelated String

Posted 2019-08-06T15:31:47.907

Reputation: 5 300

4

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).


PowerShell, 48 bytes

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.

mazzy

Posted 2019-08-06T15:31:47.907

Reputation: 4 832

4

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).

Robin Ryder

Posted 2019-08-06T15:31:47.907

Reputation: 6 625

4

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!

manatwork

Posted 2019-08-06T15:31:47.907

Reputation: 17 865

The < should be a > – Lyxal – 2020-01-14T03:53:38.880

And, uh, 10 bytes with -rR flag

– Lyxal – 2020-01-14T03:56:55.710

6 bytes with -rR flag – Lyxal – 2020-01-14T03:58:34.033

For the sake of it, 5 bytes using -ir, -lp and -rR – Lyxal – 2020-01-14T04:01:48.173

3

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.

James

Posted 2019-08-06T15:31:47.907

Reputation: 54 537

Does 0/non0 count as a boolean? If so, you can do ({({}[{}]){{}}{}})

– Riley – 2019-08-06T18:15:53.887

3lol at the "Readable version" - its so very readable :P – Quinn – 2019-08-06T18:32:06.907

@riley No that's not valid. However, I found a better trick. – James – 2019-08-06T18:42:09.163

@quinn Looks readable to me :P – James – 2019-08-06T18:42:20.913

3

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!

Shaggy

Posted 2019-08-06T15:31:47.907

Reputation: 24 623

Fixed recursive version? – Arnauld – 2019-08-06T18:34:35.807

Thanks, @Arnauld :) – Shaggy – 2019-08-06T18:50:26.047

@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 – 2019-08-06T18:51:35.220

3

R, 53 34 bytes

-19 bytes thanks to Giuseppe

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

Try it online!

Robert S.

Posted 2019-08-06T15:31:47.907

Reputation: 1 253

1I think gsub("(.)\\1","",a)=="" would do the trick as well; many others use the same regex. – Giuseppe – 2019-08-06T18:05:50.353

@Giuseppe This whole regex thing is pretty new to me. Thanks. – Robert S. – 2019-08-06T18:10:36.257

R + pryr gets you a 32-byter trivially modified from this answer.

– Khuldraeseth na'Barya – 2019-08-06T18:19:17.440

2If input can be taken as a vector, then function(a)!sum(rle(a)$l%%2) for 28 – MickyT – 2019-08-06T19:55:49.767

3

QuadR, 11 bytes

''≡⍵
(.)\1

Try it online!

''≡⍵ the result is an empty string when

(.)\1 a character followed by itself

 is replaced by nothing

Adám

Posted 2019-08-06T15:31:47.907

Reputation: 37 779

3

C# (Visual C# Interactive Compiler), 40 bytes

s=>s.Where((c,i)=>c!=$"{s}"[i|1]).Any()

Try it online!

Each character is tested against it's neighbor for inequality. If any inequalities exist, the result is false.

Since input is limited to printable ASCII characters, a control character is appended to input which is compared to the last character of an odd length string.

Outputs are reversed.

-3 bytes inspired by @Oliver

dana

Posted 2019-08-06T15:31:47.907

Reputation: 2 541

35 bytes? – Oliver – 2019-08-07T17:24:26.447

@Oliver - this throws an exception on inputs like a, aaa, aaaaa, etc. You might be into something though, I'll keep fiddling. – dana – 2019-08-07T22:31:18.047

1I was able to knock off a few bytes at least :) – dana – 2019-08-08T00:43:11.893

3

Red, 36 bytes

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

Try it online!

Longer alternative:

Red, 40 bytes

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

Try it online!

Galen Ivanov

Posted 2019-08-06T15:31:47.907

Reputation: 13 815

3

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..

qwertxzy

Posted 2019-08-06T15:31:47.907

Reputation: 101

145 bytes – Unrelated String – 2019-08-07T08:08:18.493

1...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 – 2019-08-07T08:17:51.430

3

Brain-Flak, 36 10 42 30 bytes

(<>)<>{({}[{}]<>){{}{}}{}<>}<>

Outputs 0 if it is double speak, and nothing if it isn't

-12 bytes thanks to Nitrodon

How it works

(<>) Pushes 0 to the second stack
<>   Swaps back to the first stack
{    Begins a loop that will run until the stack is empty
({}[{}]<>)    Pops the top two items off of the first stack and pushes their difference to the second stack
{{}{}}{}      If the difference is zero, it gets popped and nothing happens. 
If there difference is one, the zero that was put on at the beginning gets popped, so nothing will get outputted at the end 
<>   Swaps back to the first stack
}    End loop
<>   Swap to the second stack for output

Try it Online!

EdgyNerd

Posted 2019-08-06T15:31:47.907

Reputation: 1 106

Fixed both of the problems – EdgyNerd – 2019-08-07T15:11:09.903

({}<>)<>({}<>)({}[{}]) can be simplified to ({}[{}]<>). – Nitrodon – 2019-08-09T20:57:02.837

oh wow, no clue why I decided to pop and swap stacks twice, thanks :) – EdgyNerd – 2019-08-09T21:50:40.967

3

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!

GammaFunction

Posted 2019-08-06T15:31:47.907

Reputation: 2 838

3

Mathematica, 31 bytes

AllTrue[Length/@Split@#,EvenQ]&

This works by converting the input (an array of characters, according to @attinat) into a list of characters, splitting this list into sublists of contiguous identical elements, and checking that each sublist has an even number of elements.

Anti Earth

Posted 2019-08-06T15:31:47.907

Reputation: 151

1

An answer should be a full program or function; this is a snippet that requires s to be defined beforehand.

– attinat – 2019-08-07T19:34:50.637

@attinat fixed; I was adopting the convention used by other answers (and see with amusement you pointed this out after I asked about your exclusion of Characters@) – Anti Earth – 2019-08-07T19:40:42.733

28 bytes by using GCD instead of AllTrue. See also this n-speak solution. – Roman – 2019-08-13T18:37:31.507

128 bytes by using And instead of AllTrue. – Roman – 2019-08-13T21:17:21.760

3

Scala, 44 bytes

_.grouped(2).forall(t=>t.size>1&&t(0)==t(1))

Try it online!

cubic lettuce

Posted 2019-08-06T15:31:47.907

Reputation: 181

3

Cubix, 18 bytes

;U;;A-!/@/n\nW.\O?

Try it online! Outputs 1 if True and nothing if False.

I suppose that it is fitting that this is twice the length to my answer to the previous question

    ; U
    ; ;
A - ! / @ / n \
n W . \ O ? . .
    . .
    . .

Watch it run

  • A Put all input onto the stack
  • - subtract the TOS and start of the test loop
  • ! test result for 0
  • @ if not 0, halt (FALSE for double speak)
  • /;U;; if 0, pop subtraction result and top two items from the stack, u-turn sends it in the right direction.
  • !\n/? an ignored "if 0", reflect, negate, reflect and test for EOI (now 1)
  • O\/@ if positive (1) output and reflect a couple of times onto the halt (TRUE for double speak)
  • nW if negative, reverse the negation and shift lane onto the start of the test loop.

MickyT

Posted 2019-08-06T15:31:47.907

Reputation: 11 735

3

Gaia, 3 bytes

2Zy

Almost as trivial as the solution to the other challenge. Errors with an input size < 2, which was never confirmed to be allowed, so might be invalid.

Try it online!

2Z   Unzip input by 2
  y  All equal?

Unzipping by 2 basically undoes the result of interleaving 2 strings. So if two equal strings are interleaved, then it is doublespeak.

Business Cat

Posted 2019-08-06T15:31:47.907

Reputation: 8 927

2

K (oK), 12 bytes

Solution:

&/1==/'0N 2#

Try it online!

Explanation:

&/1==/'0N 2# / the solution
       0N 2# / reshape into Nx2 grid
    =/'      / equals (=) over (/) each (')
  1=         / equal to 1 (ie a match)
&/           / take the minimum

Extra:

  • (~).+0N 2# works(ish) for 10 bytes, but not if the only difference is a character on the end of one of the strings :(

streetster

Posted 2019-08-06T15:31:47.907

Reputation: 3 635

Wouldn't just &/=/'0N 2# work? – Traws – 2019-08-13T16:27:54.523

1

Not for odd-length input :(

– streetster – 2019-08-13T16:39:11.720

2

PowerShell, 27 24 bytes

-3 bytes thanks to mazzy

!($args-creplace"(.)\1")

Try it online!

Uses the regex method going around. If the string is emptied out, it will return true, otherwise false.

Veskah

Posted 2019-08-06T15:31:47.907

Reputation: 3 580

1

you can omit ,'' Try it online!

– mazzy – 2019-08-06T16:37:36.780

1@mazzy Ha ha, I'm smrt. Thanks – Veskah – 2019-08-06T16:40:48.837

2

SNOBOL4 (CSNOBOL4), 63 bytes

	I =INPUT
R	I LEN(1) . X
	I X X =	:S(R)
	OUTPUT =IDENT(I) 1
END

Try it online!

Matches the first character LEN(1) and saves it . to X. If I matches X concatenated with itself, it replaces that substring and repeats. If the remaining string is empty, IDENT(I,<implicit empty string>), then 1 is output, else nothing is output.

Giuseppe

Posted 2019-08-06T15:31:47.907

Reputation: 21 077

2

Charcoal, 10 bytes

⬤⪪S²⁼ι⮌…ι²

Try it online! Link is to verbose version of code. Outputs Charcoal's default boolean format, which is - for true and nothing for false. Explanation:

  S         Input string
 ⪪ ²        Split into substrings of length up to 2
⬤           All substrings
        ι   Current substring
       … ²  Extended to length 2
      ⮌     Reversed
    ⁼       Equals
     ι      Current substring
            Implicitly print

Neil

Posted 2019-08-06T15:31:47.907

Reputation: 95 035

2

Whitespace, 73 bytes

[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_input_as_character][T   T   T   _Retrieve][S N
S _Duplicate_input][S S S T S T S N
_Push_10][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_input_as_character][T   T   T   _Retrieve][T    S S T   _Subtract][N
T   S N
_If_0_Jump_to_Label_LOOP][S S S N
_Push_0][T  N
S T _Print_as_integer][N
S S S N
_Create_Label_EXIT]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Since Whitespace inputs one character at a time, the input should contain a trailing newline so it knows when to stop reading characters and the input is done.

Outputs 0 for falsey, or nothing for truthy.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Start LOOP:
  Character c = STDIN as character
  If(c == '\n'):
    Stop program
  Character d = STDIN as character
  If(c == d):
    Go to next iteration of LOOP
  Print 0

Kevin Cruijssen

Posted 2019-08-06T15:31:47.907

Reputation: 67 575

2

APL+WIN, 20 15 bytes

5 bytes saved thanks to Adam.

Prompts for input of string:

n≡(2×2|⍳⍴n)/n←⎕

Try it online! Courtesy of Dyalog Classic

Graham

Posted 2019-08-06T15:31:47.907

Reputation: 3 184

2

Stax, 6 5 bytes

╩3╦x╨

Run and debug it at staxlang.xyz!

Outputs integers. Zero for double speak and nonzero (one now!) otherwise, as allowed here. Replace 1I below with |e if you want the opposite behavior, but I think this version looks nicer.

Unpacked (6 bytes) and explanation

:G|g1I
:G        Array of run lengths
  |g      GCD
    1I    Is odd? Could use 2% instead

The GCD of run lengths will be even exactly when all run lengths are.

Khuldraeseth na'Barya

Posted 2019-08-06T15:31:47.907

Reputation: 2 608

2

PHP, 37 40 bytes

+3 bytes to fix '0' issue

<?=''==preg_replace('/(.)\1/','',$argn);

Try it online!

Similar to other RegEx answers.


PHP, 55 bytes

for(;($l=$argn[$i++])==$argn[$i++]&&$l.$l;);echo$l=='';

Try it online!

Loops to the end of the string as long as every even character (0th, 2nd, 4th, etc ...) is equal to the character after it, else stops the loop. Finally, checks if it has arrived at the end of the string, which means the string is a double speak.


Outputs 1 for double speak and nothing for not double speak.

Night2

Posted 2019-08-06T15:31:47.907

Reputation: 5 484

Your first one is close, but it negates the resulting string. "0" is falsey in PHP, so an input of "000" will be deemed doublespeak – aross – 2019-08-08T09:59:33.857

@aross: Thanks for pointing it out, yeah that '0' == false is always an issue. Fixed! – Night2 – 2019-08-08T11:38:06.087

2

dzaima/APL, 14 11 bytes

⊢≡⊢⌿⍨2 0⍴⍨≢

Try it online!

-3 thanks to Adám!

dzaima

Posted 2019-08-06T15:31:47.907

Reputation: 19 048

2

Kotlin, 56 52 bytes

{it.chunked(2).filter{it.toHashSet().size>1}.size<1}

Try it online!

Thank you Khuldraeseth na'Barya for saving 4 bytes

FunkySyntax

Posted 2019-08-06T15:31:47.907

Reputation: 31

Save a handful. Welcome to the site! – Khuldraeseth na'Barya – 2019-08-06T20:19:31.060

2

Pip, 31 bytes

a:qFb,#a{b%2?x(ab+1)Qa@b?xi:1}i

Try it online!

slightly different approach with fold operator, 31 bytes

a:qFb,#a{I!b%2i:$Q[a@b(ab+1)]}i

outputs 0 if double speak, 1 otherwise

Kenneth Taylor

Posted 2019-08-06T15:31:47.907

Reputation: 183

2

INTERCAL, 192 bytes

PLEASE,1<-#2DOCOMEFROM(2)DOWRITEIN,1DO.5<-#1$',1SUB#1'~#256PLEASE(1)NEXTDOREADOUT#1DOGIVEUP(1)DO(1002)NEXTDO.5<-#1$',1SUB#2'~,1SUB#2DO(3)NEXTDOREADOUT#0PLEASEGIVEUP(3)DO(1002)NEXT(2)DOFORGET#2

Try it online!

Output is done with INTERCAL's native "butchered Roman numerals", so the true output of 1 prints as \nI\n, and the false output of 0 prints as _\n\n.

I don't feel like writing out a full explanation at the moment, but the ungolfed code is here, I lifted the control flow from something I wrote earlier, and the gist of what it does is read two characters at a time from the input through the usually unhelpful "Turing Tape" I/O until either the first resulting number is 256 (in which case the entire input has been validated and has even length, so it is double-speak), or the second resulting number is not 0 (in which case the second character is different from the first or does not exist, and the input is not double-speak).

I think I might be able to restructure this to cut down on redundancy, but I'm not quite feeling up to that at the moment either.

Unrelated String

Posted 2019-08-06T15:31:47.907

Reputation: 5 300

2

C (gcc), 50 bytes

Returns 0 if double-speak (or empty string), truthy otherwise.

f(s,i)char*s;{for(i=*s;i&(i=*s++)&&i==*s++;);s=i;}

Try it online!

If the input string is assumed to always be at least 2 characters (gives incorrect result for single-character strings):

C (gcc), 38 bytes

f(char*s){while(*s&&*s++==*s++);s=*s;}

Try it online!

ErikF

Posted 2019-08-06T15:31:47.907

Reputation: 2 149

The second suggestion seems to treat single character strings the same as any other odd length strings? – Taemyr – 2019-08-08T07:30:02.283

Wouldn't putting s=i at the end of for braces (for(i=*s;i&(i=*s++)&&i==*s++;s=i) save you one ;? – Przemysław Czechowski – 2019-08-08T17:47:30.717

@PrzemysławCzechowski s=i is used to return the value: it's not part of the loop. I'm using i to capture the character value, so assigning it to s during the loop would mess up the pointer (and likely crash the program!) – ErikF – 2019-08-08T18:04:53.083

@ErikF my bad, I thought s=i is repeated in every iteration. – Przemysław Czechowski – 2019-08-08T18:23:52.310

2

Java (JDK), 64 bytes

s->{int i=s.length;for(;i>1;)i=s[--i]==s[--i]?i:i|1;return i<1;}

Try it online!

Explanations

s->{
 int i=s.length;
 for(;i>1;)                 // while the length is 2 or greater.
  i=s[--i]==s[--i]?i:i|1;   // check the 2 previous values. If they're identical, don't do anything. Else, make i odd so that it fails at the return.
 return i<1;                // i will be 0 only when the size is even and all characters were doubled.
}

Olivier Grégoire

Posted 2019-08-06T15:31:47.907

Reputation: 10 647

2

Perl 6, 14 bytes

{!S:g/(.)$0//}

Try it online!

Replaces all pairs of identical characters with nothing and then boolean NOTs the result to return true if is an empty string (i.e. all characters were next to an identical one), or false otherwise.

Jo King

Posted 2019-08-06T15:31:47.907

Reputation: 38 234

2

PHP, 51 50 38 bytes

echo preg_match("/^((.)\2)+$/",$argn);

Checks whether input matches pairs of chars where the chars in each pair are the same (using back ref).

Run like this:

echo 'dd00uubbllee' | php -nR 'echo preg_match("/^((.)\\2)+$/",$argn);';echo
  • -1 byte thanks to @manatwork
  • -12 bytes by using preg_match with back references.

aross

Posted 2019-08-06T15:31:47.907

Reputation: 1 583

Wouldn't /.(.?)/ be enough to handle odd length strings? – manatwork – 2019-08-08T09:29:47.420

@manatwork you're right, thanks – aross – 2019-08-08T09:32:26.140

2

Malbolge (unlimited memory access variant), Around 4 megabytes

You asked the golfers, but for the second time forgot about the bowlers.

This is too big to include in the answer for obvious reason so here is gist link.

You might want to use the fast interpreter to test this program, as it's hellishly slow (hellishly, get it?). I'm going to include the TIO.run link after Dennis (hopefully) takes on my issue on TIO tracker.

// Edit: Nope, no TIO link as the answer size limit is 65536 bytes, and no abusing url shorteners because they just refuse to shorten it

Krzysztof Szewczyk

Posted 2019-08-06T15:31:47.907

Reputation: 3 819

what is this monstrosity :) – streetster – 2019-08-13T16:45:40.073

2

Pushy, 13 bytes

LL2%}2/:=};P#

Try it online!

L              \ Push len(input)
 L2%           \ Take (len(input) + 1) % 2. This will be 1 only if the input had even length.
    }          \ Move this to the bottom of the stack for later.
     2/:  ;    \ Length of original input, divided by 2, times do:
        =      \    Pop top two characters, and check equality. (Pushes 0 or 1)
         }     \    Move this to the bottom of the stack for later.
           P   \ Push the stack's product. If the input had odd length, or any two characters
               \ did not match, then the stack will contain a 0, so the product will be 0.
               \ Else, it will be 1.
            #  \ Print the product.  

FlipTack

Posted 2019-08-06T15:31:47.907

Reputation: 13 242

2

naz, 50 bytes

2a2x1v1x1f1r3x1v2e2x2v1r3x2v1e0m1o0x1x2f0m1a1o0x1f

Works for any input string, provided it's passed as a file terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v                       # Set variable 1 equal to 2
1x1f1r3x1v2e                 # Function 1
                             # Read a byte and jump to function 2 if it equals variable 1
            2x2v             # Otherwise, store it in variable 2
                1r3x2v1e     # Read another byte
                             # Jump back to the start of function 1 if it equals variable 2
                        0m1o # Otherwise, output 0
1x2f0m1a1o                   # Function 2
                             # Output 1
1f                           # Call function 1

sporeball

Posted 2019-08-06T15:31:47.907

Reputation: 461

2

Burlesque, 8 bytes

J2en)J==

Try it online!

                           [AABBCC]         [ABC]
J   #Duplicate             [AABBCC,AABBCC]  [ABC,ABC]
2en #Every other character [AABBCC,ABC]     [ABC,AC]
)J  #Duplicated            [AABBCC,AABBCC]  [ABC,AACC]
==  #Is the same           [1]              [0]

Burlesque, 11 bytes

=[{L[2dv}al

Try it online!

=[   # Group consecutive like values
{
 L[  # Length of (group)
 2dv # Divisible by 2
}al  # All

DeathIncarnate

Posted 2019-08-06T15:31:47.907

Reputation: 916

1

Befunge-98 (PyFunge), 11 bytes

~#@~# -_#q1

Try it online!

Returns 1 if double speak, 0 if not.

10 byte solution which returns 0 for double speak and non-0 otherwise:

~#q~#1-_#q

Try it online!

negative seven

Posted 2019-08-06T15:31:47.907

Reputation: 1 931

1

Python 3, 75 bytes

lambda s:all[([s[2*i]==s[2*i+1]for i in range(int(len(s)/2))]),0][len(s)%2]

Try it online!

Dat

Posted 2019-08-06T15:31:47.907

Reputation: 879

1

Kotlin, 59 57 bytes

{s->(0..s.length-1 step 2).fold(""){t,c->t+s[c]+s[c]}==s}

Try it online!

-1 byte thanks to Khuldraeseth na'Barya

-1 byte changing it -> s


Slightly lazy attempt - basically just took my answer from the doublespeak question, applied it to every second char of the input and see if the result is the input.

Quinn

Posted 2019-08-06T15:31:47.907

Reputation: 1 153

Save a byte – Khuldraeseth na'Barya – 2019-08-06T19:25:31.647

@Khuldraesethna'Barya updated, thanks! did not know that was a thing – Quinn – 2019-08-06T19:32:30.187

1

Wolfram Language (Mathematica), 27 26 24 bytes

2==GCD@@Length/@Split@#&

Try it online!

        Length/@Split@#&    (*for the lengths of runs of characters*)
2==GCD@@                    (*check that they are all even*)

attinat

Posted 2019-08-06T15:31:47.907

Reputation: 3 495

You've excluded the necessary code to convert the string input into a list which can be fed to Split (i.e. the 11 bytes of Characters@) – Anti Earth – 2019-08-07T17:14:55.100

@AntiEarth What's a string?

– attinat – 2019-08-07T19:30:17.107

1

Ruby -n, 21 14+1 = 15 bytes

p~/^((.)\2)*$/

Try it online!

G B

Posted 2019-08-06T15:31:47.907

Reputation: 11 099

1

Lua, 90 87 86 82 bytes

a,e=1,os.exit;(...):gsub('.',load's=...a=a~=1 and(a==s and 1 or e(1))or s')e(a==1)

Try it online!

Take input as argument, use exit code as output.

Explanation

This is based on abusing few Lua features:

  • os.exit could accept either number, allowing short code for exit or boolean, making last check possible (true meaning success, false meaning failure).
  • gsub can be also used to iterate over string in callback-style, not only for doing replacement.
  • load is shorter than function(...) end.
  • ... is often shorter than arg[1].

Whole idea hidden behind those tricks:

  1. For each character: either remember if nothing is already it or perform check: if current is different from remembered, fail. Otherwise, reset remembered value and continue.
  2. When done, make sure that there's nothing pending in the buffer (e(a==1)). This is required to fail on strings with odd length.

val says Reinstate Monica

Posted 2019-08-06T15:31:47.907

Reputation: 409

1

Gema, 17 characters

?$1=
?=0@end
\Z=1

Outputs 1 on double speak and 0 on not.

Sample run:

bash-5.0$ echo -n 'TThhiiss  iiss  ddoouubbllee  ssppeeaakk!!' | gema '?$1=;?=0@end;\Z=1'
1

Try it online!

Gema, 12 characters

?$1=
?=@fail

Terminates with exit code 0 on double speak and 2 on not.

Sample run:

bash-5.0$ echo -n 'TThhiiss  iiss  ddoouubbllee  ssppeeaakk!!' | gema '?$1=;?=@fail'
bash-5.0$ echo $?
0

Try it online!

manatwork

Posted 2019-08-06T15:31:47.907

Reputation: 17 865

1

C (tcc), 59 55 50 bytes

f(char *s){while(*s==*++s)s++;return!*--s&&s!="";}

Try it online!

Thanks to Jo King for the 4 bytes and Unrelated String for saving 5 bytes

Can it be even shorter?

Loki

Posted 2019-08-06T15:31:47.907

Reputation: 31

s==++s, how is this not UB when *s points to the end of the string? – Taemyr – 2019-08-07T11:26:33.930

the *s will always point to the last character of the string given in argument which is not last character because string here ends with '\0' so the *++s gets the \0 – Loki – 2019-08-07T11:36:00.493

1You increment s by two each time through the loop, so if there is an even number of actuall characters in the string I do not see how you can guarantee that *s never points to the '\0' – Taemyr – 2019-08-07T11:58:43.380

You could golf it considerably by replacing *--s=='\0' with the simple !*--s, but also note that most challenges require submissions to be either functions or full programs, and this is neither. – Unrelated String – 2019-08-07T19:37:15.620

Thanks guys for helping shortening it and @Taemyr play with this code TIO I don't need to care if *s gets the \0 character cause then the *++s will get the first character from the string used in printf.

– Loki – 2019-08-08T05:07:13.090

Although I don't know exactly how that works(if someone could explain thanks) and I tried it with putchar too changing printf to putchar also gives the *++s some character value. – Loki – 2019-08-08T05:09:20.120

@Loki I see no printf in your code. In the TIO you get the first char of whatever the compiler puts after the string you are looking at, so you are in UB. – Taemyr – 2019-08-08T06:48:32.767

1

Kotlin, 4649 bytes

-3 bytes thanks to @cubic lettuce

{it.chunked(2).all{it.length>1&&it[0]==it[1]}}

Try it online!

{it.length%2==0&&it.chunked(2).all{it[0]==it[1]}}

Try it online!

Brojowski

Posted 2019-08-06T15:31:47.907

Reputation: 141

1Save 3 bytes by {it.chunked(2).all{it.length>1&&it[0]==it[1]}} ;) – cubic lettuce – 2019-08-07T20:41:01.103

1

T-SQL 2012, 76 bytes

Looping using the following logic.

Finding the first match on the first character in the rest of the string.

If the match is on the second position, the first 2 characters are removed.

if the match is on a later position, character 0 to 1 is removed, resulting in null string.

If there are no matches, characters 3-4 are removed. Repeating this will eventually result in a null string.

The final string will be an empty string or a null string.

Empty string is "double speak"(1). Null string is not "double speak"(0).

DECLARE @ varchar(max)='ccbbddeeff'

WHILE @>''SET
@=stuff(@,-3/~charindex(left(@,1),@,2),2,'')PRINT
iif(@=0,1,0)

Try it online

t-clausen.dk

Posted 2019-08-06T15:31:47.907

Reputation: 2 874

1

Rust, 73 bytes

|s:&str|!s.chars().enumerate().any(|(i,c)|s.chars().nth(i|1).unwrap()!=c)

Try it online!

Berry M.

Posted 2019-08-06T15:31:47.907

Reputation: 121

1

C++ (gcc), 48 47 45 43 bytes

-2 bytes thanks to @ceilingcat
-2 bytes thanks to @JoKing

recursive function assuming zero terminated char table

int f(char*s){return!*s||*s==s[1]&&f(s+2);}

Try it online!

Przemysław Czechowski

Posted 2019-08-06T15:31:47.907

Reputation: 121

@ceilingcat cool, I didn't now you can be that concise – Przemysław Czechowski – 2019-08-09T08:02:18.900

@JoKing it works, there's just a warning because I'm using string literals to generate right kind of input - zero-terminated char* - which is not exactly legal in c++ but gcc allows it – Przemysław Czechowski – 2019-08-09T08:26:28.647

Ah sorry, I thought the lack of output meant it wasn't working. 43 bytes

– Jo King – 2019-08-09T08:36:41.513

1

EDIT:

This solution is totally broken as demonstrated by the aabbbb test case. Thanks to @manatwork for pointing this out. Do not pass Go! Do not collect 200 dollars!

Bash and Gnu utils, 46 45 bytes

fold -1|uniq -c|grep -qv "2 "&&echo 0||echo 1

Try it online!

-1 byte by skipping the first space in grep expression

Grzegorz Oledzki

Posted 2019-08-06T15:31:47.907

Reputation: 233

Not sure if I can use grep exit codes and return output there? Instead of this &&echo 0||echo1 – Grzegorz Oledzki – 2019-08-09T09:32:48.340

1

This works fine on the question's test cases, but as I understand the challenge, it should output 1 on Khuldraeseth na'Barya's suggested test case, “aabbbb”.

– manatwork – 2019-08-09T09:34:19.257

@manatwork You're right. This solution is buggy in that sense. – Grzegorz Oledzki – 2019-08-09T11:23:12.580

1

JavaScript (Node.js), 26 bytes

s=>!s.replace(/(.)\1/g,'')

Try it online!

user3335941

Posted 2019-08-06T15:31:47.907

Reputation: 41

1

Rust, 61 58 39 bytes

|s:&[u8]|s.chunks(2).all(|n|n[0]==n[1])

Try it online!

This is a closure that takes the input as a byte slice (b prefix on a string), e.g.

println!("{}", f(b"aabb"));

ruohola

Posted 2019-08-06T15:31:47.907

Reputation: 414

1

C++ (gcc), 156 145 bytes

#include <iostream>
int f(){
    char a[2]; while(std::cin.get(a, 3)) if(a[0] != a[1]) return 0; return 1;
}
int main()
{
    std::cout << f();
}

Try it online!

Ver Nick says Reinstate Monica

Posted 2019-08-06T15:31:47.907

Reputation: 555

Welcome to the site! C++ is pretty lenient about whitespace so you can save bytes by removing a bunch of it. – Post Rock Garf Hunter – 2019-08-11T11:58:56.970

@SriotchilismO'Zaic Thank you! – Ver Nick says Reinstate Monica – 2019-08-11T17:12:14.707

1

Oracle SQL, 47 bytes

select*from t where regexp_like(x,'^((.)\2)+$')

It works with an assumption that input data is stored in a table t(x), e.g.

with t(x) as (select 'hheelllloo' from dual)

Returns either original string or no rows.

Dr Y Wit

Posted 2019-08-06T15:31:47.907

Reputation: 511

1

Swift, 109 bytes

func a(b:String){let c=Array(b),l=c.count;var d=0,i=0;while i<l-1{if c[i]==c[i+1]{d+=1};i+=2;};print(d*2==l)}

Try it online!

onnoweb

Posted 2019-08-06T15:31:47.907

Reputation: 211

1

C#, 190 bytes

public class P{public static void Main(string[]a){bool d=true;if(a[0].Length%(double)2>0)d=false;else for(int i=0;i<a[0].Length;i+=2){d=a[0][i]==a[0][i+1]?d:false;}System.Console.Write(d);}}

Try Online

canttalkjustcode

Posted 2019-08-06T15:31:47.907

Reputation: 131

1

Clojure, 48 bytes

(fn[x](every? #(apply = %)(partition 2 2[\0]x)))

Try it online!

Thoma

Posted 2019-08-06T15:31:47.907

Reputation: 71

1

GolfScript, 7 bytes

2/zip~=

Try it online!

Explanation

2/      # Split input into parts of 2,            e.g. tt,ee,ss,tt
  zip   # Read the list horizontally,         yielding test, test
     ~  # Put the two strings onto the stack, yielding test,test
      = # Check whether they are equal,       yielding 1

# False case:
#  tteesst
#->tt,ee,ss,t
#->test,tes
#->0
```

user85052

Posted 2019-08-06T15:31:47.907

Reputation: