Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Specification: hiddenWord and userGuess are both length- 5 strings containing lower case letters. The function returns a list L of 5 numbers, each of which

image text in transcribedimage text in transcribed

Specification: hiddenWord and userGuess are both length- 5 strings containing lower case letters. The function returns a list L of 5 numbers, each of which can be 0,1 , or 2 . For i=0,1,2,3,4, element L[i] will represent the "status" of the letter userGuess[i]. We will use the following rule to assign a status to each letter in userGuess: 0= letter does not appear in hiddenWord 1 = letter appears in hiddenWord, but not in the correct position 2= letter appears in hiddenWord in the correct position Examples: evaluateWord("snake", "boats") should return [0, 0, 2, 0, 1] evaluateWord("stole", "broom") should return [0,0,2,1,0] Note: If a letter in userGuess appears in hiddenWord in both matching and non-matching positions, then its status should be 2. Example: evaluateWord("slots", "boats") should return [0, 1, 0, 2, 2] Here globalLetterStatus is a length-26 array of numbers, which can be 1,0,1, and 2, userGuess is a 5-letter string with lower case letters, and letterStatus is a length-5 array with numbers 0,1 , and 2 . The idea is that globalLetterStatus[0] contains the status of the letter "a", globalLetterStatus[1] contains the status of the letter "b", globalLetterStatus[2] contains the status of the letter "c", etc. The meaning of the numbers in the globalLetterStatus list is as follows: -1 = corresponding letter has never appeared in any prior user guesses 0 = corresponding letter has appeared in a prior user guess, but does not appear in the hidden word 1 = corresponding letter has appeared in a prior user guess, but its position in the hiddenWord is not known to the user 2 = corresponding letter has appeared in a prior user guess, and its position in the hiddenWord is known to the user The function updates the list globalLetterStatus based on the current userGuess and letterStatus. Examples: Suppose globalLetterStatus =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1], userGuess = "testy", and letterStatus =[0,1,1,0,0]. Then calling updateGlobalLetterStatus(globalLetterStatus, userGuess, letterStatus) modifies globalLetterStatus to [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1] Suppose globalLetterStatus =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1], userGuess = "gruel", and letterStatus = [0,0,0,1,0]. Then calling updateGlobalLetterStatus(globalLetterStatus, userGuess, letterStatus) modifies globalLetterStatus to [1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,0,1,1,1,0,1] Suppose globalLetterStatus =[1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,0,1,1,1,0,1], userGuess = "stale", and letterStatus = [2, 0, 2, 0, 2]. Then calling updateGlobalLetterStatus(globalLetterStatus, userGuess, letterStatus) modifies globalLetterStatus to [2,1,1,1,2,1,0,1,1,1,1,0,1,1,1,1,1,0,2,0,0,1,1,1,0,1]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago