Skip to main content
added 208 characters in body
Source Link
Jakque
  • 2.8k
  • 8
  • 13

Python 3.8 (pre-release), 103103 102 bytes

exec(s:="from random import*;c='e'\nwhile c:print(end=c);c=choice(f'exec(s:={s!r})'.split(c)[1:])[:1]"[0]")

Try it online!Try it online!

the program stops by crashing due to an IndexError. To avoid crashing, [0] must be replaced by [:1] for the cost of 1 byte

How it works?

  • I started from the quine exec(s:="print('exec(s:=%r)'%s)")

then the core program is the following :

from random import*
c='e'
while c:
  print(end=c)
  c=choice('<the quine string>'.split(c)[1:])[:1][0]
  • I assign c to the first letter of our quine (e).

while c is not the empty string :

  • I print c
  • I randomly choose a successor of c beween all possible successor

to choose a successor :

  • let say our string is "abacbdeb" and I want a successor of 'b':
  • I split the string using 'b' as separator : ['a','ac','de','']
  • I remove the first substing which corresponds to the char before the first occurence of b : ['ac','de','']
  • I take up to 1 char of these substring : ['a','d','']

If the char is at the end of a string  , it will have the empty string as potential successor and will crash the program when atempting to get its first character. It only works beacuse no char is repeated twice.

Python 3.8 (pre-release), 103 bytes

exec(s:="from random import*;c='e'\nwhile c:print(end=c);c=choice(f'exec(s:={s!r})'.split(c)[1:])[:1]")

Try it online!

How it works?

  • I started from the quine exec(s:="print('exec(s:=%r)'%s)")

then the core program is the following :

from random import*
c='e'
while c:
  print(end=c)
  c=choice('<the quine string>'.split(c)[1:])[:1]
  • I assign c to the first letter of our quine (e).

while c is not the empty string :

  • I print c
  • I randomly choose a successor of c beween all possible successor

to choose a successor :

  • let say our string is "abacbdeb" and I want a successor of 'b':
  • I split the string using 'b' as separator : ['a','ac','de','']
  • I remove the first substing which corresponds to the char before the first occurence of b : ['ac','de','']
  • I take up to 1 char of these substring : ['a','d','']

If the char is at the end of a string  , it will have the empty string as potential successor. It only works beacuse no char is repeated twice.

Python 3.8 (pre-release), 103 102 bytes

exec(s:="from random import*;c='e'\nwhile c:print(end=c);c=choice(f'exec(s:={s!r})'.split(c)[1:])[0]")

Try it online!

the program stops by crashing due to an IndexError. To avoid crashing, [0] must be replaced by [:1] for the cost of 1 byte

How it works?

  • I started from the quine exec(s:="print('exec(s:=%r)'%s)")

then the core program is the following :

from random import*
c='e'
while c:
  print(end=c)
  c=choice('<the quine string>'.split(c)[1:])[0]
  • I assign c to the first letter of our quine (e).

while c is not the empty string :

  • I print c
  • I randomly choose a successor of c beween all possible successor

to choose a successor :

  • let say our string is "abacbdeb" and I want a successor of 'b':
  • I split the string using 'b' as separator : ['a','ac','de','']
  • I remove the first substing which corresponds to the char before the first occurence of b : ['ac','de','']
  • I take up to 1 char of these substring : ['a','d','']

If the char is at the end of a string, it will have the empty string as potential successor and will crash the program when atempting to get its first character. It only works beacuse no char is repeated twice.

Source Link
Jakque
  • 2.8k
  • 8
  • 13

Python 3.8 (pre-release), 103 bytes

exec(s:="from random import*;c='e'\nwhile c:print(end=c);c=choice(f'exec(s:={s!r})'.split(c)[1:])[:1]")

Try it online!

How it works?

  • I started from the quine exec(s:="print('exec(s:=%r)'%s)")

then the core program is the following :

from random import*
c='e'
while c:
  print(end=c)
  c=choice('<the quine string>'.split(c)[1:])[:1]
  • I assign c to the first letter of our quine (e).

while c is not the empty string :

  • I print c
  • I randomly choose a successor of c beween all possible successor

to choose a successor :

  • let say our string is "abacbdeb" and I want a successor of 'b':
  • I split the string using 'b' as separator : ['a','ac','de','']
  • I remove the first substing which corresponds to the char before the first occurence of b : ['ac','de','']
  • I take up to 1 char of these substring : ['a','d','']

If the char is at the end of a string , it will have the empty string as potential successor. It only works beacuse no char is repeated twice.