12
2
The Machine
A billiard-ball type machine is composed of only the symbols \
_
/
along with upper- and lower-case letters, spaces, and the number 1
.
\
and /
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.
The number 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 _
.
Example machine-
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.
The machine
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 A:1
.
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 C:1
.
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
The Goal
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.
Examples
A wire crossing
ab
\/
AB
An XOR gate
ab1
\_/
C
A full adder
1 a
\_/ b
\_/
\/
/\
_ __/
\_/
\/c
\\_/
_S1
\ \/
__/
/
_
\__
C
MAKE DIS AN ESOLANG – Matthew Roh – 2017-02-08T13:59:26.707
@MatthewRoh Working on it. – HyperNeutrino – 2017-02-08T16:16:47.140
@MatthewRoh I've built the main framework, and I'm working on adding new things. Also, I made a somewhat user-friendly 0+0 to 3+3 adder, and I'm working on a vertically stackable module. – HyperNeutrino – 2017-02-10T03:01:07.890
1
@AlexL. Also relevant: Marbelous
– PhiNotPi – 2017-02-10T13:41:34.627That's interesting. That's more or less the kind of thing I'm going for, but without marbles having values themselves. – HyperNeutrino – 2017-02-10T13:52:04.107
https://github.com/alexander-liao/java-public/tree/master/programs/ball-simulator – HyperNeutrino – 2017-02-10T20:00:38.813
@MatthewRoh ^ Made something to start – HyperNeutrino – 2017-02-10T20:24:19.143
@AlexL. :D Looks nice! – Matthew Roh – 2017-02-11T04:17:25.983
In your first example, why does the first ball fall down under the A? Is there an unwritten rule that balls stop when they pass onto a character which isn't
\_/
? – Peter Taylor – 2011-10-17T07:41:44.147@PeterTaylor Yes, I should add that all letter behave as an empty space when it comes to affecting the ball, and gravity pulls the ball down. – PhiNotPi – 2011-10-17T10:26:31.967
1Do you, by any chance, mean 'flipper', not 'billard'? – user unknown – 2011-10-20T00:49:26.127