euler/Problem055.hs

14 lines
825 B
Haskell

-- A number that never forms a palindrome through the reverse and add process is called a Lychrel number. Due to the theoretical
-- nature of these numbers, and for the purpose of this problem, we shall assume that a number is Lychrel until proven otherwise.
-- In addition you are given that for every number below ten-thousand, it will either (i) become a palindrome in less than fifty
-- iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome.
--
-- How many Lychrel numbers are there below ten-thousand?
import Euler
step n = n + fromDigits (reverse $ toDigits n :: [Word8])
palindrome n = let ds = toDigits n :: [Word8] in ds == reverse ds
lychrel n = not $ any palindrome $ take 50 $ iterate step (step n)
main = print $ length $ filter lychrel [1..10000]