Created
May 8, 2015 22:34
-
-
Save anonymous/f7fd4013fe3c13e88279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data Op = Plus | Minus | Concat deriving Show | |
f l = concatMap (\r -> map (: r) l) | |
g = f [Plus, Minus, Concat] | |
allOps = iterate g [[Plus], [Minus], [Concat]] !! 7 | |
step :: Int -> Op -> (Int, Int) -> (Int, Int) | |
step prev op (carry, sum) = case op of | |
Concat -> (read (show prev ++ show carry) :: Int, sum) | |
Plus -> (prev, carry + sum) | |
Minus -> (prev, sum - carry) | |
output = zipWith (,) | |
(map | |
(\ops -> uncurry (+) $ | |
foldr (uncurry step) (9, 0) (zipWith (,) [1 ..] ops)) | |
allOps) | |
allOps | |
answers = filter ((== 100) . fst) output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment