Casino

From Esolang
Jump to navigation Jump to search

Casino is a cell based esoteric programming language that utilizes a psuedo random number generator to determine which command will be run. It was created by User:Bluswimmer in 2017.

Language Overview

The language only uses two characters: "$" and linefeed. No other characters may be in the program, or else the interpreter will refuse to run the program.

When the interpreter starts, the seed of the pseudo random number generator is set to 25214903917 so that programs will always be run consistently. The user is asked to input the filename with their code in it and any program input. The interpreter then begins reading the code line-by-line.

For each "$" in a line, the seed is set to the next random integer generated from Java's random number generator. Once the end of the line is reached, the current seed is added to a seed list.

Once the interpreter has successfully read through the entire program, it will now attempt to execute the program. The interpreter loops through every seed in the seed list, and runs a command based on the result of (seed & 0b111).

Command Description
0 Increments the current cell and moves the pointer to the right.
1 Decrements the current cell.
2 Moves the pointer to the left.
3 If the current cell is not zero, then jump an amount of lines specified by the cell directly to the right of the current cell, which is treated as a signed byte. Note that jumping will not execute the command that the interpreter lands on, but the command directly after it.
4 Outputs the character corresponding to the ASCII value of the current cell.
5 Sets the current cell to the next character in the program input string's ASCII value.
6 or 7 Ends the program. Note that the program also ends when there are no more commands to run.

Computational class

First, note that the pseudorandom number generation has no effect on Casino's computational class; Java's sequence of random integers contains each of the eight low-three-bit sequences infinitely many times.

The original interpreter has limited memory due to using a fixed tape size of 30000 cells, each of which is 16 bits wide.

If the limit on the size of a cell is removed, then Casino can be shown to be Turing-complete because The Waterfall Model can be compiled into it; seven waterclocks are sufficient for The Waterfall Model to be Turing-complete, so a tape can be constructed with 15 cells, starting by alternating between cells holding waterclock values and a somewhat large positive byte, and finishing with a highly negative byte (more negative than the positive byte is positive). This makes it possible to do an unconditional skip forwards, a conditional skip forwards if a waterclock is nonzero, and an unconditional skip backwards; a run of evenly spaced 3 commands makes it possible to goto the start of the program from the end (via placing the cursor on the penultimate cell), and (when the cursor is elsewhere, so the program runs forwards) will also cause some but not all of the commands before the next 3 command to be skipped but only if the waterclock is nonzero. Via adding large runs of 4 commands (which produce output but have no other effect) to effectively skip over unused parts of the program, it's possible to implement both code that's conditional on the value of the current waterclock, and unconditional code, of arbitrary length (because you can put your code in only the conditional or unconditional portion of one 3…3 section, then if there isn't enough room, continue to the next, and so on). The only commands that can't be broken up into separate sections are those which move the pointer to point elsewhere (to test a different waterclock or to move to a cell temporarily to adjust it and then move back); but because the tape is only 15 cells wide, and the maximum value of a signed byte is much higher than that, there will always be enough space to fit one of these "atomic sections" in between 3 commands.

The language is probably also Turing-complete with limited cell size but unlimited tape size; however, this is less obvious due to the need to construct jump-distance constants on the tape as it grows.

Examples

CAT Program

$
$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$
$$$$
$$$$$$$$$

External Links

Interpreter and Source Code