Code: Selecteer alles
module Puzzle
where
split' 0 = []
split' x = (mod x 10) : (split' (div x 10))
split x = reverse (split' x)
combine' [] = 0
combine' (x:xs) = x + (10 * combine' xs)
combine x = combine' (reverse x)
noZeros [] = True
noZeros (x:xs) = (x /= 0) && (noZeros xs)
noDuplicates [] = True
noDuplicates (x:xs) = (length (filter (\y -> y == x) xs) == 0) && (noDuplicates xs)
isPrime :: Int -> Bool
isPrime x | x < 2 = False
| x >= 2 = length (filter (\y -> (mod x y) == 0) [2..(x-1)]) == 0
checkDigits (a:b:c:d:e:rest) = (isPrime a) &&
(b == e - a) &&
(c == 2 * a) &&
(d == c + 3) &&
(e == abs (a - d))
checkRange x = map (combine) (filter (checkDigits) (filter (noDuplicates) (filter (noZeros) (map (split) x))))
solveIt = do
checkRange [10000..99999]