YEsterday was not fun Haskell, I did get it done, but it is horrible. Mostly my solution, some people on Reddit did it with mutable arrays, however, the whole point of doing AoC with Haskell, was to spend sometime programming in a purely functional language, for fun, away from my normal language of choice Rust and C++ if I have too. But in truth I think yesterday would have been a lot easier and more fun in Rust, at least for me :-)
Anyway today was a lot easier and got it done pretty quickly.
split::String->Char->String->[String]split[]_ss|nullss=[]|otherwise=[ss]split(x:xs)css|c==x=ss:splitxsc""|otherwise=splitxsc(ss++[x])parse::[String]->[(S.SetString,S.SetString)]parse=mapparse'whereparse'xs=let[fs,as]=splitxs'('""fs'=splitfs' '""(a:as')=map(takeWhile(/=')').dropWhile(==' '))(splitas','"")in(S.fromListfs',S.fromList$drop9a:as')generatefoods=valid<$>M.fromListWith(++)(do(is,as)<-foodsa<-S.toListasreturn(a,[is]))wherevalidis=S.filter(\g->all(g`S.member`)is)$S.unionsistask1foods=length$filter(`S.notMember`allValids)$concatMap(S.toList.fst)foodswhereisValiding=any(\a->ing`S.member`(generatefoodsM.!a))allValids=S.unions$map(\(ings,a)->S.filter(`isValid`a)ings)foodstask2=intercalate",".map(S.elemAt0.snd).M.toAscList.go.generatewhere-- Just like day 16 find foods which contain a particular allergen and repeat-- though a process of eliminationgo::M.MapString(S.SetString)->M.MapString(S.SetString)gov|all(\s->S.sizes==1)(M.elemsv)=v|otherwise=letfound=S.unions$M.elems$M.filter(\s->S.sizes==1)vingo$M.map(\s->ifS.sizes==1thenselsesS.\\found)vmain=dois<-readFile"day21_input"<&>lines<&>parseprint(task1is)print(task2is)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
YEsterday was not fun Haskell, I did get it done, but it is horrible. Mostly my solution, some people on Reddit did it with mutable arrays, however, the whole point of doing AoC with Haskell, was to spend sometime programming in a purely functional language, for fun, away from my normal language of choice Rust and C++ if I have too. But in truth I think yesterday would have been a lot easier and more fun in Rust, at least for me :-)
Anyway today was a lot easier and got it done pretty quickly.