In this assignment we would like to implement a version of the rock paper scissors game,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment we would like to implement a version of the rock paper scissors game, where the character R represents rock, P represents paper, and S represents scissors. The expression (R&S) represents a game between the rock and the scissors, and therefore the winner (and the outcome) will be R. We can also have morc complicated expressions. For example, ((P&S)&(R&P)) will be cquivalent to (S&P) which in turn is equivalent to S. (You can think of the expression as a kind of rock paper scissors tournament and the result is the winner of the tournament!) Note the input may or may not be "valid". We define valid input (recursively) as follows: • R, P, and S are valid (single-character) inputs. • (A&B) is also valid as long as A and B are valid. Note this means that, for instance we have: • R is valid (and the outcome is just R). • (R&R) is valid (and we define the outcome to be R). (R&P&S) is invalid. • R&P is invalid. • (R&(P)) is invalid. • )R&S( is invalid. • ((R&S)) is invalid. • (A&B) is invalid (invalid characters) (R& P) is invalid (invalid character(i.c., spacc)) 1. [50 points: 10 for public tests, 15 for private tests, 15 for source code, 10 for styling] Write a program that given an input, outputs either "VALID" or "INVALID" depending on the input. For this question you can assume • The input is a single linc. • The length of the input is at most 1000 characters. Input Sample Output Sample (R& (P& ((P&R)& (R&R)))) VALID Here is another example. Input Sample Output Sample R&(R&P) INVALID In this assignment we would like to implement a version of the rock paper scissors game, where the character R represents rock, P represents paper, and S represents scissors. The expression (R&S) represents a game between the rock and the scissors, and therefore the winner (and the outcome) will be R. We can also have morc complicated expressions. For example, ((P&S)&(R&P)) will be cquivalent to (S&P) which in turn is equivalent to S. (You can think of the expression as a kind of rock paper scissors tournament and the result is the winner of the tournament!) Note the input may or may not be "valid". We define valid input (recursively) as follows: • R, P, and S are valid (single-character) inputs. • (A&B) is also valid as long as A and B are valid. Note this means that, for instance we have: • R is valid (and the outcome is just R). • (R&R) is valid (and we define the outcome to be R). (R&P&S) is invalid. • R&P is invalid. • (R&(P)) is invalid. • )R&S( is invalid. • ((R&S)) is invalid. • (A&B) is invalid (invalid characters) (R& P) is invalid (invalid character(i.c., spacc)) 1. [50 points: 10 for public tests, 15 for private tests, 15 for source code, 10 for styling] Write a program that given an input, outputs either "VALID" or "INVALID" depending on the input. For this question you can assume • The input is a single linc. • The length of the input is at most 1000 characters. Input Sample Output Sample (R& (P& ((P&R)& (R&R)))) VALID Here is another example. Input Sample Output Sample R&(R&P) INVALID
Expert Answer:
Related Book For
Probability and Statistical Inference
ISBN: 978-0321923271
9th edition
Authors: Robert V. Hogg, Elliot Tanis, Dale Zimmerman
Posted Date:
Students also viewed these mathematics questions
-
A lead ball is located in situation A at 1m height in a gas column with air air = 1.2 kg / m, dynamic viscosity air = 18 x 10 -6 (Ns) / m and in situation B at 1m height in a gas column with...
-
The following game is a version of the Prisoners Dilemma, but the payoffs are slightly different than in Table. Prisoners Dilemma in Normal Form a. Verify that the Nash equilibrium is the usual one...
-
Consider a quasi-one-dimensional steady advection-diffusion flow with the boundary conditions as illustrated in Figure 1: u(x) x=0 p=0 in = puA = 1 x 10-4 -4 kg/s Figure 1 In Figure 1, the velocity u...
-
Using Porter's Five Forces Model, examine the impact of the market positioning on the selected product or service. Describe how each of the forces provides an advantage and disadvantage to the...
-
What is a single-station automated cell?
-
A pea plant that is heterozygous with regard to seed color (yellow is dominant to green) is allowed to self-fertilize. What are the predicted outcomes of genotypes and phenotypes of the offspring?
-
Air at \(1 \mathrm{~atm}\) and \(310 \mathrm{~K}\) enters a 2 -m-long rectangular duct with cross section \(80 \mathrm{~mm} \times 160 \mathrm{~mm}\). The duct is maintained at a constant surface...
-
M. Anthony, LLP, produces music in a studio in London. The cost of producing one typical song follows: Average Cost per Song: Labor, including musicians and technicians . . . . . . . . . . . . ....
-
5. A three-stage, single acting compressor is required to compress 135m of free air per hour from 1bar to 64bar. Prove that with complete intercooling the stage pressure ratio should be equal to the...
-
Your city recently won the bid to host its first NCAA Final Four men's basketball championship. Part of the costs of hosting the event were paid from a tax fund created to attract major events. A...
-
As per the drug and alcohol policy, ships personnel A) Cannot consume any other alcoholic beverages other than beer (or wine onbd dry vsls) B) All options are correct. C) Cannot consume any alcohol...
-
Trail Co. is expected to pay a cash dividend of $2.60 next year. This dividend is expected to grow at 5% to infinity. If you require a return of at least 9%, what is the most you should be willing to...
-
When a horse pulls a 94 kg buggy down the road with a force of 27 N, the buggy hitch makes an angle of 35 degrees above the horizontal. Neglecting friction, what is the magnitude of the buggy's...
-
Explain in a formal thank-you letter to Bethesda University for including Christianity within the curriculum of your education. You may want to include specific examples of how this has been a...
-
How can organizations ensure effective knowledge transfer and retention within their resource management processes, particularly during times of employee turnover or restructuring ?
-
Midway Metal, which uses the weighted average method. produces wire baskets in two departments, Bending and Painting. The Work in Process Inventory T-account for the Bending department is shown...
-
A 50 mm diameter square-thread screw having a pitch of 8 mm carries a tensile load of 15 kN. Calculate: - The axial stress on the screw - What is the min length of nut engagement needed if the...
-
Linda Lopez opened a beauty studio, Lindas Salon, on January 2, 2011. The salon also sells beauty supplies. In January 2012, Lopez realized she had never filed any tax reports for her business and...
-
Because of tourism in the state, it was proposed that public schools in Michigan begin after Labor Day. To determine whether support for this change was greater than 65%, a public poll was taken. Let...
-
Let X and Y have a bivariate normal distribution with parameters X = 10, 2x = 9, Y = 15, Y2 = 16, and = 0. Find (a) P(13.6 < Y < 17.2). (b) E(Y | x). (c) Var(Y | x). (d) P(13.6 < Y < 17.2 | X = 9.1).
-
The weekly gravel demand X (in tons) follows the Pdf However, the owner of the gravel pit can produce at most only 4 tons of gravel per week. Compute the expected value of the tons sold per week by...
-
Is the word anxiety a candidate for creating a stable pattern? If so, give reasons.
-
Define the real meaning of anxiety. What are the different meanings of this word?
-
Can you list six important benefits of this pattern?
Study smarter with the SolutionInn App