Smarter algo, was Re: 03 digression by brute force

Peter Otten __peter__ at
Fri Dec 14 03:21:23 EST 2018

jfong at wrote:

> Just for fun:-) On my ooold PC, it takes 0.047 seconds to run the
> following algorithm on the problem 'SNED + MORE == MONEY".

> def tenThousand(u, Cin):  # Cin == M
>     global n
>     if Cin == M:
>         print(S, E, N, D, '+', M, O, R, E, '==', M, O, N, E, Y)
>         n += 1

And it probably took under two minutes with the brute force approach.
So if you were only interested in the result the code below were efficient 
only if it took at most two more minutes to write it;)

But seriously, the next step is to generalize this to work with arbitrary 
More fun!

More information about the Python-list mailing list