Browse Source

more day 20 bs, day 21

canon
Hazel Levine 7 months ago
parent
commit
228c45a53e
Signed by: hazel GPG Key ID: 1884029A28789A62
  1. 4
      data/day21.test.txt
  2. 39
      data/day21.txt
  3. 200
      day20.rkt
  4. 72
      day21.rkt

4
data/day21.test.txt

@ -0,0 +1,4 @@
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
trh fvjkl sbzzf mxmxvkd (contains dairy)
sqjhc fvjkl (contains soy)
sqjhc mxmxvkd sbzzf (contains fish)

39
data/day21.txt

@ -0,0 +1,39 @@
xfdrdc jvns jxmvd fgr nfzmfc rqg zkbjn tfrgk vnqndg jbqrf kmx jvsp gvldp xxsg krhbv khcz bsvsgpv ckxhnn kcfj smcfc lmssp sccq czfhj vcdttr ggllbbq knsmcv sklfg nhdcrsm fcgdg vv xddnkh hmbfrf glpp phjf pvczp nhdm nlxsmb zrsx krpd fqgc nlxnmh qnnfsk jchhzn hxbnzg bhzhv vlbpsc mlr rnbhjk gdsqjpb knr qkg ttkp hgfx txfcjmgr qmkz qhrsjg hsqxc gzk bvnkk cvvlpx jpvz xpxpzj txhxn bfs vllzx bl gstcl jxlk hmjtv pxt jbhcfs rqq hktg trmzkcfg jtfxpx zjdhhql blxc dvbhvrc lljjv lslbrf zdprv czqmsht lkcg cvvqm (contains eggs)
ftkq qrfvp pqvz dkpgx gstcl zsdjf dhkbkh nlxsmb qjgkx jvns bhtnm rdzzx gvldp vzcnrt lqjkvt ktvngm trmzkcfg ttxvphb czqmsht jbhcfs nbmvrvtz glpp txhxn zpbgmqh vv jrdgbq jxghqb thjln lf fcgdg hmjtv shgm dchqtx hmbfrf vnqndg ngrn rnbhjk zkbjn mlr fqqcnjj fgr qmkz fqgc tgh mbmmhs bvnkk rrhjckjb xrssmn gqk sczgc czgv qvnsd dbgx vbldc sklfg hsqxc nztj dxm xgrvrpk zrls sqhvjzp (contains fish)
hmjtv fqqcnjj nlxnmh qhrsjg zkbjn dxznn cvvqm lslbrf nrpfgqg fgr gdsqjpb rxrf vhrngpv sgkbdf jtfxpx zjdhhql shgm blxc zdprv cpjpzs hhsn krpd fcgdg nlxsmb fvrqmm rrhjckjb rhgk czfhj qlk jbqrf pvl jcxr jchhzn jxmvd glpp vv lmssp pxt bvnkk xgrvrpk lf vzcnrt lqnmc gqk czgv bsvsgpv jlvvh xpxpzj ktvngm zpbgmqh qmkz trmzkcfg jvsp jxghqb bhtnm tvxxfrnl krhbv gzk jpvz pvczp lljjv jkjgmfr fdrqq lkcg cmnnlm dxm zrldmc jvns ttxvphb (contains soy)
kmx qlk vnqndg bmhr mksnj lqjkvt gdsqjpb khcz nbmvrvtz glpp jpvz dchqtx dbgx bvnkk bl jbqrf ckxhnn nztj cjrnk cpjpzs nlxsmb vv jtfxpx vqvm jchhzn qhhzc txhxn qkg jxghqb jvztb jcxr zrldmc qnnfsk qbnkv jlvvh zrls zdprv nhdm dxznn pvl jbhcfs rnbhjk nhdcrsm qvnsd sgfmv trmzkcfg zsdjf zrsx rttfvfrs xfdrdc cvvqm cvvlpx ttxvphb smcfc ktz (contains fish, eggs)
qdlxb czgv ffp fgr pvl rdzzx nhsxfc dxm jxmvd qmkz hzk nlxsmb ttxvphb qlk bvnkk vnqndg bmhr jrdgbq jxlk kmx gstcl jvztb nhdm trmzkcfg zrldmc bhzhv knsmcv vv jchhzn ttkp qnnfsk zrls sgkbdf qkg ktz pxt jpvz cmnnlm fvrqmm xxsg rqq zsdjf vzcnrt sgkp bl (contains nuts, soy, wheat)
jvns czqmsht gvldp sgkbdf ffp ttxvphb qmkz sqhvjzp qzfq ngrn csgf hmnqgbn dngmrr dhpm qnnfsk bhzhv rnbhjk nlxsmb fvrqmm xfdrdc svtb phjf gqk qgxftv jchhzn jbhcfs zrldmc dhkbkh jxlk txfcjmgr vlbpsc nbmvrvtz mksnj khcz rdzzx bvnkk vv qbnkv fcgdg hgfx jtfxpx rxrf rqg djtnh vbldc nhdcrsm hxbnzg tcjcn cvvqm lf nkkxt zdprv dxznn fkzfb nhsxfc zrls czfhj qkkb gcrfsb mzmz jpvz blxc (contains wheat, fish, nuts)
qlrcp lf nlxsmb cszgr txhxn tfrgk vv ngqf mxrm hhsn xqpsvm kmx bfs csgf sgkbdf jpvz nztj qlk trmzkcfg nnqq ttxvphb jvztb xfdrdc sxd fgr hcxdnj nhdm kgzbpxt gzk zdprv qmkz bvnkk vllzx rqg mbmmhs dhkbkh qhrsjg bmhr hgfx lkcg kgbd ngfhps dqq hzk qvnsd svtb pkjjt ckfhr (contains eggs, nuts, wheat)
qhrsjg mzmz ttxvphb dvbhvrc mcbnnp vv vnqndg nnqq fqgc vlbpsc dbgx nlxsmb jtfxpx qkg rhgk pkjjt rqq ftkq zrsx kmlxqx sqhvjzp jmdr smbvks lf hmbfrf bsvsgpv hcxdnj vqvm phjf vcdttr xgvz qrfvp qbnkv jcxr ffp lljjv bvnkk rnbhjk khcz rxrf jpvz dxznn trmzkcfg rttfvfrs hmjtv bmhr ttkp cszgr jxghqb krhbv fgr qkkb nfzmfc ckxhnn zrldmc txfcjmgr cpjpzs zjdhhql ggllbbq cmnnlm zkbjn qnnfsk (contains fish, dairy)
jpvz sblll ttxvphb lslbrf qjgkx ckfhr vhmh bmhr mlr ggllbbq fqqcnjj knsmcv qrfvp nhsxfc rxrf dvbhvrc ngrn jxghqb lljjv blxc csgf lqnmc vnqndg mcbnnp svtb sklfg hcxdnj bsvsgpv jrdgbq nnqq rrhjckjb bvnkk qsvkt bl pvl mzmz hmbfrf xfdrdc qmkz ftkq hmjtv czqmsht nfzmfc sccq dxm rdzzx qgxftv rqg jchhzn dxznn cszgr pqvz ngfhps trmzkcfg vv nlxsmb nhdcrsm cvvlpx (contains eggs, nuts)
txhxn lrkft jpvz gstcl nhdm gzk nhdcrsm sblll bsvsgpv rnbhjk cjrnk jlvvh zjdhhql smcfc dbgx sm hhsn nkkxt sgkbdf pxt nbmvrvtz ftkq jmdr lmssp fgr mlr csgf qmkz jvztb vllzx jvsp gcrfsb nfzmfc cjhk krhbv ttxvphb cvvqm svtb knsmcv dvbhvrc phjf sgfmv jjzh qnnfsk trmzkcfg qsvkt qlk cszgr xrssmn thjln bvnkk qvnsd dqq cpjpzs kcfj zpbgmqh qhhzc hcxdnj zkbjn xqpsvm pvczp khcz cvvlpx nlxnmh ckfhr lvbbgn txfcjmgr ktvngm dxm rhgk vv tgh fqgc vbldc (contains wheat, shellfish, fish)
qhrsjg bfs nkkxt fvrqmm ttxvphb lqjkvt nlxsmb mzmz lmssp lkcg cvvlpx qdlxb blxc gdsqjpb bl trmzkcfg phjf zrls qvnsd dxznn zjdhhql mxrm hcxdnj nlxnmh jmdr gstcl jvns jlvvh sccq vbldc smbvks qhcj nfzmfc dqq qmkz ktvngm rttfvfrs lrkft vv rnbhjk ngqf vzcnrt mbmmhs qgxftv djtnh qhhzc fgr jtfxpx sczgc vhmh cvvqm sgfmv jxmvd cjrnk mksnj kgbd jxlk gvldp kmx nhdcrsm ktz jpvz kcfj xpxpzj dhkbkh nnqq hxbnzg lqnmc sm (contains fish, shellfish)
czfhj nrpfgqg gstcl xddnkh jxlk mcbnnp hsqxc vnqndg kgzbpxt jmdr gzk vcdttr zrsx mlr jtfxpx vv ktvngm krpd smbvks sqhvjzp cjrnk gvldp dngmrr trmzkcfg qlk hmjtv qvnsd qhrsjg sccq hktg cvvlpx jvsp bvnkk ttxvphb jxghqb fvrqmm sm qbnkv zdprv tfrgk lmssp djtnh kmx lljjv rdzzx rnbhjk jpvz dvbhvrc fcgdg hzk jcxr mksnj fqqcnjj qhcj tcjcn zrldmc qmkz tvxxfrnl dxm hmbfrf bhtnm zsdjf vhmh khcz xqpsvm ffp fqgc rxrf xpxpzj krhbv sklfg (contains fish, shellfish)
qbnkv fgr rnbhjk csgf xrssmn ttkp trmzkcfg vv vhrngpv vqvm zrls xfdrdc fcgdg tfrgk lljjv kgzbpxt svtb pkjjt fdrqq nztj jchhzn cjhk djtnh kcfj vcdttr jmdr qlk bl hhsn cpjpzs hmjtv pvl nkkxt tgh jxmvd jvns jcxr dhpm nhsxfc sxd smbvks ckxhnn glpp bmhr dxm mlr jlvvh czqmsht txfcjmgr sczgc cvvqm nhdm gvldp sklfg sgkp nfzmfc gzk lf bvnkk nlxsmb qhrsjg ftkq gqk bsvsgpv dhkbkh jpvz nlxnmh mcbnnp qrfvp mxrm bhzhv ngfhps krpd kmx tcjcn jkjgmfr ttxvphb cjrnk zpbgmqh hsqxc (contains fish)
nztj jtfxpx zrls krhbv fqqcnjj bfs rqg kmlxqx xddnkh mlr gzk czfhj zsdjf qvnsd ckfhr czqmsht ngrn trmzkcfg dxm fdrqq jkjgmfr hcxdnj bl cjrnk xqpsvm xpxpzj tfrgk hmbfrf pkjjt lvbbgn nlxsmb lmssp bhzhv tvxxfrnl fgr sqhvjzp qzfq smcfc mksnj qjgkx vv lqnmc lkcg bvnkk gvldp qmkz shgm jpvz jxlk czgv pxt ffdc ttxvphb (contains nuts, peanuts, eggs)
mlr lqjkvt nrpfgqg djtnh nhdcrsm vv ktz gvldp zjdhhql gstcl qvnsd czgv xgvz csgf fqgc jxlk rdzzx nbfkp gdsqjpb fvrqmm hhsn lljjv dxznn zrldmc lvbbgn vhrngpv dhpm nkkxt hmbfrf hsqxc sm ttxvphb qrfvp bl xddnkh jvns rrhjckjb cjrnk lslbrf jmdr sczgc jvsp gzk rxrf qnnfsk zpbgmqh kmx qlk ktvngm trmzkcfg vzcnrt bmhr hcxdnj nlxsmb jpvz rnbhjk xxsg tcjcn qhhzc knsmcv qmkz rqq mzmz fgr ngqf gqk czfhj (contains shellfish, dairy, soy)
dkpgx qmkz sccq rnbhjk xgrvrpk vv gzk gcrfsb trmzkcfg dhkbkh zkbjn svtb fgr xpxpzj qkg ckxhnn zsdjf jcxr hgfx sqhvjzp djtnh vllzx rdzzx nlxsmb hmjtv nrpfgqg lslbrf ktz bvnkk ngfhps nbmvrvtz phjf zjdhhql lf pkjjt sxd ttxvphb dhpm nnqq kcfj zrldmc qjgkx jxghqb xddnkh vhrngpv nbfkp ftkq (contains peanuts, fish)
jvztb nhdm vcdttr cjhk qrfvp dbgx svtb jkjgmfr fgr tcjcn pvl bvnkk txhxn nztj sgkp fcgdg jtfxpx tgh jpvz lljjv zsdjf fqgc vv nfzmfc qkg knr gcrfsb trmzkcfg qzfq jxmvd rrhjckjb ftkq ttkp czgv qmkz sqhvjzp rnbhjk bhtnm hmjtv vhmh xddnkh mzmz jxghqb jchhzn ktvngm jvsp cjrnk bmhr rqg dhpm sm smcfc ttxvphb tfrgk vzcnrt qhcj fqqcnjj tvxxfrnl jjzh dxznn sblll rxrf dngmrr djtnh kgzbpxt nlxnmh lvbbgn qhrsjg rttfvfrs vnqndg cmnnlm sxd (contains fish, wheat)
ckfhr vzcnrt ngfhps ggllbbq sgkbdf cszgr qgxftv qdlxb bvnkk xqpsvm vv smbvks nbfkp lf bsvsgpv sblll qmkz trmzkcfg rnbhjk gdsqjpb jpvz gvldp qkg nbmvrvtz jmdr czqmsht fqgc dhpm qhcj sczgc vllzx tgh hsqxc qzfq blxc qrfvp krpd ttxvphb qjgkx tvxxfrnl khcz qhrsjg kmlxqx nztj dhkbkh gqk nkkxt rdzzx zpbgmqh tfrgk thjln rqg sgkp lkcg hzk ktvngm phjf (contains shellfish, dairy, soy)
qhhzc mbmmhs trmzkcfg smcfc rrhjckjb vlbpsc xgrvrpk zkbjn zrls lrkft qdlxb qmkz nbmvrvtz qjgkx qrfvp vv jjzh zsdjf qbnkv txhxn ttxvphb ckxhnn tvxxfrnl txfcjmgr sgkp qgxftv qlrcp qsvkt zrsx bhtnm qkg xddnkh krhbv hxbnzg phjf ttkp qlk cszgr sm jpvz kcfj bvnkk sklfg hmnqgbn pvl jbqrf cmnnlm dvbhvrc dqq mcbnnp kmx rqq rnbhjk zrldmc xqpsvm nnqq sqhvjzp ktz ffp vllzx hzk cvvlpx fqqcnjj vhrngpv nhdm vcdttr jxmvd (contains dairy, nuts)
gqk fvrqmm qmkz vqvm vcdttr rnbhjk hxbnzg kgbd vhrngpv fgr qkkb bvnkk zjdhhql cvvqm bfs mlr nrpfgqg tfrgk rqq dxznn vv nhsxfc nbfkp gdsqjpb vzcnrt dqq jvsp ttxvphb nlxnmh kmlxqx nhdm xgrvrpk kmx zrls sczgc sxd hmbfrf fcgdg xgvz ktz jbqrf dkpgx sqhvjzp mzmz bsvsgpv shgm dchqtx glpp qzfq vnqndg nbmvrvtz rdzzx bmhr trmzkcfg nlxsmb bhtnm hktg lslbrf pxt dhkbkh zsdjf mbmmhs sccq ttkp xpxpzj rttfvfrs dhpm (contains dairy, fish)
rnbhjk fcgdg rqq khcz lslbrf bfs vqvm nlxsmb rqg dvbhvrc mbmmhs kgzbpxt vlbpsc qmkz sgkbdf fdrqq sxd cpjpzs lqjkvt gcrfsb sqhvjzp pxt czgv jcxr vv jrdgbq vzcnrt cmnnlm jbhcfs qjgkx ngrn nhdcrsm dkpgx xrssmn gqk hmnqgbn ngfhps jmdr dxznn thjln xgrvrpk bvnkk dchqtx qnnfsk pqvz jpvz hzk gvldp djtnh csgf qgxftv hmbfrf smcfc lf sm svtb vhmh mlr ttkp ttxvphb dbgx tcjcn qlrcp zpbgmqh lrkft sblll lmssp qhrsjg phjf (contains eggs)
zjdhhql ftkq zrldmc vzcnrt dbgx bhzhv nlxnmh shgm nlxsmb qsvkt vlbpsc qvnsd nhdcrsm cjhk sklfg djtnh hmbfrf nhdm dhpm qkkb bvnkk smbvks vv pxt fcgdg lkcg blxc jpvz rxrf cszgr kmlxqx rnbhjk fvrqmm rqq ttxvphb cvvlpx rdzzx cjrnk qlrcp dxm bl nztj vhrngpv zkbjn qrfvp xpxpzj zrsx mlr qmkz qhhzc (contains peanuts)
zkbjn qrfvp vlbpsc sczgc jlvvh knsmcv ngfhps rnbhjk vv hktg cszgr ttkp jvztb dngmrr trmzkcfg cvvlpx djtnh tcjcn lmssp nlxsmb jbhcfs qvnsd qkkb sccq mzmz jtfxpx fcgdg lvbbgn cjhk pvczp qmkz sxd jcxr dqq bvnkk sgfmv hmbfrf cjrnk jkjgmfr xpxpzj rxrf rhgk jvsp blxc vllzx jpvz xgrvrpk ffp qlrcp hmnqgbn zsdjf nkkxt zrsx qgxftv czfhj vqvm lrkft kgzbpxt ngqf kgbd xfdrdc (contains soy)
dxm ftkq sccq ktvngm zrls lvbbgn gcrfsb cszgr vv xrssmn vzcnrt jchhzn rttfvfrs qmkz mbmmhs hmjtv qnnfsk nhdm qsvkt xxsg gvldp trmzkcfg svtb txfcjmgr jrdgbq bmhr sgkp cpjpzs bsvsgpv hmnqgbn glpp dxznn blxc nlxsmb fgr jtfxpx jpvz qhrsjg bvnkk fkzfb cvvqm qvnsd bl kmlxqx ngrn lqnmc lslbrf thjln kmx smcfc lrkft nfzmfc ttxvphb cjhk rrhjckjb dhpm (contains shellfish, eggs, nuts)
qmkz rxrf ngqf ttxvphb qrfvp qjgkx bfs hzk kgbd pvczp tfrgk jbqrf xgvz jxmvd nnqq qhhzc zrsx bl cmnnlm nbmvrvtz fvrqmm zpbgmqh fqgc hmnqgbn ttkp nhdm sgfmv jvns sccq hktg hmjtv ngfhps vqvm qlk qgxftv dchqtx sm rrhjckjb ffdc bvnkk dvbhvrc vhrngpv ktz smcfc jpvz trmzkcfg kmx mlr hcxdnj nkkxt nlxnmh czfhj smbvks jcxr rhgk rnbhjk ngrn krhbv txhxn sklfg shgm sxd krpd gvldp pxt dxznn thjln dkpgx jbhcfs hmbfrf pvl qzfq xfdrdc mcbnnp vv sgkp zdprv (contains wheat)
xgrvrpk zrsx ckfhr jtfxpx ckxhnn trmzkcfg qrfvp lslbrf smcfc bhtnm pxt rhgk jxmvd dngmrr jmdr czfhj djtnh cjrnk hgfx ktz qgxftv fqqcnjj hmjtv rrhjckjb mxrm zrldmc rttfvfrs tvxxfrnl qkkb ttxvphb dvbhvrc pvczp vhrngpv bl sblll jpvz jchhzn tcjcn qjgkx xxsg vv czgv dxm kmlxqx zpbgmqh hcxdnj lf jcxr zdprv nhsxfc smbvks vnqndg rdzzx nnqq sxd ffp nrpfgqg bvnkk sgkp qzfq gcrfsb ftkq nlxsmb rnbhjk rqq dbgx nkkxt pkjjt dhkbkh qlrcp fcgdg knr xgvz xrssmn (contains fish, soy)
pvczp bsvsgpv nfzmfc zpbgmqh qsvkt pkjjt jxghqb hgfx dxm xgrvrpk smbvks txhxn sgkp xfdrdc rttfvfrs tgh jpvz tcjcn bmhr cvvqm sccq rhgk nztj gzk vhrngpv ttkp nkkxt zrldmc ggllbbq xpxpzj qmkz ktvngm krhbv zrsx jchhzn mbmmhs gstcl hzk kgzbpxt dhpm fgr jbqrf sklfg ffp ttxvphb bvnkk jbhcfs dqq rqq mxrm rqg vhmh jkjgmfr hhsn qhrsjg jxmvd fdrqq rrhjckjb nlxsmb kmlxqx cszgr qrfvp nhdcrsm lljjv kmx tfrgk glpp cjrnk fvrqmm qnnfsk blxc nbfkp qzfq jvztb cjhk ngqf qgxftv zjdhhql zkbjn sqhvjzp czqmsht thjln djtnh rnbhjk gqk zsdjf shgm gcrfsb vv dkpgx (contains dairy, eggs)
cmnnlm sgkp qlk jvns sqhvjzp fvrqmm jpvz rhgk jbqrf rqq qzfq rnbhjk gvldp vv fkzfb ktz mzmz jtfxpx bhzhv txfcjmgr nlxsmb smbvks rdzzx jvztb jrdgbq ftkq qvnsd mlr gcrfsb mcbnnp fdrqq zsdjf trmzkcfg dvbhvrc ttxvphb hmjtv qhhzc fcgdg dkpgx rrhjckjb lmssp sccq qmkz pvczp krpd ckfhr svtb mxrm (contains wheat, soy, peanuts)
jxmvd mlr jkjgmfr hhsn rxrf qvnsd phjf vhmh lmssp ttxvphb lljjv qlrcp bsvsgpv qsvkt trmzkcfg kmx hxbnzg rnbhjk qmkz thjln fvrqmm hzk jbqrf nlxsmb lqjkvt hktg kgzbpxt fqgc qrfvp gcrfsb bvnkk txhxn qlk smcfc kmlxqx jpvz pqvz krpd gstcl fqqcnjj gzk nnqq lrkft tfrgk (contains fish, wheat, peanuts)
xxsg lqnmc jxlk phjf lljjv lqjkvt rdzzx kcfj nkkxt zjdhhql rnbhjk nbfkp nlxnmh hhsn jtfxpx nztj qrfvp xgrvrpk jpvz krpd jlvvh pxt lrkft qgxftv qjgkx trmzkcfg lmssp hmjtv ttxvphb xddnkh qsvkt rxrf vhrngpv hzk qmkz jcxr vv mxrm hmnqgbn smbvks vllzx gcrfsb bhzhv qlrcp qdlxb nlxsmb fqqcnjj ngqf txhxn jvztb knsmcv ktvngm (contains peanuts, dairy)
jbqrf tvxxfrnl mlr cvvqm zpbgmqh vlbpsc knsmcv xrssmn cjhk qkkb cpjpzs qnnfsk hmnqgbn hzk fdrqq vcdttr qmkz jcxr qrfvp vhrngpv pvczp fgr gstcl vnqndg tgh mbmmhs ktz rnbhjk lmssp qdlxb fqqcnjj xxsg nlxsmb trmzkcfg hktg qhhzc xddnkh pkjjt ngfhps ttxvphb xfdrdc rqg tcjcn zrsx smbvks dxm jtfxpx xpxpzj lf nztj vllzx qbnkv jchhzn nlxnmh jjzh sqhvjzp dbgx sczgc qhrsjg bvnkk xgrvrpk jpvz hmjtv dvbhvrc knr czgv hxbnzg (contains eggs, shellfish)
rnbhjk qvnsd nlxsmb krpd qbnkv kgzbpxt mzmz qzfq lqjkvt ngrn qhrsjg qhcj bhtnm trmzkcfg sqhvjzp blxc txfcjmgr ggllbbq jxmvd jrdgbq gvldp cmnnlm nhdm zsdjf sm vllzx hmbfrf dvbhvrc pqvz rdzzx jvns kgbd lljjv cvvqm lkcg knsmcv djtnh rqg rrhjckjb jkjgmfr vlbpsc tcjcn nbmvrvtz fqgc gqk hcxdnj vcdttr jtfxpx xrssmn lrkft pvl nkkxt ttxvphb csgf sxd bsvsgpv vv bvnkk qmkz (contains fish, soy)
tfrgk dxznn nfzmfc qmkz ngqf nkkxt sm hzk kmlxqx fgr jvsp gzk jkjgmfr hmbfrf dngmrr hgfx vcdttr ggllbbq rnbhjk ffp lqnmc zkbjn xxsg hktg qlk lqjkvt glpp vlbpsc rhgk pxt cjhk jxlk pvl lf hhsn dbgx jchhzn sxd sccq cszgr phjf qgxftv lmssp qkkb vhmh bfs bhtnm trmzkcfg dhpm smbvks nhsxfc fcgdg sgkp mlr smcfc xddnkh lrkft sgfmv mxrm lslbrf jtfxpx nlxnmh sgkbdf kgbd vv qdlxb ttxvphb bl xfdrdc ngfhps jpvz nhdm fqqcnjj thjln knr dchqtx knsmcv xpxpzj nlxsmb ngrn hcxdnj ttkp zsdjf jbhcfs blxc xrssmn ckfhr jvns qlrcp hmnqgbn ckxhnn svtb zpbgmqh ffdc gstcl jvztb shgm (contains shellfish, eggs)
gqk dbgx gstcl mxrm qjgkx qhrsjg jpvz bvnkk kmx fkzfb lrkft qzfq ttxvphb rxrf tgh bl vlbpsc fcgdg pvczp zrldmc kmlxqx dvbhvrc rnbhjk qgxftv vqvm thjln xqpsvm trmzkcfg bmhr nlxnmh qmkz pvl dngmrr khcz bsvsgpv phjf hcxdnj djtnh jkjgmfr jtfxpx ttkp nbmvrvtz czqmsht cvvlpx rqq xgrvrpk qlrcp hzk jchhzn jcxr vcdttr cjrnk sccq jlvvh vv (contains shellfish)
hhsn jxghqb fqgc sccq jrdgbq qnnfsk djtnh nkkxt nlxsmb xrssmn bhtnm krhbv sgfmv cvvlpx jcxr xgrvrpk jmdr bsvsgpv hktg qhcj vbldc cpjpzs lqjkvt hzk sgkbdf vnqndg ttxvphb lqnmc rrhjckjb kcfj lf rnbhjk blxc bvnkk hmbfrf nbfkp pvczp zkbjn fcgdg qmkz sczgc ggllbbq phjf trmzkcfg svtb dhpm jpvz (contains fish)
hmjtv qbnkv qhhzc mzmz rhgk ktvngm jvns hmnqgbn gqk zrldmc khcz sgfmv nfzmfc knr nhdcrsm jlvvh bfs jpvz ttxvphb rxrf ggllbbq nlxsmb sccq mcbnnp sgkbdf cszgr sqhvjzp pqvz trmzkcfg nnqq qhrsjg jxlk fqqcnjj fvrqmm rnbhjk vnqndg jbqrf mbmmhs czgv pvl sm nztj dbgx bvnkk hsqxc jjzh vv nhsxfc vlbpsc dchqtx jtfxpx xgvz hhsn bmhr jvztb qrfvp rqg zpbgmqh sxd jcxr jrdgbq thjln zrsx lkcg fqgc dhkbkh fdrqq cjhk (contains wheat, peanuts)
vv bvnkk rttfvfrs nnqq smbvks vzcnrt nbmvrvtz khcz hmjtv fgr zrls qmkz hmbfrf nhdm tfrgk ttxvphb lkcg dvbhvrc qkg mlr sccq jxghqb lrkft csgf sgkp zkbjn kgzbpxt jbqrf jpvz pxt krhbv rqg knr sm qjgkx nhdcrsm jmdr cszgr zrsx gvldp gzk zsdjf trmzkcfg pvl xddnkh ffp gdsqjpb pqvz vqvm dhkbkh sxd bmhr ffdc xpxpzj bhzhv nfzmfc rnbhjk lslbrf (contains shellfish)
bfs ftkq sqhvjzp ffp nlxsmb hgfx cvvlpx rdzzx kgzbpxt mbmmhs bvnkk jjzh xddnkh krpd dxm jchhzn qrfvp nbmvrvtz zrldmc ktz gvldp svtb zdprv vqvm mxrm zrsx nbfkp tgh rrhjckjb tvxxfrnl jtfxpx sm rqq dqq pkjjt nkkxt qdlxb jvztb vv fgr txhxn fdrqq gqk cjhk xgrvrpk rhgk lmssp fkzfb zrls ttxvphb smbvks jvns trmzkcfg hhsn jxghqb fqqcnjj vhmh dngmrr qsvkt gzk jlvvh tcjcn rqg ngqf dkpgx xpxpzj sgfmv tfrgk qmkz rnbhjk jxlk jcxr lslbrf pqvz fcgdg bhtnm zjdhhql jbqrf ngfhps bmhr (contains peanuts, soy, eggs)
zrsx dxznn lvbbgn hmbfrf rnbhjk nhdcrsm bhtnm xgrvrpk cvvlpx knsmcv bvnkk pxt qkkb qzfq vv zkbjn thjln qlrcp jrdgbq hhsn nztj mbmmhs khcz lqnmc vlbpsc rrhjckjb hmnqgbn hsqxc xfdrdc tfrgk czfhj zrls jpvz dhkbkh vllzx trmzkcfg zpbgmqh nfzmfc gstcl sgkbdf hxbnzg vcdttr nhdm tvxxfrnl lf pvczp vhrngpv nlxsmb ttxvphb nrpfgqg rdzzx jxghqb sccq xrssmn cmnnlm sblll sxd sqhvjzp qhhzc kmlxqx kcfj jlvvh gdsqjpb jmdr (contains soy)

200
day20.rkt

@ -1,6 +1,5 @@
#lang racket
(require "lib/common.rkt"
data/applicative (prefix-in f: data/functor) data/maybe data/monad
graph)
(struct posn (x y) #:transparent)
@ -75,116 +74,106 @@
# ## ## ###
# # # # # #")
; generates the number of times you need to rotate right
; hold board 1 fixed, mess with board 2
; there is a better way to do this. I am not doing it /deliberately/
(define (rotate-relative rot1 rot2)
(match rot1
['top (match rot2
['top 2]
['bottom 0]
['left 3]
['right 1])]
['bottom (match rot2
['top 0]
['bottom 2]
['left 1]
['right 3])]
['left (match rot2
['top 1]
['bottom 3]
['left 2]
['right 0])]
['right (match rot2
['top 3]
['bottom 1]
['left 0]
['right 2])]))
; stupid for no reason because memes
(define (direction-loop dir n)
(cond [(zero? n) dir]
[else
(direction-loop
(match dir
['top 'right]
['right 'bottom]
['bottom 'left]
['left 'top])
(sub1 n))]))
(define (board-flip-x board)
; flipping on the y-axis MEANS reversing all rows
(vector-map vector-reverse board))
(define (board-flip-y board)
; flipping on the x-axis MEANS reversing the vector
(define (board-flip board)
(vector-reverse board))
(define (board-rotate board)
(match-define (cons m _) (board-dim board))
(for/vector ([idx (in-range 0 m)])
(for/vector ([row (in-vector board)])
(vector-ref row idx))))
(define current-board-states (make-parameter (hash)))
(define (board-rotate-n! board n id upd)
(define cur (hash-ref upd id (cons #f #f)))
(hash-set! upd id (cons n (cdr cur)))
(define (board-rotate-n board n)
(for/fold ([brd board])
([i (in-range 0 n)])
([_ (in-range 0 n)])
(board-rotate brd)))
; generates an applicative functor that moves the board at id2 relative to id1
; also updates the input hash with the new transform
(define (generate-transform meta upd id1 id2)
; safely grabs data from the meta hash
; we want to be insensitive as to order, so check both possibilities
(define (get-from-meta [repeat #f])
(define val (hash-ref meta (if repeat (cons id2 id1) (cons id1 id2)) #f))
(cond [val (just val)]
[repeat nothing]
[else (get-from-meta #t)]))
; updates the metadata for the given id1 depending on former transforms
; once we place an id2, it becomes an id1. once an id1 is placed, it never becomes
; an id2 again, as it is permanently fixed in that position
(define (update-metadata rot1 mtch)
(match-define (cons rotation flip) (hash-ref upd id1 (cons #f #f)))
(define new-rotation
(if rotation (direction-loop rot1 rotation) rot1))
(define new-mtch (if flip
(match mtch ['match 'rev-match] ['rev-match 'match])
mtch))
(just (list new-rotation new-mtch)))
; generates the function to flip the board if we are reversed
(define (flip-if-needed rot2 mtch)
(define cur (hash-ref upd id2 (cons #f #f)))
(cond [(and (eq? mtch 'rev-match)
(or (eq? rot2 'left) (eq? rot2 'right)))
(just board-flip-x)]
[(and (eq? mtch 'rev-match)
(or (eq? rot2 'top) (eq? rot2 'bottom)))
(just board-flip-y)]
[else (just identity)]))
; generates the function to rotate the board
(define (rotate-if-needed rot1 rot2)
(just (λ (b) (board-rotate-n! b (rotate-relative rot1 rot2) id1 upd))))
; working in a maybe context...
(do [`(,rot1/u ,rot2 ,mtch/u) <- (get-from-meta)]
[`(,rot1 ,mtch) <- (update-metadata rot1/u mtch/u)]
[flip-fn <- (flip-if-needed rot2 mtch)]
[rot-fn <- (rotate-if-needed rot1 rot2)]
(pure (compose rot-fn flip-fn))))
; computes the entirety of the board, without trimming edges
(define (assemble dim G meta)
(define meta-board (make-hash))
(define corners
(for/list ([v (in-vertices G)]
#:when (= (length (get-neighbors G v)) 2))
(define (board-permutations board)
(for*/list ([fn (in-list identity board-flip)]
[rotations (in-range 4)])
(fn (board-rotate-n board rotations))))
(define (matching-ids meta id)
(define keys (hash-keys meta))
(for/list ([key (in-list keys)]
#:when (or (= (car key) id)
(= (cdr key) id)))
key))
(define (force-fit data board1 board2 direction)
(define (get-working-edge dir edges)
(match-define (list left right top bottom) edges)
(match dir
['left left] ['right right]
['top top] ['bottom bottom]))
(define work1 (get-working-edge direction (board-edges board1)))
(define (permutation-valid? perm)
(define opposing
(match direction
['left 'right] ['right 'left]
['top 'bottom] ['bottom 'top]))
(define work2 (get-working-edge opposing (board-edges perm)))
(eq? 'match (matching-edge? work1 work2)))
(for/first ([perm (in-list (board-permutations board2))]
#:when (permutation-valid? perm))
perm))
(define (meta-board-populated? meta-board x y)
(not (false? (board-ref meta-board x y))))
; populates the neighbors for the given id
; returns the ids and posns as pairs of the two boards placed
(define (populate-neighbors! mapping G meta id pt meta-board)
(define (next-posn direction)
(match-define (posn x y) pt)
(match direction
['left (struct-copy posn pt [x (sub1 x)])]
['right (struct-copy posn pt [x (add1 x)])]
['top (struct-copy posn pt [y (sub1 y)])]
['bottom (struct-copy posn pt [y (add1 y)])]))
(define (gen-next-posn from to)
(match-define (list _ dir _) (hash-ref meta (cons from to)))
(define p (next-posn dir))
(if (meta-board-populated? meta-board (posn-x p) (posn-y p))
#f
p))
(for*/list ([neighbor (in-list (get-neighbors G id))]
[next-psn (in-value (gen-next-posn id neighbor))]
#:when next-psn)
(board-set! meta-board (posn-x next-psn) (posn-y next-psn)
(hash-ref mapping neighbor))
(cons neighbor next-psn)))
; computes the entirety of the metaboard
(define (generate-meta-board mapping G meta)
(define dim (sqrt (hash-count mapping)))
(define meta-board (make-vector dim (make-vector dim #f)))
(define (top-left? id)
(define neighbors (get-neighbors G id))
(and (= (length neighbors) 2)
(for/or ([n (in-list neighbors)])
(eq? 'left (first (hash-ref meta (cons n id) '(#f)))))
(for/or ([n (in-list neighbors)])
(eq? 'top (first (hash-ref meta (cons n id) '(#f)))))))
(define top-left
(for/first ([v (in-vertices G)]
#:when (top-left? v))
v))
; begin by populating the top left
(board-set! meta-board 0 0 (hash-ref mapping top-left))
(define (populate-board! id pt)
(define res (populate-neighbors! mapping G meta id pt meta-board))
(cond [(empty? res) (void)]
[else (for ([nbr (in-list res)])
(match-define (cons nbr-id next-psn) nbr)
(populate-board! nbr-id next-psn))]))
; then populate starting with the top left...
(populate-board! top-left (posn 0 0))
meta-board)
(define (day20b input)
@ -207,10 +196,5 @@
(λ (prt)
(define input (parse prt))
(define-values (G meta) (gen-graph input))
; relative to 1951, 2311 should be to the right and have no other transforms
; so in effect, identity.
(check-equal? ((generate-transform meta (make-hash) 1951 2311) (just (hash-ref input 2311)))
(just (hash-ref input 2311)))
; relative to 2311, 3079 should be flipped across the x-axis
(check-equal? ((generate-transform meta (make-hash) 2311 3079) (just (hash-ref input 3079)))
(just (board-flip-x (hash-ref input 3079)))))))
(dbg meta)
(dbg (generate-meta-board input G meta)))))

72
day21.rkt

@ -0,0 +1,72 @@
#lang racket
(require "lib/common.rkt"
graph)
(define (parse prt)
(define (parse-line str)
(define-values (ingredients contains)
(match str
[(pregexp #px"(.*) \\(contains (.*)\\)" (list _ a b)) (values a b)]
[(pregexp #px"(.*)" (list _ a)) (values a #f)]
[else (error "oh no")]))
(list (string-split ingredients)
(if contains
(map string-trim (string-split contains ","))
#f)))
(map parse-line (port->lines prt)))
(define (generate-mapping input)
(for*/fold ([acc (hash)])
([food (in-list input)]
[allergen (in-list (second food))])
(define ingredients (list->set (first food)))
(hash-update acc allergen (λ (e) (set-intersect ingredients e)) ingredients)))
(define (day21a input)
(define mapping (generate-mapping input))
(define with-allergens
(for*/fold ([acc (set)])
([(_ ingredients) (in-hash mapping)])
(set-union ingredients acc)))
(define all-ingredients
(for*/list ([food (in-list input)]
[ingredient (in-list (first food))])
ingredient))
(define no-allergens (set-subtract (list->set all-ingredients) with-allergens))
(for*/sum ([noa (in-set no-allergens)]
[ing (in-list all-ingredients)]
#:when (equal? ing noa))
1))
(define (day21b input)
(define mapping (generate-mapping input))
(define edges
(for*/list ([(k v) (in-hash mapping)]
[f (in-set v)])
(list k f)))
(define G (undirected-graph edges))
(define match-hash
(for/hash ([i (in-list (maximum-bipartite-matching G))])
(values (second i) (first i))))
(define sorted-allergens (sort (hash-keys match-hash) string<?))
(string-join
(for/list ([v (in-list sorted-allergens)])
(hash-ref match-hash v))
","))
(module+ main
(call-with-input-file "data/day21.txt"
(λ (prt)
(define input (parse prt))
(answer 21 1 (day21a input))
(answer 21 2 (day21b input)))))
(module+ test
(require rackunit)
(call-with-input-file "data/day21.test.txt"
(λ (prt)
(define input (parse prt))
(check-equal? (day21a input) 5)
(check-equal? (day21b input) "mxmxvkd,sqjhc,fvjkl"))))
Loading…
Cancel
Save