in reply to Re^3: Challenge: Nearest Palindromic Number
in thread Challenge: Nearest Palindromic Number

halley,
Forgive my hasty initial response. I knew your method was flawed but gave a bad test case. 999 and 1001 are both valid when the input is 1000. Your method fails on the updated test case though 1085. The correct answer should be 1111.

Cheers - L~R

Replies are listed 'Best First'.
Re^5: Challenge: Nearest Palindromic Number
by halley (Prior) on Feb 02, 2005 at 19:45 UTC
    Which is why I initially mentioned that incrementing would be easy, to find the alternative. If the input isn't already palindromic, you have to find two palindromic alternatives. Roy Johnson wrote the code I foresaw: '10##'++ would be '1111'.

    --
    [ e d @ h a l l e y . c c ]