commit 1492327fa770491b679fb1554d77c308bad0f2b9
parent 876324232bbfbf585128550408cf0bf516ee489e
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 21 Dec 2020 12:33:23 +0100
added day 21 and fixed helper scripts / config
Diffstat:
8 files changed, 300 insertions(+), 10 deletions(-)
diff --git a/data/helper/config b/data/helper/config
@@ -7,8 +7,7 @@ export AOCYEAR=2020
export SRCDIR="src"
# specify what files to copy to your day directory on prepare
-export TEMPLATE_DIR="data"
+export TEMPLATE_DIR="data/helper/template"
export TEMPLATE_FILES="
-main.c:main.c
-makefile:makefile
+main.zig:main.zig
"
diff --git a/data/helper/scripts/build b/data/helper/scripts/build
@@ -1,9 +1,7 @@
#!/bin/bash
-[ -z "$REPOROOT" ] && exit 1
-
-[ ! -e "$REPOROOT/cache" ] && mkdir "$REPOROOT/cache"
-zig build-exe --cache-dir "$REPOROOT/cache" \
- --pkg-begin "console8" "$REPOROOT/lib/console8.zig" --pkg-end \
- --pkg-begin "aoc" "$REPOROOT/lib/aoc.zig" --pkg-end \
+[ ! -e "$SOLUTIONS_ROOT/cache" ] && mkdir "$SOLUTIONS_ROOT/cache"
+zig build-exe --cache-dir "$SOLUTIONS_ROOT/cache" \
+ --pkg-begin "console8" "$SOLUTIONS_ROOT/lib/console8.zig" --pkg-end \
+ --pkg-begin "aoc" "$SOLUTIONS_ROOT/lib/aoc.zig" --pkg-end \
main.zig
diff --git a/data/helper/scripts/run b/data/helper/scripts/run
@@ -1,4 +1,4 @@
#!/bin/bash
-[ ! -e "main" ] && aoc build
+[ ! -e "main" ] && $HELPER_ROOT/scripts/build
$PWD/main $@
diff --git a/src/day21/input b/src/day21/input
@@ -0,0 +1,44 @@
+xfnblrf splqrb glvjzk dkjgz rcdlt tlsmzc ljmm pxk lbhqrq vcqvn cqdjsj nxnvv qgxrc fbhmh dxxntl gzpbkt lfvd rbkhld zzmx zkrz hhgt qnkx qgcp lfn lkcgn dzqc njskrg hzxvbms jcnz jknn cjtq ccbqz kmctc rfzvj ppj gvtg lnvnz ctjvj gkkmpl sbb fqhpsl prbrk zxncg zbbnj bhnfpcvd qdkfkf glzb kxhqn clzpsl kxjns jjmxj snrcdhk jzkk (contains soy)
+mtrx bkhft hzxvbms bsgzhx gzshkj dznsq qcjt thhpgh lfhx pxk glvjzk gzpbkt tvxsj zq glzb dsqj ssprv rdds rlfrp hdmt zkrz bhnfpcvd clzpsl jfvvd cdhvs mlqxlj csvvgp thrghc qzrgr kmrjz bmvp vjftvr qgcp fqhpsl qsmnqk rhzcpf jcnz fzc jzkk mhccvqc sfblpl zxncg hjgff pzr zbbnj lkcgn cjtq vjfz jkgbvlxh ppj xgsqv xfnblrf svbzk hnhk (contains dairy)
+dzqc hjgff ldbpm szlxt bsgzhx jsqxpg ssctn npd sbb zjzhk zbbnj rkttjb xfxf qsmnqk ppj bztrz prbrk zrkxbt ccbqz rjsjj gdtgj clzpsl qzrgr jkgbvlxh ns qnkx jcnz tzp qfsl vjmtq tpzdk snrcdhk mlqxlj pvslsq qjrb nkqskmp pjb lgbv chdfj gvtg qgxrc lbhqrq fqhpsl kmctc vjftvr dxxntl glzb gzpbkt cqdjsj nbljd (contains peanuts)
+vqrqz fqhpsl vcqvn jjmxj lbhqrq bsgzhx ssprv mjdjl dxgv jznbx jpngf cjxhzq crbmb cnxt clzpsl xs fzc lqjnxd kxbhrc ppj bztrz lptxlb qdkfkf xjnzfd sfqf grd qml hzzzb xfnblrf kmctc rhzcpf zxncg zbbnj smzzfxhn qjdbs snj npd thhpgh qgcp lrscdk vjftvr fbdmm dstsmrf csvvgp gkfbq jknn mbnv fxrc ns cpxgc prcgf pxk dxxntl gzshkj kxhqn lgbv hfvdbkz jbpzm xgsqv ckpt kmrjz glzb czcmvz rjsjj xrmjljb tzp qjrb jkgbvlxh cjtq rgm (contains fish, wheat)
+xrmjljb tpcf chdfj cjxhzq tvxsj bbbdrp cdhvs kxhqn lkcgn jmgj qcjt rlfrp dsqj dxgv zbbnj dzqc nngr tzp qfsl rdds vjmtq gkkmpl ctjvj kmctc hjgff qjrb bmvp pxk ns czcmvz mhccvqc glvjzk smvvl qml dxxntl qnkx hnhk zxncg jznbx sqhrd clzpsl ccbqz thrghc thhpgh njskrg jkgbvlxh glzb rfzvj vzgmd zrkxbt tpzdk scdvrs zzmx tdjl lfhx fqhpsl cpxgc xspt rcdlt vzjd (contains wheat, sesame, fish)
+hnhk qnppf zkrz qfgh jfvvd mxjc ccbqz jjmxj zq cpprq clzpsl ns rgm ffpsg vjmtq glzb hpqpp fxrc vqrqz hdmt prcgf rhdsb mthm tlsmzc fbhmh qjdbs tvxsj dstsmrf mlqxlj bkmf bhvb jsqxpg gkfbq lkcgn qgcp jznbx rcdlt rfzvj ppj jkgbvlxh tggl jknn cdhvs bbbdrp lbhqrq rkttjb fqhpsl qfgcq hjcz xspt rbrzc bztrz qnkx kxbhrc vhs bmvp jt skrdkp sklpqmx mbnv zbbnj bkhft sbb nmkk jmgj gzshkj zzllrz vjfz lnvnz zxncg (contains nuts, dairy)
+dxgv fqhpsl cdhvs rdds zbbnj snj cpprq nbljd qzrgr ljmm jpngf tfpxc jjmxj qfgh fbdmm jkgbvlxh dkjgz gzpbkt clzpsl vjmtq rhdsb vzjd rlfrp hqlqvt hhgt npd rjsjj tlsmzc tdjl vzgmd thrghc czcmvz rhzcpf vkcb zzllrz csvvgp lgbv qgxrc pxk smzzfxhn kxjns bkmf lbhqrq gdtgj hzxvbms thhpgh szlxt zq ppj sbb kmrjz hlrxgk zjzhk jl lnvnz plsrmjt dxxntl sqhrd qjdbs skrdkp qml lfn nngr zrkxbt dznsq jt qjrb vjfz zxncg mgzcgm rcdlt zzmx mjdjl vhs qgcp hfvdbkz bhnfpcvd fzc ccbqz bktkc dsqj lfhx cjtq qfsl dzqc bhvb xjnzfd (contains dairy, peanuts)
+sbb snrcdhk rhdsb txjk lkcgn thhpgh cpxgc zxncg ns sfqf hfvdbkz xgsqv hctssrm cjtq vjftvr nmkk zjzhk pxk dxxntl xspt sklpqmx glzb zq xfnblrf czcmvz qjdbs rbkhld tpzdk smvvl clzpsl njskrg kxhqn ppj svbzk jmgj qgxrc lfvd cnxt rbrzc qsmnqk pvslsq ckpt jkgbvlxh splqrb qgcp dzqc vjmtq bhvb qml zbbnj bkhft (contains peanuts, nuts, fish)
+tggl ccbqz bkhft crbmb vhs prbrk ljmm fqhpsl rzjjgq rbrzc cpprq mxjc xgsqv jkgbvlxh dxgv cjxhzq qjn bkmf ssctn czcmvz rdds xspt qfsl ppj rbkhld jpngf mgzcgm zzmx tvxsj lkcgn qnppf bmvp gvtg hjgff bsgzhx clzpsl kxbhrc sklpqmx hpqpp bhnfpcvd gkfbq nkqskmp vjfz pvslsq vjmtq hzzzb kmrjz smzzfxhn cdhvs lfvd mtrx grd prcgf qdkfkf lnvnz vzjd qml lgbv shqfzt chdfj glzb zxncg glvjzk zbbnj qcjt gzpbkt cpxgc nxnvv (contains dairy)
+zxncg hjcz zjzhk bktkc mthm rgm qcjt nkqskmp jmgj scdvrs ldbpm qfgcq kmrjz qjrb gjzt lqjnxd glzb hctssrm jznbx fzc kmctc grd jsqxpg mprh jcnz rkttjb bmvp cpprq vjftvr vkcb cjxhzq gzshkj skrdkp xfxf prcgf zbbnj mlqxlj clzpsl dxth snrcdhk xspt hzzzb rjsjj lnvnz qfsl hjgff hlrxgk lgbv jkgbvlxh fqhpsl zqpq rbrzc tfpxc dzqc (contains dairy, nuts)
+dstsmrf mjdjl bktkc qfgcq glzb jzkk ccbqz zbbnj cdhvs xfnblrf hpqpp gzpbkt cjxhzq mxjc ckpt fqhpsl qgcp jpngf rgm vzjd czcmvz kmrjz rkttjb mtrx txjk bkhft qdkfkf lnvnz njskrg pzr clzpsl xfxf lqjnxd bhvb xjnzfd szlxt gkkmpl dxgv crbmb hlrxgk tggl kmctc bbbdrp zrkxbt cpprq gzshkj snrcdhk grd dzqc smvvl vjmtq hzzzb qjrb zjzhk mgzcgm jjmxj ppj fvrns hctssrm xgsqv qsmnqk smzzfxhn mthm lfhx jznbx jt vcqvn kxjns ljmm sfqf jkgbvlxh (contains sesame, fish, nuts)
+cpxgc cdhvs dzqc fbhmh shqfzt ccbqz snj gzshkj jkgbvlxh bkhft hzzzb nbljd tzp zjzhk jjmxj ffpsg vjftvr cqdjsj dsqj sqhrd qfgh jpngf tggl sfblpl qnkx lptxlb chdfj fqhpsl jznbx gjzt ppj cpprq scdvrs tpcf hfvdbkz zbbnj zrkxbt fbdmm qzrgr glvjzk rjsjj zzllrz sklpqmx mgzcgm clzpsl qcjt zxncg rfzvj lgbv fxrc kqqns hpqpp lrscdk (contains eggs)
+hjgff lptxlb bbbdrp qml cnxt bktkc plsrmjt nngr pjb gkfbq lgbv rbrzc xgsqv xrmjljb vjmtq vkcb hzzzb qjrb jfvvd qfsl csvvgp smzzfxhn jkgbvlxh cdhvs zbbnj qcjt nxnvv tvxsj hctssrm clzpsl tpcf xfxf vhs qnppf mthm mbnv xspt kxfl bsgzhx jpngf txjk fqhpsl gzshkj gzpbkt tdjl hnhk rhzcpf dzqc thhpgh jbpzm jknn vzgmd cqdjsj ppj npd splqrb snrcdhk zxncg pzr gjzt mlqxlj jsqxpg lbhqrq fzc tzp bkhft hhgt ccbqz dznsq fxrc rcdlt (contains sesame, fish)
+rkttjb splqrb scdvrs jt lnvnz prcgf nmkk gkkmpl smvvl qzrgr ljmm mlqxlj cqdjsj ppj mhccvqc kxhqn rhdsb mxjc fqhpsl jkgbvlxh pvslsq zjzhk vqrqz tggl qjdbs jzkk fbdmm hdmt glzb lptxlb mprh cnxt qfsl prbrk gzpbkt bztrz smzzfxhn cpprq hjgff rlfrp gkfbq qgcp dzqc zqpq clzpsl jjmxj vjmtq dxgv qfgcq bkhft nngr pzr bhnfpcvd kxbhrc vkcb zbbnj mjdjl qnkx fbhmh rhzcpf hpqpp glvjzk sfblpl (contains nuts)
+gzshkj ssctn jknn fbhmh tggl xjnzfd mgzcgm tvxsj qnppf qgxrc rzjjgq ffpsg nkqskmp qgcp prcgf rcdlt xfnblrf jjmxj qsmnqk clzpsl ppj bsgzhx jfvvd cqdjsj vqrqz zbbnj vkcb tpcf cpxgc vjfz fqhpsl qnkx szlxt xrmjljb jzkk vjftvr dzqc dxth chdfj snrcdhk hctssrm nbljd nngr hhgt hzzzb nxnvv jkgbvlxh thhpgh sfblpl shqfzt zxncg qjn zjzhk (contains soy, eggs, nuts)
+glzb tvxsj zbbnj pvslsq xgsqv dstsmrf tpzdk qfsl clzpsl cjxhzq hjcz mprh kxjns tdjl jcnz vzgmd cdhvs nngr jkgbvlxh xjnzfd bkmf fqhpsl snrcdhk lfn qcjt zxncg mjdjl cpxgc gzpbkt bktkc tggl fvrns kmctc rlfrp mthm dzqc ssctn vhs kqqns bsgzhx crbmb dznsq npd tzp qml sfblpl hzzzb cqdjsj jbpzm sklpqmx fbdmm qzrgr bztrz bkhft jjmxj vqrqz qjn zjzhk (contains eggs, wheat)
+lrscdk clzpsl dxgv cdhvs czcmvz nngr skrdkp mlqxlj fzc dsqj hdmt ppj nbljd prbrk tpzdk qnppf bztrz hfvdbkz tdjl bhnfpcvd pvslsq kxfl hzxvbms dznsq bsgzhx lnvnz vjftvr cnxt mthm xfnblrf snj mprh rbkhld gzpbkt dzqc plsrmjt rhdsb zzllrz jkgbvlxh rfzvj xbjk cpxgc dkjgz kxjns jfvvd ffpsg glvjzk gdtgj zzmx xs mjdjl npd bkhft qcjt lgbv snrcdhk crbmb lkcgn kmctc mbnv rcdlt qzrgr ccbqz qjn fqhpsl zxncg vzgmd chdfj zbbnj (contains fish, eggs)
+dzqc rlfrp fqhpsl lqjnxd kmctc ppj lrscdk xs jzkk jl qnppf pxk jjmxj mhccvqc zzllrz njskrg clzpsl czcmvz tggl vkcb gjzt lfvd fbdmm shqfzt kmrjz tlsmzc xgsqv gkfbq sbb qzrgr txjk rfzvj sklpqmx zxncg lfhx hjcz zbbnj dznsq smzzfxhn mlqxlj bkhft scdvrs qfsl qfgcq pvslsq crbmb bsgzhx sfblpl tzp splqrb qcjt jznbx zjzhk tfpxc dkjgz jkgbvlxh jsqxpg kxfl ssprv gzpbkt fzc rbrzc vjmtq sfqf (contains soy)
+rjsjj kmctc mprh qnkx hlrxgk rcdlt xrmjljb prbrk qdkfkf rdds dkjgz zbbnj qsmnqk kqqns hnhk fqhpsl txjk qfsl bsgzhx szlxt tggl qjn ljmm ns bbbdrp pvslsq hzxvbms qzrgr kxhqn snj plsrmjt glzb qml nmkk tvxsj hqlqvt njskrg xfnblrf jcnz bkmf sfqf ppj thrghc pzr smvvl mtrx fbhmh cpprq dsqj lkcgn csvvgp czcmvz lgbv jjmxj lrscdk lfn jt dxxntl lfhx lbhqrq jmgj rgm qgcp dxth zkrz zq bhvb qcjt zxncg fxrc xdfpz dzqc bztrz dznsq zzllrz gjzt kxfl vzjd glvjzk cjtq dstsmrf gkfbq vhs clzpsl hfvdbkz svbzk vcqvn zqpq (contains eggs, dairy, sesame)
+cpprq zxncg lfhx mbnv hctssrm qfgh bktkc zbbnj gkfbq glzb chdfj dzqc mjdjl cjxhzq fbhmh dxgv pvslsq szlxt ljmm vhs lptxlb fqhpsl tpzdk hhgt czcmvz jjmxj shqfzt rdds cnxt bbbdrp smvvl glvjzk lnvnz nkqskmp prbrk dstsmrf lgbv xrmjljb smzzfxhn ctjvj rbkhld nngr xfxf lfvd hjcz xspt kmrjz jznbx txjk lqjnxd vjmtq cpxgc mgzcgm kxfl fxrc ppj qsmnqk ffpsg tpcf njskrg qzrgr kxhqn xdfpz nmkk hqlqvt ckpt hzxvbms rhdsb gkkmpl mlqxlj nbljd clzpsl gdtgj plsrmjt dkjgz svbzk (contains wheat, fish)
+hhgt hdmt hnhk dzqc kxfl vzgmd hlrxgk fbhmh rfzvj fqhpsl prbrk vjmtq tpcf dsqj plsrmjt rbkhld hjgff xjnzfd jkgbvlxh tggl clzpsl czcmvz zbbnj rjsjj cdhvs jl skrdkp cnxt qgcp zxncg nkqskmp lgbv vcqvn txjk kmrjz gkkmpl fzc fxrc mprh ppj xdfpz thrghc tdjl (contains fish, peanuts)
+qjn crbmb ppj pzr tlsmzc lkcgn dzqc kxfl csvvgp hzxvbms fbdmm rgm mbnv smzzfxhn bhnfpcvd zjzhk fqhpsl thhpgh hnhk glzb prcgf vjftvr qfgcq smvvl mthm qdkfkf ccbqz rbkhld jjmxj ns clzpsl vcqvn rfzvj gkfbq xbjk lrscdk rkttjb dxth zkrz zbbnj hfvdbkz hjcz dstsmrf ldbpm hzzzb xfxf bztrz zxncg snj gzshkj skrdkp mhccvqc lfhx vzjd gjzt lbhqrq pjb qnkx njskrg xs nxnvv qcjt (contains wheat, fish)
+rdds smzzfxhn qjdbs jsqxpg kqqns gvtg lgbv mxjc qfsl hctssrm rlfrp mprh jznbx snj fbhmh jt xrmjljb sqhrd qml ctjvj grd lbhqrq mjdjl glzb xgsqv rfzvj lrscdk gzpbkt lptxlb gjzt vqrqz kxbhrc thhpgh sfqf thrghc xdfpz fzc tpzdk svbzk glvjzk jmgj qzrgr shqfzt dkjgz cjtq lfvd clzpsl fqhpsl jfvvd sbb vcqvn splqrb qdkfkf hjcz ccbqz dzqc qgcp hhgt rkttjb dxxntl dznsq mbnv jkgbvlxh ckpt hlrxgk mtrx rjsjj cdhvs ppj npd cqdjsj qgxrc crbmb zzllrz dxgv tpcf rhdsb bkmf lnvnz jknn zxncg tfpxc (contains eggs, soy)
+jznbx bbbdrp jkgbvlxh zjzhk szlxt zbbnj bmvp hqlqvt xbjk hhgt ccbqz lnvnz rkttjb smzzfxhn splqrb dstsmrf sfqf fqhpsl hctssrm xrmjljb kxjns nngr lptxlb dzqc rhzcpf mthm zkrz thrghc jbpzm jl rjsjj ppj mlqxlj hfvdbkz tlsmzc chdfj xfxf rcdlt mgzcgm vcqvn hjcz glzb tfpxc tdjl vkcb qnppf pxk zxncg rhdsb (contains wheat)
+pjb qjn txjk dkjgz mlqxlj zzmx tdjl bmvp ljmm cpxgc kmctc clzpsl bztrz jkgbvlxh zxncg mjdjl bhnfpcvd hqlqvt lbhqrq pzr qzrgr plsrmjt vjmtq jjmxj dznsq nxnvv gdtgj skrdkp xdfpz snj rfzvj ssctn dxth vcqvn ldbpm pxk gkkmpl gvtg bbbdrp smvvl vzjd xfxf vhs zkrz zjzhk xgsqv vkcb dzqc ppj kxjns tlsmzc zbbnj sqhrd cnxt sfqf bktkc lfn cjtq qjdbs xrmjljb dstsmrf nmkk snrcdhk tfpxc fqhpsl zzllrz tpzdk tzp ns lqjnxd xjnzfd kqqns (contains sesame)
+rkttjb rbrzc dxxntl dkjgz njskrg qml cdhvs rlfrp hqlqvt grd jsqxpg clzpsl dxgv jknn ns ccbqz hzzzb kxfl zxncg npd mtrx gkkmpl qjdbs mthm xfxf bhnfpcvd hpqpp jznbx jmgj kmctc dsqj kxjns bbbdrp sfqf hjcz jkgbvlxh prcgf lnvnz jt rfzvj thrghc sfblpl mbnv gvtg qfsl qjrb fqhpsl mxjc mlqxlj smzzfxhn vjfz glzb cjxhzq kmrjz pvslsq xs rhdsb fbdmm bhvb snj vhs csvvgp kqqns vqrqz xspt mhccvqc kxbhrc gjzt ffpsg xjnzfd xgsqv svbzk hdmt jl zqpq jcnz nxnvv ppj qzrgr lfvd xfnblrf szlxt zbbnj qdkfkf tpcf zzmx (contains peanuts, wheat)
+szlxt smzzfxhn ssctn qjdbs ckpt zzllrz ffpsg thhpgh gvtg pxk ns xbjk fzc hqlqvt glzb ljmm xspt hctssrm zjzhk tfpxc qdkfkf lrscdk qsmnqk cpprq jznbx nbljd rcdlt njskrg cnxt rjsjj lfhx kxhqn svbzk jmgj hdmt lfvd kmrjz bhnfpcvd dxxntl qnppf gjzt txjk ccbqz crbmb jsqxpg kmctc xfnblrf shqfzt lptxlb hjgff hhgt xdfpz npd hzzzb smvvl ldbpm jjmxj skrdkp dzqc jbpzm xjnzfd mthm pvslsq bhvb mbnv sfqf rkttjb glvjzk dznsq gdtgj chdfj cqdjsj tvxsj vzjd rfzvj bsgzhx dxth jkgbvlxh czcmvz zxncg ctjvj ppj kxbhrc qzrgr zbbnj mgzcgm fqhpsl mprh (contains soy)
+gkkmpl bztrz lgbv jkgbvlxh zqpq cqdjsj mprh sfqf lfn mlqxlj rdds gzshkj jcnz xgsqv hjcz vjmtq dxxntl ssctn grd zbbnj rbrzc clzpsl sbb gdtgj kxfl hctssrm rzjjgq jpngf kmrjz zxncg dkjgz jzkk fqhpsl jjmxj hnhk hpqpp lptxlb mxjc njskrg xfnblrf dzqc xrmjljb tzp mthm qfgh ssprv ckpt rlfrp fbhmh tlsmzc zzllrz ppj qfgcq qjn svbzk rcdlt sfblpl xjnzfd vcqvn lkcgn mbnv mgzcgm lbhqrq qjrb bkmf nkqskmp fxrc gzpbkt hqlqvt cdhvs csvvgp (contains nuts, dairy)
+zrkxbt gjzt rzjjgq qjn jznbx jcnz ssprv mjdjl cnxt vkcb kmctc xrmjljb rbrzc mhccvqc tpcf hdmt jbpzm zbbnj nkqskmp pvslsq snj glzb ppj cjxhzq tzp qfsl rlfrp hfvdbkz glvjzk hpqpp jsqxpg dzqc sfqf vjftvr rhzcpf czcmvz qnppf lgbv xfnblrf fxrc prcgf bsgzhx clzpsl mprh hhgt dstsmrf kmrjz jpngf smvvl zxncg shqfzt qjdbs hzxvbms ffpsg fzc dkjgz hqlqvt vqrqz hctssrm vzgmd txjk tvxsj kxhqn jfvvd nxnvv sfblpl vcqvn fqhpsl zq zqpq hjgff pxk vjfz bkhft cpprq chdfj plsrmjt (contains sesame)
+prcgf lqjnxd shqfzt qgxrc zxncg qjn fqhpsl kxfl bkhft glzb xbjk jkgbvlxh ppj pjb hpqpp hzxvbms vzgmd nxnvv xs tggl xspt hhgt tpzdk jznbx dkjgz hjgff bztrz qfgh lgbv mthm zzllrz zbbnj bmvp mxjc prbrk lfn mlqxlj vhs qdkfkf njskrg zq xdfpz qcjt kxjns dzqc zqpq qzrgr glvjzk (contains nuts, eggs, soy)
+vhs jbpzm lfvd zq gjzt qnppf zkrz bmvp mgzcgm sklpqmx jmgj szlxt jkgbvlxh thrghc bkmf tggl splqrb mjdjl lrscdk qfgcq lfhx qdkfkf gkfbq pvslsq hfvdbkz xrmjljb smvvl mhccvqc rhzcpf qzrgr zjzhk zzmx bztrz fvrns fqhpsl sqhrd hjcz thhpgh zxncg chdfj txjk clzpsl ckpt shqfzt ppj tpzdk glvjzk zbbnj bhvb vcqvn glzb lkcgn (contains nuts, wheat)
+tpcf rbkhld fqhpsl lkcgn mlqxlj xjnzfd jkgbvlxh dzqc qfgh rgm zbbnj hpqpp glzb clzpsl cpxgc dstsmrf rjsjj glvjzk ppj mxjc prbrk plsrmjt kmrjz hdmt pjb szlxt cdhvs xs nkqskmp fbhmh grd jl ns hctssrm bbbdrp bhvb xfnblrf zkrz rzjjgq thhpgh kxbhrc npd rkttjb vhs chdfj jknn ckpt (contains wheat, dairy, sesame)
+snrcdhk gvtg dkjgz bktkc gjzt svbzk ljmm kxhqn rgm hhgt dxth pvslsq nbljd jzkk sqhrd rjsjj xfnblrf ssctn qsmnqk czcmvz hpqpp vcqvn sfqf tpzdk mbnv zbbnj lfhx bhnfpcvd nxnvv fqhpsl vjmtq lbhqrq xrmjljb jfvvd rzjjgq bhvb nkqskmp gzpbkt zxncg mhccvqc zrkxbt hqlqvt mthm cjtq mgzcgm vqrqz rhdsb prbrk clzpsl mjdjl rdds npd rfzvj ckpt splqrb qfgh xgsqv tlsmzc ctjvj vhs glzb nmkk ssprv rlfrp sbb tfpxc rcdlt kmctc cnxt jl rbrzc mprh hctssrm scdvrs zzmx jt smvvl prcgf ffpsg gzshkj mlqxlj fzc fvrns lrscdk gkfbq crbmb dzqc rkttjb ppj (contains soy)
+ldbpm zrkxbt ctjvj ppj sbb gzshkj cjtq xfxf jmgj zqpq hfvdbkz dznsq vzjd lbhqrq rkttjb sqhrd rhdsb xs vcqvn dxgv tvxsj jkgbvlxh ljmm bktkc zxncg ns tpzdk mxjc xrmjljb tzp fxrc kmctc jfvvd jbpzm lgbv jjmxj qdkfkf plsrmjt lrscdk tfpxc mlqxlj fqhpsl mtrx ffpsg nmkk rdds xjnzfd mthm cdhvs vjfz nbljd clzpsl xfnblrf dzqc jknn glzb dxxntl jcnz sfqf ccbqz pjb vjftvr (contains eggs)
+thrghc nngr rbkhld kxfl szlxt tpcf vzgmd zxncg snj hhgt mthm fbdmm hdmt rhdsb tfpxc bkhft bktkc jcnz qml mjdjl jkgbvlxh bmvp cpprq hnhk vjftvr fxrc lnvnz fqhpsl qnkx pxk zjzhk prbrk npd bsgzhx mgzcgm dzqc qgxrc cqdjsj clzpsl pvslsq smvvl ppj jmgj tggl vkcb svbzk qjrb dkjgz lrscdk lfn rhzcpf hctssrm qfgh ckpt xbjk ssctn qfsl zbbnj (contains sesame, dairy, eggs)
+glzb gjzt ssctn mjdjl splqrb bbbdrp skrdkp fqhpsl vjftvr ppj qjrb qdkfkf qfgh cqdjsj clzpsl zkrz jjmxj sfblpl zxncg tdjl mthm zqpq rhdsb dstsmrf xfnblrf gdtgj vhs njskrg bktkc xgsqv nkqskmp gkfbq vkcb pvslsq hdmt grd qjn ldbpm nngr lnvnz qml qcjt vzjd npd zbbnj tggl rbrzc gkkmpl kmctc pjb dzqc tzp qnkx (contains eggs, soy, dairy)
+vzgmd jbpzm hqlqvt kxfl gzpbkt fbhmh smzzfxhn glzb jjmxj xfnblrf fqhpsl gkfbq hctssrm lfvd hjgff vjfz mhccvqc svbzk tdjl rdds vzjd mbnv mjdjl jcnz lgbv xfxf plsrmjt ppj rfzvj jl jpngf xjnzfd xbjk zrkxbt ffpsg qgxrc lfn zbbnj jkgbvlxh chdfj rhzcpf jfvvd dsqj zxncg cpxgc dzqc prcgf jknn cqdjsj lptxlb hlrxgk prbrk fxrc gjzt (contains peanuts, soy, wheat)
+qsmnqk jjmxj hpqpp jkgbvlxh zqpq tpzdk fbhmh jfvvd lbhqrq fxrc kmctc chdfj thrghc pzr xs qnppf nmkk vqrqz mtrx xbjk lfvd zrkxbt sqhrd ssprv hjcz cpprq mbnv kxbhrc dxgv qfsl ldbpm sbb zxncg vjfz prbrk dzqc zzllrz mgzcgm hqlqvt sfqf csvvgp vzgmd vjmtq gkfbq npd dstsmrf qdkfkf lrscdk tggl clzpsl mxjc qzrgr pjb mhccvqc tzp ppj pvslsq zzmx jl rlfrp rdds dsqj gvtg tpcf mlqxlj fqhpsl tvxsj rhzcpf mthm cpxgc thhpgh zbbnj hhgt shqfzt xrmjljb dxth (contains nuts)
+lfn dsqj hdmt jbpzm mxjc dxth crbmb zxncg nxnvv kmctc cjtq ppj fqhpsl ssctn bhnfpcvd tpcf tdjl mthm lbhqrq lfvd mbnv ctjvj ns qnkx jsqxpg dzqc qml bktkc fbdmm rhdsb clzpsl pxk xrmjljb mgzcgm rhzcpf qsmnqk prcgf thrghc rdds vjfz vqrqz lfhx lqjnxd thhpgh cpprq mtrx jpngf cdhvs nngr rfzvj qcjt kqqns lnvnz zq rzjjgq xspt pvslsq vkcb vjftvr xjnzfd kxjns rlfrp xgsqv zzmx jkgbvlxh gkfbq hjcz rcdlt sqhrd tzp glzb snj (contains wheat)
+gzpbkt clzpsl mbnv jkgbvlxh qjn jznbx ljmm jjmxj ssprv ppj vjmtq kxbhrc hlrxgk rbkhld lnvnz chdfj bsgzhx zbbnj hpqpp hctssrm bkhft nmkk rbrzc thhpgh hzxvbms gvtg gkkmpl qgcp jmgj glzb mlqxlj cpxgc glvjzk kxjns gzshkj xjnzfd vhs mxjc rfzvj fbdmm prcgf grd npd ns smvvl rhdsb snj bmvp tpcf xbjk txjk hfvdbkz dzqc mprh rdds qsmnqk vjftvr jzkk sqhrd zjzhk qfgh rjsjj zqpq zxncg dsqj rkttjb lrscdk hzzzb thrghc qnkx mgzcgm tfpxc qgxrc jknn xfxf nngr dkjgz jcnz ctjvj rlfrp (contains fish)
+jkgbvlxh bbbdrp scdvrs sqhrd zbbnj mlqxlj hfvdbkz ctjvj gkkmpl gdtgj bktkc rbrzc rzjjgq cqdjsj qcjt vcqvn dznsq dsqj pvslsq xs czcmvz mprh glzb xspt vjftvr mgzcgm dzqc tggl kxjns hdmt clzpsl lfn dxxntl rgm lkcgn fqhpsl rcdlt lrscdk fbdmm jpngf hqlqvt qjrb gzpbkt jzkk ppj szlxt lfvd jbpzm ldbpm tfpxc kmrjz qjn hnhk zkrz hjgff pzr ljmm snrcdhk nkqskmp qfgcq lbhqrq qsmnqk hhgt sfblpl prbrk xfnblrf shqfzt kxhqn jknn snj bztrz qml (contains wheat, peanuts, sesame)
+zrkxbt lfn kmctc qjrb bkhft plsrmjt zkrz qfgcq xdfpz qdkfkf hdmt vkcb jt bsgzhx nkqskmp jl dzqc vhs hjgff zbbnj gzshkj rbkhld tzp ckpt bztrz tggl bktkc hctssrm dstsmrf csvvgp qzrgr lgbv dxxntl rjsjj mprh qgxrc mxjc ppj mgzcgm hlrxgk skrdkp ljmm snj zqpq vjfz jcnz kxjns fvrns npd vzgmd kxfl cnxt mtrx hfvdbkz xfxf rhzcpf bkmf zjzhk hnhk cqdjsj clzpsl jkgbvlxh kxbhrc tpcf lqjnxd lrscdk zxncg bhvb fqhpsl sqhrd qnkx pvslsq ns rzjjgq cpprq mbnv vzjd fxrc jpngf rlfrp rhdsb cpxgc gkfbq vcqvn tpzdk kqqns (contains eggs)
+clzpsl mtrx fbhmh gkfbq ldbpm vzgmd hpqpp fvrns dxgv jmgj txjk bhvb snrcdhk cjxhzq zxncg cpxgc dxth skrdkp ppj rkttjb sfblpl zzmx xdfpz vjmtq csvvgp rhdsb dznsq ccbqz lnvnz pxk cdhvs glzb xfxf qfgh lgbv gzshkj jznbx vcqvn xjnzfd xrmjljb fqhpsl tggl mbnv tdjl fxrc qgcp vjftvr jsqxpg dzqc cqdjsj cpprq glvjzk hdmt tzp plsrmjt grd nngr lfhx bhnfpcvd zbbnj vhs lkcgn jjmxj lfn svbzk qsmnqk qnppf mlqxlj ljmm tpzdk sklpqmx szlxt mhccvqc nkqskmp hzxvbms rcdlt hlrxgk rgm (contains nuts, soy)
+shqfzt kxhqn vzjd jjmxj dzqc bktkc ldbpm glvjzk cqdjsj lptxlb xs lqjnxd vjftvr clzpsl bsgzhx xdfpz qzrgr qml nxnvv jkgbvlxh crbmb qfsl glzb njskrg fvrns fzc bhnfpcvd ljmm hhgt ns dxgv hfvdbkz jfvvd tggl dxxntl xspt lkcgn qsmnqk jpngf plsrmjt fqhpsl rdds ssctn lfvd ppj zbbnj qcjt zzllrz bkmf sqhrd jl smzzfxhn (contains peanuts, fish)
diff --git a/src/day21/input-test b/src/day21/input-test
@@ -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)
diff --git a/src/day21/main.zig b/src/day21/main.zig
@@ -0,0 +1,180 @@
+const std = @import("std");
+const aoc = @import("aoc");
+
+const hasher = std.hash.CityHash32;
+const IngredientInfo = struct {
+ count: u32,
+};
+const Pair = struct { ingredient: []const u8, allergen: []const u8 };
+
+fn freeListmap(listmap: *std.AutoHashMap(u32, std.ArrayList(u32))) void {
+ var mapit = listmap.iterator();
+ while (mapit.next()) |kv| {
+ kv.value.deinit();
+ }
+ listmap.deinit();
+}
+
+fn getAllergen(allergens: *std.AutoHashMap(u32, std.ArrayList(u32)), ingredient: u32) ?u32 {
+ var allergenit = allergens.iterator();
+ while (allergenit.next()) |alg| {
+ if (alg.value.items.len == 1 and alg.value.items[0] == ingredient)
+ return alg.key;
+ }
+ return null;
+}
+
+fn updateAllergens(allocator: *std.mem.Allocator, allergens: *std.AutoHashMap(u32, std.ArrayList(u32)), allergen: u32) !void {
+ var next = std.ArrayList(u32).init(allocator);
+ defer next.deinit();
+
+ try next.append(allergen);
+
+ while (next.items.len > 0) {
+ const key = next.items[0];
+ var ingredient = allergens.getEntry(key).?.value.items[0];
+ var mapit = allergens.iterator();
+ while (mapit.next()) |alg| {
+ if (alg.key == key) continue;
+ const ind = std.mem.indexOfScalar(u32, alg.value.items, ingredient);
+ if (ind != null) {
+ _ = alg.value.swapRemove(ind.?);
+ if (alg.value.items.len == 1) {
+ try next.append(alg.key);
+ }
+ }
+ }
+ _ = next.swapRemove(0);
+ }
+}
+
+fn parseAllergens(allocator: *std.mem.Allocator, allergens: *std.AutoHashMap(u32, std.ArrayList(u32)), unhash: *std.AutoHashMap(u32, []const u8), ingredient_counts: *std.AutoHashMap(u32, u32), input: []const u8) !void {
+ var ingredients = std.ArrayList(u32).init(allocator);
+ defer ingredients.deinit();
+
+ var lineit = std.mem.tokenize(input, "\n");
+ while (lineit.next()) |line| {
+ var allergen = false;
+
+ try ingredients.resize(0);
+
+ var spaceit = std.mem.tokenize(line, " ");
+ while (spaceit.next()) |word| {
+ if (std.mem.eql(u8, word, "(contains")) {
+ allergen = true;
+ continue;
+ }
+
+ if (allergen) {
+ const allergen_name = if (word[word.len - 1] == ')' or word[word.len - 1] == ',') word[0 .. word.len - 1] else word;
+ const allergen_hash = hasher.hash(allergen_name);
+ try unhash.put(allergen_hash, allergen_name);
+ var algentry = allergens.getEntry(allergen_hash);
+ if (algentry) |algent| {
+ var i: u32 = 0;
+ while (i < algent.value.items.len) {
+ if (std.mem.indexOfScalar(u32, ingredients.items, algent.value.items[i]) == null) {
+ _ = algent.value.swapRemove(i);
+ } else {
+ i += 1;
+ }
+ }
+
+ if (algent.value.items.len == 1) {
+ try updateAllergens(allocator, allergens, algent.key);
+ }
+ } else {
+ var copy = std.ArrayList(u32).init(allocator);
+ errdefer copy.deinit();
+ for (ingredients.items) |ing| {
+ if (getAllergen(allergens, ing) == null) {
+ try copy.append(ing);
+ }
+ }
+ try allergens.put(allergen_hash, copy);
+ }
+ } else {
+ const ingredient_hash = hasher.hash(word);
+ try unhash.put(ingredient_hash, word);
+ try ingredients.append(ingredient_hash);
+ const entry = ingredient_counts.getEntry(ingredient_hash);
+ if (entry == null) {
+ try ingredient_counts.put(ingredient_hash, 1);
+ } else {
+ entry.?.value += 1;
+ }
+ }
+ }
+ }
+}
+
+fn ascendingAllergen(ctx: void, p1: Pair, p2: Pair) bool {
+ var i: u32 = 0;
+ while (i < std.math.min(p1.allergen.len, p2.allergen.len) and p1.allergen[i] == p2.allergen[i]) : (i += 1) {}
+ return p1.allergen[i] < p2.allergen[i];
+}
+
+fn part1(allocator: *std.mem.Allocator, input: []u8, args: [][]u8) !void {
+ var allergens = std.AutoHashMap(u32, std.ArrayList(u32)).init(allocator);
+ defer freeListmap(&allergens);
+
+ var ingredient_counts = std.AutoHashMap(u32, u32).init(allocator);
+ defer ingredient_counts.deinit();
+
+ var unhash = std.AutoHashMap(u32, []const u8).init(allocator);
+ defer unhash.deinit();
+
+ try parseAllergens(allocator, &allergens, &unhash, &ingredient_counts, input);
+
+ var answer: u32 = 0;
+
+ var algit = allergens.iterator();
+ while (algit.next()) |alg| {
+ std.debug.print("{} - ", .{alg.key});
+ for (alg.value.items) |v| {
+ std.debug.print("{} ", .{v});
+ }
+ std.debug.print("\n", .{});
+ }
+
+ var mapit = ingredient_counts.iterator();
+ while (mapit.next()) |kv| {
+ if (getAllergen(&allergens, kv.key) == null) answer += kv.value;
+ }
+
+ std.debug.print("{}\n", .{answer});
+}
+
+fn part2(allocator: *std.mem.Allocator, input: []u8, args: [][]u8) !void {
+ var allergens = std.AutoHashMap(u32, std.ArrayList(u32)).init(allocator);
+ defer freeListmap(&allergens);
+
+ var ingredient_counts = std.AutoHashMap(u32, u32).init(allocator);
+ defer ingredient_counts.deinit();
+
+ var unhash = std.AutoHashMap(u32, []const u8).init(allocator);
+ defer unhash.deinit();
+
+ try parseAllergens(allocator, &allergens, &unhash, &ingredient_counts, input);
+
+ var pairs = std.ArrayList(Pair).init(allocator);
+ defer pairs.deinit();
+
+ var mapit = ingredient_counts.iterator();
+ while (mapit.next()) |kv| {
+ const alg = getAllergen(&allergens, kv.key);
+ if (alg != null) {
+ try pairs.append(Pair{ .ingredient = unhash.get(kv.key).?, .allergen = unhash.get(alg.?).? });
+ }
+ }
+
+ std.sort.sort(Pair, pairs.items, {}, ascendingAllergen);
+
+ for (pairs.items) |p, i| {
+ if (i > 0) std.debug.print(",", .{});
+ std.debug.print("{}", .{p.ingredient});
+ }
+ std.debug.print("\n", .{});
+}
+
+pub const main = aoc.gen_main(part1, part2);
diff --git a/src/day21/part1 b/src/day21/part1
@@ -0,0 +1,43 @@
+--- Day 21: Allergen Assessment ---
+
+You reach the train's last stop and the closest you can get to your vacation island without getting
+wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need
+a few days' worth of food for your journey.
+
+You don't speak the local language, so you can't read any ingredients lists. However, sometimes,
+allergens are listed in a language you [1m[37mdo[0m understand. You should be able to use this
+information to determine which ingredient contains which allergen and work out which foods are safe
+to take with you on your trip.
+
+You start by compiling a list of foods (your puzzle input), one food per line. Each line includes
+that food's [1m[37mingredients list[0m followed by some or all of the allergens the food
+contains.
+
+Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen.
+[1m[37mAllergens aren't always marked[0m; when they're listed (as in (contains nuts, shellfish)
+after an ingredients list), the ingredient that contains each listed allergen will be
+[1m[37msomewhere in the corresponding ingredients list[0m. However, even if an allergen isn't
+listed, the ingredient that contains that allergen could still be present: maybe they forgot to
+label it, or maybe it was labeled in a language you don't know.
+
+For example, consider the following list of foods:
+
+mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
+trh fvjkl sbzzf mxmxvkd (contains dairy)
+sqjhc fvjkl (contains soy)
+sqjhc mxmxvkd sbzzf (contains fish)
+
+The first food in the list has four ingredients (written in a language you don't understand):
+mxmxvkd, kfcds, sqjhc, and nhms. While the food might contain other allergens, a few allergens the
+food definitely contains are listed afterward: dairy and fish.
+
+The first step is to determine which ingredients [1m[37mcan't possibly[0m contain any of the
+allergens in any food in your list. In the above example, none of the ingredients kfcds, nhms,
+sbzzf, or trh can contain an allergen. Counting the number of times any of these ingredients appear
+in any ingredients list produces [1m[37m5[0m: they all appear once each except sbzzf, which
+appears twice.
+
+Determine which ingredients cannot possibly contain any of the allergens in your list. [1m[37mHow
+many times do any of those ingredients appear?[0m
+
+
diff --git a/src/day21/part2 b/src/day21/part2
@@ -0,0 +1,22 @@
+--- Part Two ---
+
+Now that you've isolated the inert ingredients, you should have enough information to figure out
+which ingredient contains which allergen.
+
+In the above example:
+
+
+ - mxmxvkd contains dairy.
+ - sqjhc contains fish.
+ - fvjkl contains soy.
+
+
+Arrange the ingredients [1m[37malphabetically by their allergen[0m and separate them by commas to
+produce your [1m[37mcanonical dangerous ingredient list[0m. (There should [1m[37mnot be any
+spaces[0m in your canonical dangerous ingredient list.) In the above example, this would be
+[1m[37mmxmxvkd,sqjhc,fvjkl[0m.
+
+Time to stock your raft with supplies. [1m[37mWhat is your canonical dangerous ingredient
+list?[0m
+
+