Answered step by step
Verified Expert Solution
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 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 precomputed. We have a finite set of inputs both the guess and the answer have only 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 waythen 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 theres 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 Tc T T 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 list of bool sListlistbool 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 commaseparated characters in no particular order, and returns a list of the indices corresponding to those characters: eg abc would return It should not matter what order the characters are in They should work with both upper and lower case letters ie would return the same as 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 rowcolumn lookup pair to be checked in the verifier, in the form ie pf type, tuple int int You will need to read the specific values from the file verifieraddress. in It is in the format guess, on each line. eg an input guess of returns 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 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 criteria A The Triangle Cospared to B The ramber of in the code D Nurber of Even numbers compared to Odd Evensodd Evensdd 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, eg 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 unknownnot checked for false result for true result a single turn with four verifiers D and checking aDb where a is the only true verifier would give the result for that turm as: If the guess list was and the turn history was the same as described above, the output of the function would be: tablexyzABCxx pay close attention to the number of spaces and line
In Part 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 precomputed. We have a finite set of inputs both the guess and the answer
have only 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 waythen 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 theres 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 Tc T T
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 list of bool sListlistbool 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 commaseparated characters in no particular order, and
returns a list of the indices corresponding to those characters:
eg abc would return
It should not matter what order the characters are in
They should work with both upper and lower case letters ie would return the
same as
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 rowcolumn lookup pair to be checked in
the verifier, in the form ie pf type, tuple int int
You will need to read the specific values from the file verifieraddress. in It is in the
format guess, on each line.
eg an input guess of returns
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 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 criteria
A The Triangle Cospared to B The ramber of in the code
D Nurber of Even numbers compared to Odd Evensodd Evensdd
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, eg
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 unknownnot checked
for false result
for true result
a single turn with four verifiers D and checking aDb where a is the only
true verifier would give the result for that turm as:
If the guess list was and the turn history was the same as described above, the
output of the function would be:
tablexyzABCxx
pay close attention to the number of spaces and line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started