The problem is simply is "Determining if the 196 algorithm will halt on the number 196". The 196 algorithm is very simple, reverse the input number, add it to the original input number, and halt if you have a palindrome, if you don't re-execute the algorithm with the new number. I wrote the 196 algorithm in java, and I just gave it a try by running it for a while, and writing the results to a file, I got a 39 MB file in 1 minute approx. and the algorithm didn't halt of course. Now am thinking about approaching the problem with a pen in my hand. If you think about it, the 196 algorithm will directly halt if you give it a number where all digits are less than 5, or otherwise, if every 2 opposing digits sum up not to yield a return ( > the output on a file to store it).
Code -> http://pastebin.com/f53aa5124
2 comments:
If you like these puzzles, you should try http://projecteuler.net/
At first they are very, very simple to solve. But after a while, straight brute force algorithms don't work anymore.
And the best thing is, after you've solved a problem, you get access to a discussion board with other people's solutions. And there is a lot to learn.
And I guess this is probably more fun than starting with a problem that no one has solved so far... ;-)
Wow, that's very good, I will visit right when I have time.
Post a Comment