- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
digits n = reverse $ map (`mod` 10) (takeWhile (/= 0) (iterate (`div` 10) n))
fromDigits l = sum $ zipWith (*) (reverse l) (map (10^) [0..])
isPalindromic x = digits x == (reverse $ digits x)
f :: Integer -> [[Integer]] -> [Integer] -> Int -> [[Integer]]
f x founded lookedup niter
| niter > 50 = [notlychers, [x] ++ lychers ++ lookedup, zs]
| nextX `elem` notlychers = [[x] ++ notlychers ++ lookedup, lychers, zs]
| nextX `elem` lychers = [notlychers, [x] ++ lychers ++ lookedup, zs]
| isPalindromic nextX = [[x] ++ notlychers ++ lookedup, lychers, zs]
| otherwise = f nextX founded (x : lookedup) (niter+1)
where nextX = x + fromDigits (reverse $ digits x)
notlychers = founded !! 0
lychers = founded !! 1
zs = founded !! 2
g :: [[Integer]] -> [[Integer]]
g founded = f (x-1) [xs, ys, [x-1]] [] 0
where x = zs !! 0
xs = founded !! 0
ys = founded !! 1
zs = founded !! 2
gg n = g [[],[],[n+1]]
isLycher n = null $ (gg n) !! 0