Jug
Jump to navigation
Jump to search
Jug is an esoteric programming language created by User:Marz. Inspired by Liquid and the Die Hard Water Puzzle, Jug involves pouring water between different jugs in order to accomplish integer arithmetic.
Language overview
Jug has 8 functions, which are called like so:
function(a,b);
Each function returns a value, meaning a function can be called with another function as a parameter.
Strings can be concatenated with ampersands, and can include numbers, like so:
99&" bottles of beer on the wall."
Strings cannot be stored in jugs, as they are not liquid.
Commands
Function | Description |
---|---|
jug(x,y); |
Creates Jug x (int), of size y (int). Returns x .
|
fill(x); |
Fills Jug x (int). Returns x .
|
empty(x); |
Empties Jug x (int). Returns x .
|
pour(x,y); |
Pours water from Jug x (int) into Jug y (int), stopping before Jug y overflows. Returns the volume of water poured (int).
|
echo(x); |
Prints x (string). Returns x .
|
volume(x); |
Returns the volume of water in Jug x (int).
|
Flow control | |
if_empty(x){}; |
If Jug x is empty, {...}. Returns x .
|
else{}; |
Follows if_empty(x) statement. If Jug x is not empty, {...}. Returns x .
|
drain(x){}; |
Loops until Jug x (int) is empty. Returns x .
|
Arithmetic
Addition
4+3
jug(0,4); jug(1,3); jug(2,100); fill(0); fill(1); pour(0,2); pour(1,2); echo(volume(2));
Subtraction
7-2
jug(0,7); jug(1,2); fill(0); pour(0,1); echo(volume(0));
Multiplication
4*6
jug(0,4); jug(1,6); jug(2,1); jug(3,100); fill(0); drain(0){ fill(1); pour(1,3); pour(0,2); empty(2); } echo(volume(3));
Examples
Hello, World!
echo("Hello, world!");
Fibonacci sequence
jug(0,20); jug(1,1); jug(2,5000); jug(3,5000); jug(4,5000); fill(1); pour(1,3); empty(1); echo("0\n1\n"); drain(fill(0)){ pour(2,empty(4)); pour(3,4); echo(volume(4)&"\n"); pour(3,empty(2)); pour(4,empty(3)); pour(0,1); empty(1); }
99 bottles of beer
jug(0,99); jug(1,1); drain(0){ echo(volume(0)&" bottles of beer on the wall,\n"; echo(volume(0)&" bottles of beer.\nTake one down, pass it around,\n"); pour(0,1); empty(1); if_empty(0) echo("No bottles of beer on the wall."); else echo(volume(0)&" bottles of beer on the wall."); }