r/programming • u/SilasX • 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
r/programming • u/SilasX • May 09 '15
2
u/vidude May 10 '15
Counter-example: 56 56554 56556
The correct answer is 565655656554, while your algorithm would give the answer 565565656554. I don't think you can escape doing some level of brute force analysis. The perl script below starts with a lexically ordered list but recursively tries all different orderings of numbers that have the same starting digit. Of course it degenerates to full brute force if all numbers start with the same digit. Dynamic Programming techniques could be used to improve this.