Created
December 7, 2020 18:35
-
-
Save aplainzetakind/fb48c59ac152dff3f1dc97bd3374bd6c 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
star2 :: [(String, [(Int, String)])] -> Int | |
star2 i = let m = M.fromList i | |
go n [] = n | |
go n kss = let n' = sum . fmap fst $ kss'' | |
kss' = fmap (\(c, (c', s)) -> (c * c', s)) | |
. concatMap sequence $ kss'' | |
kss'' = fmap (fmap (m M.!)) kss | |
in go (n + n') kss' | |
in go 0 [(1, "shiny gold")] | |
star2' :: [(String, [(Int, String)])] -> Int | |
star2' i = let m = M.fromList i | |
go st = case m M.! st of | |
[] -> 0 | |
cs -> sum (fmap fst cs) | |
+ sum (fmap (uncurry (*) . fmap go) cs) | |
in go "shiny gold" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment