Last active
August 29, 2015 14:01
-
-
Save codemonkey-uk/bc2a824c55fe16804818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A five digit number minus a four digit number equals 33333, | |
-- where the nine contributing digits are 1-9, each used only once. | |
import Data.List | |
slice start end = take (end - start + 1) . drop start | |
sliced :: String -> [Int] | |
sliced s = [read $ slice 0 4 s, read $ slice 5 9 s] | |
sub :: [Int] -> Int | |
sub (a:b:_) = a - b | |
findSolution str = [ x | x <- (map sliced $ permutations str), (sub x) == 33333 ] | |
main = putStrLn ( show $ findSolution "123456789") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment