TL;DR
The whole story
Just recently:
Son: “Daddy, there are some math tasks I need your help with.”
Me: “Easy-peasy, bring it on!”
Son: “It’s something with letters and numbers…”
Me: “Ahhhhhhhhhhhhhhhhhhhhh!”
My worst nightmare: Cryptogram equations!
I consider myself as a fairly logical thinker but these are the tasks I always miserably fail in IQ tests or assessments. Just got no sense for these 🙁
So just for those who don’t know what cryptogram equations are:
You are given an equation where letters (or symbols) represent numbers and your task is to find valid solutions where each letter (or symbol) stands for exactly one number,
e.g.: AA * AA = ABA => 11 * 11 = 121 (A = 1, B = 2)
Google gave me some hints but the approaches / algorithms didn’t fully solve the problem or where rather complex.
So if I can’t solve it the computer has to (heard these boxes are good with numbers ‘n stuff).
But how?
Exactly!
“The reason why you should always find a brute force solution first” by Sam Gavis-Hughson
At first I wasn’t sure whether this can be brute-forced but actually there are “just” 3’860’000 possible combinations (with 10 letters / symbols representing the numbers from 0 to 9).
As this isn’t a high number for today’s computing power I’ve first drafted something in Java and when I saw that this basically takes no time I coded the final solution in JavaScript. There isn’t much exciting about the code (actually nothing). Just 10 nested for-loops (0..9) and some checking. Spits out all solutions in less than a second even on a mobile device and result looks like this:
Conclusion(s)
- I couldn’t actually help my son but at least his interest in programming increased (yet I hope he won’t take daddy’s route and learn/study something useful)
- Made my peace with the beast. Ha, now I know that I’m better than you! (Will fail the next test with a smile on my face.)
- Brute-force can be an efficient solution and can give you the time to write blogs or to have a drink with your colleagues instead of coding for hours
why you intresting about cryptogramme ?
I don’t. I bl**dy hate ’em 😉
Thank you so much! You saved me. I had to solve the same cryptogram for my son and spent more that 1 hour to solve only the first 2. And then spent 2 hours until I found your solution on internet 🙂
Happy to hear. So I’m not the only one with this problem. 😉