A billiard-ball type machine is composed of only the symbols
/ along with upper- and lower-case letters, spaces, and the number
/ are ramps. A ball coming from above will be deflected to either the right or left side, respectively. For both ramps, if a ball comes from either side, it will be deflected downward.
_ is a logic element. The logic performed by it is the most un-billiard-like part of the computer. First, a ball coming from the left or right continues in the same direction. A ball coming from above will be stopped. Then, after the end of its execution (see Running the Machine below), if the number of balls crossing/landing on it is positive even number, then a single ball is released from the bottom of the element.
A space does nothing. Any balls coming from any direction fall straight down due to gravity.
Lowercase letters are inputs. All inputs will either be a single 1 or 0.
Uppercase letters are outputs. The number outputted will be the number of billiard balls that hit its location.
1 releases a extra billiard-ball at that location. It represents a logical 1.
All characters besides
\_/ cause any ball coming from any direction to fall straight down due to gravity.
Balls never combine, split, or collide. They are only created when released from an input, a
_, or a
1. They are only destroyed when they fall straight down onto a
1 a \_/ b \_/ \/ /\ / _ _ A B
There will never be any blank lines in a machine, but the
_'s may make it appear that there is a blank line.
Running the Machine
A machine is run in layers, or rows. All billiard-ball movement on the top layer is performed before anything happens on the second layer.
ab \_A C
is run as follows:
First, it prompts for the input
a in the form
a:. The user will then input a 1 or 0 (followed by enter). It repeats this for the input
b. This is the end of the first layer. I am going to assume that the user entered a 1 for both inputs.
It then traces out the path of the first ball (from
a), which goes along the
\, across the
_, into the
A, and falls down to the spot under the
A. It then traces out the path for the second ball (from
b), which goes straight down onto the
_ and terminates. This is the end of the second layer.
Now, before the third layer, since the
_ has had two balls cross over it, it releases one ball. The output
A has had one ball cross over it, so it outputs
For the third layer, it traces the path of the first ball (from the
_), which goes though the
C and falls straight down. The second ball (which fell through the
A) also falls straight down.
Now, before the fourth layer, since the output
C had one ball travel over it, it outputs
Since the fourth layer is blank, the program terminates.
The total result should look like
a:1 (the user entered the one) b:1 (same here) A:1 C:1
Your goal is to take a machine from STDIN and simulate it by taking inputs and printing output as needed to STDOUT. The first part of the input to your program will consist of the machine to be run, followed by a blank line. Any input letters encountered should cause your program to prompt for input in the form of the input name followed by a colon. Any output should be shown in the form of the output name, followed by a colon, followed by the number of balls passing over that spot.
This is golf.
A wire crossing
ab \/ AB
An XOR gate
ab1 \_/ C
A full adder
1 a \_/ b \_/ \/ /\ _ __/ \_/ \/c \\_/ _S1 \ \/ __/ / _ \__ C