# The Binary Eyes

A binary eye is an odd set of digits, with all of its digits except the center one set to 1 or 0, and the center one set to the opposite of the others. Thus, there are two binary eyes for a given odd number of digits:

x eyes
1 1,0
3 101,010
5 11011,00100
7 1110111,0001000
9 111101111,000010000

Make the smallest program possible, in any language, that prints out x number of binary eyes. For example, with an input of two, the program would output
1,0 and 101,010.
With 3 it should output that and the next, and with 4 the next as well, and so on. with 5 it should output the complete table above. You can also have it just continue giving outputs, as long as it outputs only correct outputs, and at least the number of outputs asked for.

• Since we can output just "at least the number of outputs asked for", can we just output every possible binary eye, infinitely, and ignore the input? Apr 23 at 19:04
• Yes, you can pxeger Apr 23 at 19:12
• Based on the pattern, wouldn't it make more sense that n=1 output 0,1 instead of 1,0? Apr 23 at 20:25
• @dingledooper I thought the order didn't matter? Apr 23 at 22:21
• Would it be acceptable to output a list or string of 2n bits with the same separator between each of them? For example, for n=5 [1,1,0,1,1,0,0,1,0,0] or "1101100100"? Apr 25 at 16:50

# Python 3, 45 bytes

n=1
while[print(f'{0:1^{n}},{1:0^{n}}')]:n+=2


Try it online!

# Python, 48 bytes

s,t="01"
while[print(s,t)]:s,t=f"1{s}1",f"0{t}0"

Attempt This Online!

-5 thanks to @loopy walt

# JavaScript (V8), 42 bytes

for([s,t]='01';!print(s,t);t=0+t+0)s=1+s+1


Try it online!

-9 bytes using the same trick loopy walt suggested for the Python answer.

• Seems cheaper to write everything twice: ato.pxeger.com/… Apr 23 at 19:16
• @tsh that doesn't print the first ones, 0 and 1 Apr 24 at 5:41

g[0]
g x=x:map(0^)x:g(1:x++[1])


Try it online!

Infinite sequence

• The problem statement flips the first two entries. Apr 25 at 11:36
• @Jonathan Frech seems that the order doesn't matter , other answers doesn't have same order too Apr 25 at 12:04

# Jelly, 6 bytes

ṬŒḄ¬Ƭ)


Try it online!

Add another byte if the pairs can't be backwards.

# Factor + combinators.extras, 69 bytes

"0""1"[ 2dup ","glue print "1""1"rot "0""0"[ surround ] 3bi@ t ] loop


Try it online!

## Explanation

Outputs increasing binary eyes forever. In older versions of Factor (such as the build on TIO), whitespace is not required after strings.

##### The combinators
• [ ... t ] loop Do ... forever.
• 3bi@ Apply a quotation to two sets of three things.
"0""1"             ! "0" "1"
2dup               ! "0" "1" "0" "1"
"," glue           ! "0" "1" "0,1"
print              ! "0" "1"         (output w/ newline)
"1""1"             ! "0" "1" "1" "1"
rot                ! "0" "1" "1" "1"
"0""0"             ! "0" "1" "1" "1" "0" "0"
[ surround ] 3bi@  ! "101" "010"
(and so forth...)


# x86-64 machine code, 32 bytes

31 D2 B8 31 34 01 AA 34 01 89 D1 F3 AA F6 DC 78 F3 C6 07 0A AE 7B F0 FF C2 39 F2 75 EA 88 0F C3


Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address at which to place the result, as a null-terminated byte string, and takes the input number in ESI.

In assembly:

f:  xor edx, edx    # Set EDX to 0.
.byte 0xB8, 0x31# These bytes combine with the next two instructions to form
#  mov eax, 0xAA013431. In particular, the lowest byte (AL) is 0x31 ('1')
#  and the second-lowest byte (AH) is 0x34, which is positive.
a:  xor al, 1       # Change AL from '0' to '1' or vice versa.
stosb           # Write AL to the string, advancing the pointer.
b:  xor al, 1       # Change AL from '0' to '1' or vice versa.
mov ecx, edx    # Set ECX to EDX.
rep stosb       # Write AL to the string that many times, advancing the pointer.
neg ah          # Negate the value of AH.
js a            # Jump if it is negative (every other time).
mov BYTE PTR [rdi], 10  # Put 10 (line feed) at the current output address.
scasb           # Set flags based on AL minus that value, advancing the pointer.
jpo b           # Jump if that has an odd number of 1 bits,
#  true if AL is '0' and not if AL is '1'.
inc edx         # Add 1 to EDX.
cmp edx, esi    # Compare that with the input number.
jne b           # Jump if they are not equal.
mov [rdi], cl   # Put the low byte of ECX, which is 0
#  (REP STOSB counts it down to 0), at the current output address.
ret             # Return.


# VyxalM, 6 bytes

ƛÞǔ∞₍†


Try it Online!

ƛÞǔḂḢJ:†"
ƛ        # Map implicit input (implicit range, flag M means inclusive zero range)
Þǔ      # Untruth
∞     # Palindromise
₍†   # Parallel wrap apply with vectorised NOT


# Retina 0.8.2, 32 bytes

.+
$* 1$0$¶$0$¶ T10d¶.+¶  Try it online! Explanation: .+$*


Convert n to unary using the Retina 0.8.2 default character of 1.

1
$0$¶$0$¶


Create all of the prefixes of n 1s, and wrap 0 with them, duplicating each time.

T10d¶.+¶


Switch the 1s and 0s over in alternate duplicates.

# Charcoal, 13 bytes

ＥＮＥ²⪫Ｅ²⭆ι¬λＩλ


Try it online! Link is to verbose version of code. Explanation:

 Ｎ              First input as a number
Ｅ               Map over implicit range
²            Literal integer 2
Ｅ             Map over implicit range
²         Literal integer 2
Ｅ          Map over implicit range
ι       Outer index
⭆        Map over implicit range and join
λ     Inner index
¬      Logical Not
⪫           Joined by
λ   Inner index
Ｉ    Cast to string
Implicitly print


# PARI/GP, 51 bytes

i=!o=0;while(!print(o","i),o=Str(1o,1);i=Str(0i,0))

Attempt This Online!

# PARI/GP, 57 bytes

for(i=0,oo,printf("%o,%0"j=2*i+1"o\n",(8^j-1)/7-k=8^i,k))

Attempt This Online!

I don't understand why printf doesn't support binary.

# Perl 5 + -M5.10.0, 30 bytes

Outputs infinitely ignoring input.

$,.=0while$}.=say"$}0$} $,1$,"

Try it online!

## Explanation

Uses a while loop where the condition appends the result of calling say (which is 1) to $} which will always be truthy and the body appends 0 to $,.

## Batch, 111 bytes

@set/ai=1,o=0
@for /l %%i in (1,1,%1)do @call:c
@exit/b
:c
@echo %i%
@echo %o%
@set i=0%i%0
@set o=1%o%1


Unfortunately string substitution fails for unset (i.e. empty) strings, otherwise the following would work for 108 bytes:

@set s=
@for /l %%i in (1,1,%1)do @call:c
@exit/b
:c
@echo %s%1%s%
@echo %s:0=1%0%s:0=1%
@set s=0%s%


# Bash, 50 bytes

s=0;t=1;while echo $s$t;do t=0${t}0;s=1${s}1;done


Try it online!

# R, 56 bytes

a=0
b=1
[=paste0
repeat{cat(a,b,"")
a=1[a,1]
b=0[b,0]}


Try it online!

Takes no input and outputs binary eyes separated by spaces.

# Common Lisp, 65 bytes

(do((i 1(+ 2 i)))(())(format t"~v,,,'1:@<0~> ~v,,,'0:@<1~> "i i))


Try it online!

Explanation

Infinite loop, does not read input. It works by centering a 0 (resp. a 1) using the ~:@<...~> directive in a field of size 2i + 1, where the padding character is a 1 (resp. a 0).

# C (GCC), 90 bytes

n;main(b,i){for(;++n;)for(b=2;--b+1;putchar(b?44:10))for(i=n;i>1-n;)putchar(48|--i!=0^b);}

Attempt This Online!

• I think it would be fine although there's a leading space 77 bytes, you can convert to function and fix leading space at no cost n;f(b,i){for(n=1;++n;... Apr 24 at 16:25
• A bit weird but could be fine 70 bytes Apr 24 at 16:31

# Burlesque, 23 bytes

q1j{0+]0[+}jC!ClJm{)n!}


Try it online!

q1        # Block containing 1
j         # Reorder stack
{0+]0[+}  # Surround with 0s ({1} -> {0 1 0})
jC!       # Put user input as argument for continue many
Cl        # Collect results
Jm{)n!}   # Duplicate and create noted copy


# Ruby, 42 bytes

a="0,1";loop{puts a;a[?,]="1,0";a=?1+a+?0}


Try it online!

# 05AB1E, 8 bytes

0L[=εN.ø


Outputs indefinitely.

Try it online.

Explanation:

0L        # Push list [1,0]
[       # Start an infinite loop:
=      #  Print the current pair with trailing newline (without popping)
ε     #  Map over both values:
N    #   Push the current (0-based) map-index
.ø  #   Surround the value with this index as leading/trailing item


flip take$[1]:[0]:(drop 2$[0]#[1]);x#y=x:y:(1:x++[1])#(0:y++[0])


Try it online!

# MATLAB, 48 bytes

function b(n),1,o=0,for i=3:2:n,o=[1 o 1],~o,end


prints to command window. start off with a hard-coded 0 and 1, storing o as 0. Then in a for loop, loop through every 2 integers from 3 to input n (if n is 1, the loop is skipped) and add ones to either end of o, using a comma instead of a semicolon so the output is put to the command window. At the same time, this becomes the new value of o. Taking the logical not operator to o inverts the zeroes and ones.

Try it online!

# V (vim), 20 bytes

i1,0ÀñÙé0wé0lá1Á1ñd


Try it online!

Hexdump:

00000000: 6931 2c30 1bc3 80fe 58c3 b1c3 99c3 a930  i1,0....X......0
00000010: 77c3 a930 6cc3 a131 c381 31c3 b164 c3bf  w..0l..1..1..d..
00000020: c3                                       .


Explanation:

i1,0                   " Insert the text '1,0'
Àñ            " Arg times...
Ù           "   Duplicate a line downwards
é0         "   Prepend a '0'
w        "   Move forward one word
é0      "   Append a '0'
l     "   Move one character right
á1   "   Append a '1'
Á1 "   Append a '1' to the end of this line
" (implicitly end the loop)


This does one loop too many, but that seems to be allowed by the rules. To fix that, add ñd to the end (ñ is "explicitly end the loop" and d is "delete one line").

An infinite version saves one byte:

i1,0<esc>ÒÙé0wé0lá1Á1


# sed, 40

:x
s/^\$/1/p
h
y/10/01/
p
x
s/.*/0&0/p
bx


Try it online!

# Brainfuck, 116 bytes

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


Try it online!

Explanation:

memory map: unused;nl;character;loop_count;digit_counter;digit_counter_copy
++++++++++[->+>+++++<<]>>- create newline and set character to "1"
[-             loop loop_count times
>+            increase digit counter
@ [->+<<<.>>] print the "1"s and move digit_counter to digit_counter_copy
@ <<-.        set character to "0" and print
@ +           set character to "1"
@ >>>         go to digit counter_copy
@ [-<+<<.>>>] print "1"s and move digit_counter_copy to digit_counter
<<<-----.     set character to "," and print
++++          set character to "0"
>>            go to digit counter

now follows copy of previous block denoted by @
it is just slightly modified to ouput oposite eye
@ [->+<<<.>>] print the "0"s and move digit_counter to digit_counter_copy
@ <<+.        set character to "1" and print
@ -           set character to "0"
@ >>>         go to digit counter_copy
@ [-<+<<.>>>] print "0"s and move digit_counter_copy to digit_counter
<<<+          set character back to "1"
<.            print newline
>>            got back to loop_count
]