Refer to the figure shown below. A marble is dropped in at points A or B.
Levers X1, X2 and X3 divert the marble to the left or right. Whenever a marble
encounters a lever, it causes the lever to change state, so that the next
marble to encounter that lever will take the opposite branch.
Input will be a sequence of 0,'s and 1's, where
A sequence is accepted if the last marble comes out at point D and is rejected
if the last marble comes out at point C.
Write a program to model the problem. Input will be the integers 0 and 1 as
described above and -1 to denote the end of a sequence. There will be a number
of sequences given in the problem until reaching end of file.
Output will be the statements:
Input file (model.dat):
Output file (model.out):
Set n accepted
or Set n rejected
where n is the chronological position of the sequence.
A B
| | | |
| | | |
| / | | / |
/ /X1 \ / /X2 \
/ \/ \
/ /\ /\ \
/ / \ / / \ \
\ \ / /X3 \ / /
\ \/ \/ /
\ /\ /
\ / \ /
| | | |
| | | |
| | | |
C D
Sample:
-1
0 0 0 0 -1
0 0 0 0 0 -1
1 1 -1
0 0 1 -1
Set 1 rejected
Set 2 accepted
Set 3 rejected
Set 4 accepted
Set 5 accepted