For once, the JS version is compact :) - where's part 2, though ? 😊
A flat structure is indeed simpler to manage, given that we have to traverse the graph both ways (part 1 is basically "count all my parents" and part 2 "count all my descendents")
Haskell version (of both part 1 & 2)
norm=filterisAlphaNumruleOfr=let[color,bagStr]=splitOn" bags contain "rinsplitOn", "bagStr&filter(/="no other bags.")&map(unwords.init.words)&mapnorm&map(breakisAlpha)&map(\(a,b)->(normcolor,(reada::Int,b)))allContainersrulescolor=letcontainers=mapfst$filter((==normcolor).snd.snd)rulesincolor:concatMap(allContainersrules)containersallContainedrulescolor=letcontained=mapsnd$filter((==normcolor).fst)rulesin1+sum(map(\c->fstc*(allContainedrules.snd)c)contained)ans=dorules<-concatMapruleOf.lines<$>readFile"./data.txt"return(Set.size.Set.fromList.filter(/="shiny gold")$allContainersrules"shiny gold",allContainedrules"shiny gold"-1)
Damn, it's been a long time I haven't written a single line of Haskell...
I thought doing it with Haskell but... Pretty sure I would have given up already!
Good job!
Advent of code is quite a good occasion to practice or learn. So I figured "given that you like hurting yourself, why not doing it in Haskell ?" (I dont use it often)
For once, the JS version is compact :) - where's part 2, though ? 😊
A flat structure is indeed simpler to manage, given that we have to traverse the graph both ways (part 1 is basically "count all my parents" and part 2 "count all my descendents")
Haskell version (of both part 1 & 2)
Damn, it's been a long time I haven't written a single line of Haskell...
I thought doing it with Haskell but... Pretty sure I would have given up already!
Good job!
Advent of code is quite a good occasion to practice or learn. So I figured "given that you like hurting yourself, why not doing it in Haskell ?" (I dont use it often)
This is part 2!
Actually I always traversed in the same order. I just bruteforced in part 1, trying all possible start point 😂 This is my part 1 solution:
oh yes right :)