Jug
From Esolang
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.
Contents |
[edit] 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.
[edit] Commands
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).
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.
[edit] Arithmetic
[edit] 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));
[edit] Subtraction
7-2
jug(0,7); jug(1,2); fill(0); pour(0,1); echo(volume(0));
[edit] 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));
[edit] Examples
[edit] Hello, World!
echo("Hello, world!");
[edit] 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);
}
[edit] 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.");
}

