A box with balls

From Esolang
Jump to navigation Jump to search

A box with balls (Abwb for short) is an esolang made by me, User:Hashibami, as a joke around an paradox, the paradox says: "If in a box, there is 10 balls, and every time you take one, you add the current amount of balls in the box, and you do it indefinitely, when you stop, how many balls are in the box?"

Commands

Well, in Abwb there are 5 commands:

Command In python
add:balls; box += balls
remove:balls; box -= balls
bless:balls; box *= balls
divide:balls; box /= balls
watch:; print(box)

Interpreter for Python

I made this interpreter that you can run code, just change the current code string:

def run(code):
    box = 0
    lines = code.strip().splitlines()
    for line in lines:
        line = line.strip()
        if line.startswith("add:"):
            box += int(line[4:-1])
        elif line.startswith("remove:"):
            box -= int(line[7:-1])
        elif line.startswith("divide:"):
            box //= int(line[7:-1])
        elif line.startswith("bless:"):
            box *= int(line[6:-1])
        elif line == "watch:;":
            print(box)
        else:
            print(f"Invalid: {line}")
code = """
add:3;
bless:4;
remove:2;
divide:2;
watch:;
"""
run(code)