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)
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.
Sign up to join this communityWrite 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)
-0p
, Saved 5 bytes thanks to a comment by @Sisyphus on another answer.
eval s="1until$_!='eval s=%p'%s"
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.