# Alphametics exercise - Need help with performance

Hello!

I submitted a solution to this exercise (which passes all tests on my local) but fails on Exercism. If anyone has suggestions for improving the algorithm/performance I’d very much appreciate it. Thanks in advance. What is the error on the website?

Your tests timed out. This might mean that there was an issue in our infrastructure, but more likely it suggests that your code is running slowly. Is there an infinite loop or something similar?

Please check your code, and if nothing seems to be wrong, try running the tests again.

One way to get a big speedup is to precompute the total “weight” of each letter instead of evaluating each addend on every permutation. For instance, in “SEND + MORE == MONEY”, the E in SEND contributes 100, the E in MORE contributes 1 and the E in MONEY contributes -10 (negative because it is on the RHS). So the total weight of E is 100 + 1 - 10 = 91. Then for each permutation, do the dot product of the weights and the letter values and see if the result is zero. This is especially helpful on the big puzzle with 199 addends. Knuth discusses this approach in TAOCP 7.2.1.2.

Thank you so much for your suggestion! A few questions…

1. I understand a dot product of x-y coordinates, but not of an alphametics puzzle. Would you please provide an example of what you mean?

2. In your example, how do you know that the letter E in MORE is equal to 1?

3. Said another way: E is not 1 because the total weight = 91. Is that a correct assumption?