Skip to main content
added 649 characters in body
Source Link

Haskell, 32 bytes

!f=f 0
_!f=f 1*>0!f
main=0!print

I think this is the only answer posted so far where the first character (the digit) isn't the entry point.

Anyway, explanation: I'm creating an operator function called !, and defining it by cases. We enter the top case if the left operand matches the program's first digit, and the bottom case otherwise. The right operand is bound to f in both cases (and it happens to always be print). In the top case, we just print a 0. In the bottom case, we print a 1, and then recursively call ourself with the same operands. (We know the left operand will always be 0.) Finally, main, the entry point, calls our operator with 0 and print.

Try it online with 0! Try it online with 1!

Haskell, 32 bytes

!f=f 0
_!f=f 1*>0!f
main=0!print

Try it online with 0! Try it online with 1!

Haskell, 32 bytes

!f=f 0
_!f=f 1*>0!f
main=0!print

I think this is the only answer posted so far where the first character (the digit) isn't the entry point.

Anyway, explanation: I'm creating an operator function called !, and defining it by cases. We enter the top case if the left operand matches the program's first digit, and the bottom case otherwise. The right operand is bound to f in both cases (and it happens to always be print). In the top case, we just print a 0. In the bottom case, we print a 1, and then recursively call ourself with the same operands. (We know the left operand will always be 0.) Finally, main, the entry point, calls our operator with 0 and print.

Try it online with 0! Try it online with 1!

Source Link

Haskell, 32 bytes

!f=f 0
_!f=f 1*>0!f
main=0!print

Try it online with 0! Try it online with 1!