Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this program, simulate the operation of the game with an application program in C++. We drop a marble down the chute labeled A. If

For this program, simulate the operation of the game with an application program in C++. We drop a marble down the chute labeled A. If the last marble that we drop down the chute comes out one of the chutes labeled B or D, then we win. If the last marble that we drop down the chute comes out one of the chutes labeled C or E, then we loose. In this case, your program will take two inputs, the first being the gate directions and the second being the input string to simulate and your program will output the sequence of gate configurations and the chute that the last marble exits.

To simulate this we have an input alphabet of {0, 1}. An input symbol of '0' or '1' simulates dropping a marble down chute A, but they interact differently with gate X1. Each time a marble touches a gate it causes the gate to toggle. For gates X2, X3, and X4, they toggle from right to left and left to right. But gate X1 has three possible directions left, center, or right. On an input of 0, X1 toggles from left to right to center to left (and so on). On an input of 1, X1 toggles from left to center to right to left (and so on). When a marble touches a gate, the gate toggles and the marble goes in the direction that the gate was set to prior to being toggled. Initially all of the gates are configured to the left (as shown in the diagram). As an example, if all of the gates are positioned to the left, then dropping a 0 marble down chute A results in the marble exiting gate B and toggling gate X1 to the right and gate X2 to the right. If all of the gates are positioned to the left, then dropping a 1 marble down chute A results in the marble exiting gate B and toggling gate X1 to the center and gate X2 to the right.

image text in transcribed

Trace of configurations for various inputs (values for X1X2X3X4 and string to process). ./project LLLL 0000 LLLL->RRLL->CRLR->LRRR->RLRR C ./project LLLL 1111 LLLL->CRLL->RRRL->LRRR->CLRR C ./project LLLL 01010101 LLLL->RRLL->LRLR->RLLR->LLLL->RRLL->LRLR->RLLR->LLLL E ./project LLLL 10101010 LLLL->CRLL->LRRL->CLRL->LLLL->CRLL->LRRL->CLRL->LLLL D

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions