Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -2,34 +2,34 @@ import Nanoquery.Util; random = new(Random)
|
|||
|
||||
// a function to verify the user's input
|
||||
def verify_digits(input)
|
||||
global size
|
||||
seen = ""
|
||||
global size
|
||||
seen = ""
|
||||
|
||||
if len(input) != size
|
||||
return false
|
||||
else
|
||||
for char in input
|
||||
if not char in "0123456789"
|
||||
return false
|
||||
else if char in seen
|
||||
return false
|
||||
end
|
||||
if len(input) != size
|
||||
return false
|
||||
else
|
||||
for char in input
|
||||
if not char in "0123456789"
|
||||
return false
|
||||
else if char in seen
|
||||
return false
|
||||
end
|
||||
|
||||
seen += char
|
||||
end
|
||||
end
|
||||
seen += char
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
return true
|
||||
end
|
||||
|
||||
size = 4
|
||||
chosen = ""
|
||||
while len(chosen) < size
|
||||
digit = random.getInt(8) + 1
|
||||
digit = random.getInt(8) + 1
|
||||
|
||||
if not str(digit) in chosen
|
||||
chosen += str(digit)
|
||||
end
|
||||
if not str(digit) in chosen
|
||||
chosen += str(digit)
|
||||
end
|
||||
end
|
||||
|
||||
println "I have chosen a number from 4 unique digits from 1 to 9 arranged in a random order."
|
||||
|
|
@ -38,29 +38,29 @@ println "You need to input a 4 digit, unique digit number as a guess at what I h
|
|||
guesses = 1
|
||||
won = false
|
||||
while !won
|
||||
print "\nNext guess [" + str(guesses) + "]: "
|
||||
guess = input()
|
||||
print "\nNext guess [" + str(guesses) + "]: "
|
||||
guess = input()
|
||||
|
||||
if !verify_digits(guess)
|
||||
println "Problem, try again. You need to enter 4 unique digits from 1 to 9"
|
||||
else
|
||||
if guess = chosen
|
||||
won = true
|
||||
else
|
||||
bulls = 0
|
||||
cows = 0
|
||||
for i in range(0, size - 1)
|
||||
if guess[i] = chosen[i]
|
||||
bulls += 1
|
||||
else if guess[i] in chosen
|
||||
cows += 1
|
||||
end
|
||||
end
|
||||
if !verify_digits(guess)
|
||||
println "Problem, try again. You need to enter 4 unique digits from 1 to 9"
|
||||
else
|
||||
if guess = chosen
|
||||
won = true
|
||||
else
|
||||
bulls = 0
|
||||
cows = 0
|
||||
for i in range(0, size - 1)
|
||||
if guess[i] = chosen[i]
|
||||
bulls += 1
|
||||
else if guess[i] in chosen
|
||||
cows += 1
|
||||
end
|
||||
end
|
||||
|
||||
println format(" %d Bulls\n %d Cows", bulls, cows)
|
||||
guesses += 1
|
||||
end
|
||||
end
|
||||
println format(" %d Bulls\n %d Cows", bulls, cows)
|
||||
guesses += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
println "\nCongratulations you guess correctly in " + guesses + " attempts"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue