r/programming • • May 09 '15

"Real programmers can do these problems easily"; author posts invalid solution to #4

https://blog.svpino.com/2015/05/08/solution-to-problem-4
3.1k Upvotes

1.3k comments sorted by

View all comments

3

u/_exalt_ May 09 '15 edited May 09 '15

my oneliner: print(max([int(''.join(x)) for x in itertools.permutations(['56', '50', '5'])])) not efficient nor practical but i solved the problem in 5 seconds

1

u/lorddarkflare May 09 '15

After I realized that the obvious answer was wrong, this was my algorithmic solution as well.

Not very efficient for large lists, but easy to read and pretty much foolproof.

In the real world, if the list had a reasonable max length, I would consider this option.

I would at least consider it as a stopgap before implementing a mathematical solution.