The python 'ord' function returns the ASCII number value for a given character -- for instance ord('a') == 97. By multiplying all the numbers in a given text, we create a common multiple that can be divided evenly by any letter contained in that text.
So, we simply check if the whole alphabet can evenly divide our 'text multiple', and we have a soft guarantee that the text contains the entire alphabet.
It's possible that longer texts can present false positives (I think?), but it should be pretty difficult to 'accidentally' generate number that's a multiple of every letter in the alphabet -- and hey, where's the fun without a few spooky bugs?
Just an idea to make your code messier, but making the logic bulletproof.
You need to assign a prime number to each letter. Easiest to use the first 26 prime numbers.
Then you can be 100% sure, when your text letters' assigned numbers give you the expected result of the first 26 primes multiplied, then your text passes. No false positives any more.
View all comments
Show parent comment
2
u/ArchCypher Feb 20 '21 edited Feb 20 '21
Full explanation:
The python 'ord' function returns the ASCII number value for a given character -- for instance
ord('a') == 97. By multiplying all the numbers in a given text, we create a common multiple that can be divided evenly by any letter contained in that text.So, we simply check if the whole alphabet can evenly divide our 'text multiple', and we have a soft guarantee that the text contains the entire alphabet.
It's possible that longer texts can present false positives (I think?), but it should be pretty difficult to 'accidentally' generate number that's a multiple of every letter in the alphabet -- and hey, where's the fun without a few spooky bugs?