{{ message }}

Instantly share code, notes, and snippets.

perey/esolang0815_examples.md

Last active Dec 15, 2015
0815 Interpreter

Hello World

The Esolang wiki version

``````<:48:x<:65:=<:6C:\$=\$=\$\$~<:03:+\$~<:ffffffffffffffbd:+\$<:ffffffffffffffb1:
+\$<:57:~\$~<:18:x+\$~<:03:+\$~<:06:x-\$x<:0e:x-\$=x<:43:x-\$
``````

Explanation

Store "H" and "e". Print them. Use addition and subtraction to get the characters "l", "o", comma, and space. Print them (twice for the "l"). Store "W". Print it. Print "o" (which is still in a register). Use addition to get the characters "r", "l", "d", and "!". Print them.

Problems

Well, it takes a few inefficient approaches to various numbers. And the language specification says nothing about negative numbers having to be entered in two's complement; if anything, its insistence on signed arithmetic implies that negative numbers ought to be accepted with a minus sign instead.

(Note, however, that the author's implementation does insist on two's complement, rather than minus signs.)

Cat

The Esolang wiki version

``````}:_t:!~\$^:_t:
``````

Explanation

Read a character. Print it. If it wasn't zero, go back to the start (i.e. input is null-terminated).

Problems

EOF might have been a better choice of terminator.

Truth Machine

The Esolang wiki version

``````|~}:i:%^:i:
``````

Explanation

Read in a number. Print it. If it's non-zero, print it again, and again, and...

Odd or Even

The Esolang wiki version

``````}:s:|=<:2:x~#:e:=/~%~<:20:~\$=<:73:x<:69:~\$~\$~<:20:~\$=^:o:<:65:
x<:76:=\$=\$~\$<:6E:~\$<:a:~\$^:s:}:o:<:6F:x<:64:x~\$~\$\$<:a:~\$^:s:
``````

Explanation

Read in a number. Divide it by 2. Print the number followed by " is ". If the remainder of division is non-zero, print "odd\n" and jump back to the beginning; otherwise print "even\n" and jump back to the beginning.

Problems

The seventh instruction (`#:e:`) is a jump to a non-existent label `:e:`. This is probably deliberate, because jumping to non-existent labels is a way to terminate the program (the only way, short of killing the process, when using the author's own implementation, because it has no way to quit when the program is waiting for input).

A version that instead outputs "0 is even" should simply remove that jump.

Fibonacci Sequence

The Esolang wiki version

``````%<:0D:>~\$<:01:~%>=<:a94fad42221f2702:>~>}:_s:{x{={~\$x+%{=>~>x~-x<:0D:~>~>~
^:_s:?
``````

Explanation

Print 0, then "\r" (CR), then 1. Put 0, 1, "\r", and the 93rd Fibonacci number (0xa94fad42221f2702) into the queue, in that order. While the second number in the queue is not equal to F(93), read the numbers out, add them up, and print "\r" and their sum; then store the second number, the sum, "\r", and F(93) in the queue.

Problems

CR? Really? What is this, Mac OS 9?

Also, "\r" is enqueued, dequeued, printed, and discarded. Then another copy is loaded and the cycle repeats.

Finally, F(93) is too large to be stored as a signed 64-bit value, so it overflows and becomes negative. This would not be a problem if it was checked before being printed.

Fixed version:

``````%<:0A:>~\$<:01:~%>=<:68a3dd8e61eccfbd:>~>}:_s:{x{={~\$x+%{=>~>x~-x<:0A:~>~>~
^:_s:?
``````
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters