Skip to main content
deleted 5 characters in body
Source Link
Jakque
  • 2.8k
  • 8
  • 13

Python 3.8 (pre-release), 264 250 121120 + 121120 = 242240 bytes

Code 0: (121120 bytes)

for i in(c:=[]),0:
 c+=0,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^allc[0]^all(c:=c[1:]-1])},;exec(s:=%r)#'%s)")#

Try it online!Try it online!

Code 1: (121120 bytes)

for i in(c:=[]),0:
 c+=1,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^allc[0]^all(c:=c[1:]-1])},;exec(s:=%r)#'%s)")#

Try it online!Try it online!

Test Suite

Try it online!Try it online!

How it works:

  • c store the binary number of the program on the form of a list

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop()^allc[0]^all(c:=c[1:]-1]) is called, it returns the nth leftmost bit of c+1

the next for loop are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.8 (pre-release), 264 250 121 + 121 = 242 bytes

Code 0: (121 bytes)

for i in(c:=[]),0:
 c+=0,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^all(c:=c[1:])},;exec(s:=%r)#'%s)")#

Try it online!

Code 1: (121 bytes)

for i in(c:=[]),0:
 c+=1,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^all(c:=c[1:])},;exec(s:=%r)#'%s)")#

Try it online!

Test Suite

Try it online!

How it works:

  • c store the binary number of the program on the form of a list

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop()^all(c:=c[1:]) is called, it returns the nth leftmost bit of c+1

the next for loop are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.8 (pre-release), 264 250 120 + 120 = 240 bytes

Code 0: (120 bytes)

for i in(c:=[]),0:
 c+=0,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c[0]^all(c:=c[1:-1])},;exec(s:=%r)#'%s)")#

Try it online!

Code 1: (120 bytes)

for i in(c:=[]),0:
 c+=1,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c[0]^all(c:=c[1:-1])},;exec(s:=%r)#'%s)")#

Try it online!

Test Suite

Try it online!

How it works:

  • c store the binary number of the program on the form of a list

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c[0]^all(c:=c[1:-1]) is called, it returns the nth leftmost bit of c+1

the next for loop are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

deleted 262 characters in body
Source Link
Jakque
  • 2.8k
  • 8
  • 13

Python 3.9Python 3.8 (pre-release), 264 250 125121 + 125121 = 250242 bytes

Code 0: (125121 bytes)

for i in*in(c:=[1]=[]),0:
 c+=[0]*i;execc+=0,;exec(s:="i or print(end=f'for i in*in(c:=[1]=[]),0:\\n c+=[c+={c.pop(1)^all(c:=c[1:])}]*i;exec,;exec(s:=%r)#'%s)")#

Try it online!Try it online!

Code 1: (125121 bytes)

for i in*in(c:=[1]=[]),0:
 c+=[1]*i;execc+=1,;exec(s:="i or print(end=f'for i in*in(c:=[1]=[]),0:\\n c+=[c+={c.pop(1)^all(c:=c[1:])}]*i;exec,;exec(s:=%r)#'%s)")#

Try it online!Try it online!

Test Suite

Try it online!

The syntax for i in*(c:=[1]),0: is valid in python 3.9 (but throw an error in python 3.8). As tio doesn't support python 3.9, I modified this line by for i in(c:=[1])+[0] for the tests to work.Try it online!

How it works:

  • c store the binary number of the program on the form of a list with a leading 1.

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop(1)^all(c:=c[1:]) is called, it returns the n+1nth leftmost bit of c+1

the next for loops after the first oneloop are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.9, 264 125 + 125 = 250 bytes

Code 0: (125 bytes)

for i in*(c:=[1]),0:
 c+=[0]*i;exec(s:="i or print(end=f'for i in*(c:=[1]),0:\\n c+=[{c.pop(1)^all(c)}]*i;exec(s:=%r)#'%s)")#

Try it online!

Code 1: (125 bytes)

for i in*(c:=[1]),0:
 c+=[1]*i;exec(s:="i or print(end=f'for i in*(c:=[1]),0:\\n c+=[{c.pop(1)^all(c)}]*i;exec(s:=%r)#'%s)")#

Try it online!

Test Suite

Try it online!

The syntax for i in*(c:=[1]),0: is valid in python 3.9 (but throw an error in python 3.8). As tio doesn't support python 3.9, I modified this line by for i in(c:=[1])+[0] for the tests to work.

How it works:

  • c store the binary number of the program on the form of a list with a leading 1.

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop(1)^all(c) is called, it returns the n+1th leftmost bit of c+1

the for loops after the first one are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.8 (pre-release), 264 250 121 + 121 = 242 bytes

Code 0: (121 bytes)

for i in(c:=[]),0:
 c+=0,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^all(c:=c[1:])},;exec(s:=%r)#'%s)")#

Try it online!

Code 1: (121 bytes)

for i in(c:=[]),0:
 c+=1,;exec(s:="i or print(end=f'for i in(c:=[]),0:\\n c+={c.pop()^all(c:=c[1:])},;exec(s:=%r)#'%s)")#

Try it online!

Test Suite

Try it online!

How it works:

  • c store the binary number of the program on the form of a list

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop()^all(c:=c[1:]) is called, it returns the nth leftmost bit of c+1

the next for loop are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

added 708 characters in body
Source Link
Jakque
  • 2.8k
  • 8
  • 13

Python 3.8 (pre-release)Python 3.9, 132264 125 + 132125 = 264250 bytes

Code 0: (132125 bytes)

for i inin*(bc:=1=[1]),(a:=-1)0:
 c=1;execc+=[0]*i;exec(s:="~i="i and(b:=2*b-c)or print(end=f'for i inin*(bc:=1=[1]),(a:=-1)0:\\n c=c+=[{~b>>a&1c.pop(1)^all(c)};exec]*i;exec(s:=%r)#'%s);a+=i"")#

Try it online!Try it online!

Code 1:  (132125 bytes)

for i inin*(bc:=1=[1]),(a:=-1)0:
 c=0;execc+=[1]*i;exec(s:="~i="i and(b:=2*b-c)or print(end=f'for i inin*(bc:=1=[1]),(a:=-1)0:\\n c=c+=[{~b>>a&1c.pop(1)^all(c)};exec]*i;exec(s:=%r)#'%s);a+=i"")#

Try it online!Try it online!

Test Suite

Test Suite

Try it online!

The syntax for i in*(c:=[1]),0: is valid in python 3.9 (but throw an error in python 3.8). As tio doesn't support python 3.9, I modified this line by for i in(c:=[1])+[0] for the tests to work.

How it works:

  • a increments the length of the program
  • bc store the binary number of our code
  • c store the 'bit' part of each program on the form of a list with a leading 1.

The for loop execute twice :

  • the first time, it assigns a and bc to the wantedcorrect value
  • the second time, it prints the code replacing a char by 1 or code 0 according to the state ofdepending on bc. The ~b>>a&1n select the good value forth time c.pop(1)^all(c) is called, it returns the n+1th leftmost bit of c+1

the for loops after tehthe first one are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.8 (pre-release), 132 + 132 = 264 bytes

Code 0: (132 bytes)

for i in(b:=1),(a:=-1):
 c=1;exec(s:="~i and(b:=2*b-c)or print(end=f'for i in(b:=1),(a:=-1):\\n c={~b>>a&1};exec(s:=%r)#'%s);a+=i")#

Try it online!

Code 1:  (132 bytes)

for i in(b:=1),(a:=-1):
 c=0;exec(s:="~i and(b:=2*b-c)or print(end=f'for i in(b:=1),(a:=-1):\\n c={~b>>a&1};exec(s:=%r)#'%s);a+=i")#

Try it online!

Test Suite

How it works:

  • a increments the length of the program
  • b store the binary number of our code
  • c store the 'bit' part of each program.

The for loop execute twice :

  • the first time, it assigns a and b to the wanted value
  • the second time, it prints the code 1 or code 0 according to the state of b. ~b>>a&1 select the good value for the bit

the for loops after teh first one are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Python 3.9, 264 125 + 125 = 250 bytes

Code 0: (125 bytes)

for i in*(c:=[1]),0:
 c+=[0]*i;exec(s:="i or print(end=f'for i in*(c:=[1]),0:\\n c+=[{c.pop(1)^all(c)}]*i;exec(s:=%r)#'%s)")#

Try it online!

Code 1: (125 bytes)

for i in*(c:=[1]),0:
 c+=[1]*i;exec(s:="i or print(end=f'for i in*(c:=[1]),0:\\n c+=[{c.pop(1)^all(c)}]*i;exec(s:=%r)#'%s)")#

Try it online!

Test Suite

Try it online!

The syntax for i in*(c:=[1]),0: is valid in python 3.9 (but throw an error in python 3.8). As tio doesn't support python 3.9, I modified this line by for i in(c:=[1])+[0] for the tests to work.

How it works:

  • c store the binary number of the program on the form of a list with a leading 1.

The for loop execute twice :

  • the first time, it assigns c to the correct value
  • the second time, it prints the code replacing a char by 1 or 0 depending on c. The nth time c.pop(1)^all(c) is called, it returns the n+1th leftmost bit of c+1

the for loops after the first one are ignored thanks to the comment #

The printing is a derivate of this quine : exec(s:="print('exec(s:=%r)'%s)")

Source Link
Jakque
  • 2.8k
  • 8
  • 13
Loading