Skip to content

Instantly share code, notes, and snippets.

@aplainzetakind
Created December 7, 2020 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aplainzetakind/fb48c59ac152dff3f1dc97bd3374bd6c to your computer and use it in GitHub Desktop.
Save aplainzetakind/fb48c59ac152dff3f1dc97bd3374bd6c to your computer and use it in GitHub Desktop.
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