Closest palindrome integer
An integer is a palindrome if it is written with the same decimal digits forward and backward. Your job is to write a function that takes an integer and returns the closes palindrome integer to it. The closest one could be larger or smaller than the given integer.
Examples
(closest-palindrome 100) ;=> 99 (return the smaller in case of tie)
(closest-palindrome 887) ;=> 888
(closest-palindrome 888) ;=> 888
Note: If two palindromes are equidistant from the given integer, return the smallest. If the given integer is itself a palindrome, return it.
Thanks to this site for the problem idea, where it is rated Hard in Ruby. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/