Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Part 3 , we approached verifiers as programmatic structures - they compute some property of the input and return the result. It can be

In Part 3, we approached verifiers as programmatic structures - they compute some property of the
input and return the result. It can be observed, however, that with a finite set of inputs, the results
of any verifier can be pre-computed. We have a finite set of inputs - both the guess and the answer
have only 125 possibilities each. Thus with a finite amount of space, we can simply just list all the
possibilities, and use the guess and the answer to index them in some clever way-then it just
becomes a lookup table.
In this Part, we will use this approach to verifiers, though we will elide how they're computed and
which exact situation they correspond to.
Input Data
There are two main data inputs, stored in files, the verifierAddress. in file and the game card
files.
The verifieraddress. in gives the indexing scheme for which row and column to look in for a
particular guess.
The game cards have one string on the top line (the criterion). The rest of the file makes up the
verifier (there's some magic in how this data is computed so that the lookup works, and in the
board game these come as two separate pieces, allowing the lookup to change dependent on the
secret answer). You have been given four example verifier files, however the tests will use more
than these, so you can't simply hard code these ones.
The contents of the verifier files has the format (with different data in each of course):
The Tr sangle compared to a (Tc3, T*3, T>3)
Some definitions
You don't have to have variables with these names, but to simplify the documentation, here is what
these key conceptual components have been called
the criterion is a str describing the logic of checks made in the associated verifier.
verifier is a 2D list of bool s(List[list(bool)]) that checks the condition as described in
the criterion.
ganeCard is a tuple of the above (criterion, verifier)
Functions
For the actual task, you will implement a series of functions (no objects or classes herel) in the
machine.py file. You start with an empty .- section. This is not part of the tests, and you
may use it for your personal testing. All your functions should be defined in this file. The function
details are as follows:
inputcard takes a filename as a str and returns a ganeCard corresponding to the data in
that file (as described above).
getverifierInput takes a str of 3 comma-separated characters in no particular order, and
returns a list of the indices corresponding to those characters:
e.g., a,b,c would return ,1,2
It should not matter what order the characters are in.
They should work with both upper and lower case letters (i.e.,a,B,c would return the
same as a,b,c.
You do not have to check to ensure valid input.
The output list of int s should be sorted.
guesstoIndex takes a guess ( int) and retums the row-column lookup pair to be checked in
the verifier, in the form (x,y)(i.e. pf type, tuple [int, int]).
You will need to read the specific values from the file verifieraddress. in. It is in the
format guess, x,y on each line.
e.g., an input guess of 111 returns (2,5)
checkverifier takes a ganeCard and a guess as an int, and returns a bool stating if the
guess is true or false by obtaining the lookup pair, then looking in that location on the
verifier given by the ganeCard.
Listcriteria takes a list of ganecard s and returns a str listing the number of criteria, then
each condition indented by four spaces, and enumerated with an uppercase letter followed by
a close parenthesis, and then the criterion. An example of this format is:
You have 4 criteria
A) The Triangle Cospared to 3(T3,T=3,T>3) B) The ramber of 4s in the code (0x4,14,24,34)
D) Nurber of Even numbers compared to Odd (Evensodd, Evens0dd)
showTurnHistory takes a tist of past guess values and a tist of previous results and
returns a str formatted as a grid representation of the game state
past guesses are integers, so the list of past guesses is a list of integers, e.g.,[345,521,
314]
the turn history is a list of results of from each turn
a result is a list with an outcome for each verifier currently in use
the values in each list should follow:
& for unknown/not checked
1 for false result
2 for true result
a single turn with four verifiers (A-D) and checking a,D,b where a is the only
true verifier would give the result for that turm as: 2,1,8,1.
If the guess list was [124] and the turn history was the same as described above, the
output of the function would be:
\table[[xyz,A,B,C,0],[124,0,x,,x]]
(pay close attention to the number of spaces and line
image text in transcribed

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