x86 machine code, 9 8 bytes
D1 E9 SHR CX, 1 ; divide length in half
L1:
AD LODSW ; load next two chars into AH/AL
3A E0 CMP AH, AL ; compare AH and AL
E1 FB LOOPE L1 ; if equal, continue loop
C3 RET ; return to caller
Callable function. 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:
abba
which should be falsey \$\endgroup\$aabbbb
which should be truthy \$\endgroup\$