Write a program that takes a string as an input. For the input:

  • If the input doesn't match the source code, the program shall output the input intact. (Hence a cat)

  • Otherwise, the program shall fall in an infinite loop. (So actually not a cat)

  • \$\begingroup\$ Can the program read its own source code? \$\endgroup\$
    – Sisyphus
    Oct 16 '20 at 3:43
  • 1
    \$\begingroup\$ So a cross between a narcissist program and a truth machine \$\endgroup\$
    – Jo King
    Oct 16 '20 at 4:01
  • 4
    \$\begingroup\$ Possible duplicate of Write the shortest self-identifying program (a quine variant) \$\endgroup\$ Oct 16 '20 at 4:19
  • 1
    \$\begingroup\$ that looks very very similar \$\endgroup\$
    – Razetime
    Oct 16 '20 at 4:20
  • 4
    \$\begingroup\$ I chose to slam this since in most languages it's basically just wrapping the target in a while loop and then adding a print after the loop. Adding extra code to a quine isn't always trivial, but I think most of the answers there are competitive here after a small change. \$\endgroup\$ Oct 16 '20 at 4:42

Ruby -0p, 38 37 32 bytes

Saved 5 bytes thanks to a comment by @Sisyphus on another answer.

eval s="1until$_!='eval s=%p'%s"

Try it online!

The -0 flag sets the null byte as the input record separator. Without -0, a loop would also be entered if the input consisted of the code repeated on more than one line.


Not the answer you're looking for? Browse other questions tagged or ask your own question.