tildebot | Accept either order of prime factors

This commit is contained in:
rakiru 2018-07-17 22:47:52 +01:00
parent 888b3e871a
commit 3d2af2a72d
1 changed files with 6 additions and 1 deletions

View File

@ -44,7 +44,12 @@ def make_puzzle(obfuscate=True):
elif roll == 5:
p1 = random.choice(primes)
p2 = random.choice(primes)
answer = str(min(p1,p2)) + ',' + str(max(p1,p2))
def answer(guess):
# Check the the numbers entered are correct, regardless of order
# or surrounding whitespace.
attempt = sorted(word.strip() for word in guess.split(","))
correct = sorted([str(p1), str(p2)])
return attempt == correct
bonus = 1
puzzle += p.number_to_words(p1 * p2) + " when factored into its two primes (answer in the form of the two primes with a comma between)"
elif roll == 6: