diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-10-29 23:02:39 +0200 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-10-29 23:02:39 +0200 |
commit | e7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch) | |
tree | 237261eef3afd0720be77dbcbb9599fa66a24b67 /2020 |
Initial commit
Diffstat (limited to '2020')
68 files changed, 12388 insertions, 0 deletions
diff --git a/2020/01/.gitignore b/2020/01/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/01/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/01/Makefile b/2020/01/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/01/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/01/input b/2020/01/input new file mode 100644 index 0000000..127b7a7 --- /dev/null +++ b/2020/01/input @@ -0,0 +1,200 @@ +1293 +1207 +1623 +1675 +1842 +1410 +85 +1108 +557 +1217 +1506 +1956 +1579 +1614 +1360 +1544 +1946 +1666 +1972 +1814 +1699 +1778 +1529 +2002 +1768 +1173 +1407 +1201 +1264 +1739 +1774 +1951 +1980 +1428 +1381 +1714 +884 +1939 +1295 +1694 +1168 +1971 +1352 +1462 +1828 +1402 +1433 +1542 +1144 +1331 +1427 +1261 +1663 +1820 +1570 +1874 +1486 +1613 +1769 +1721 +1753 +1142 +1677 +2010 +1640 +1465 +1171 +534 +1790 +2005 +1604 +1891 +1247 +1281 +1867 +1403 +2004 +1668 +1416 +2001 +1359 +686 +1965 +1728 +1551 +1565 +1128 +1832 +1757 +1350 +1808 +1711 +1799 +1590 +1989 +1547 +1140 +1905 +1368 +1179 +1902 +1473 +1908 +1859 +1257 +1394 +1244 +1800 +1695 +1731 +1474 +1781 +1885 +1154 +1990 +1929 +1193 +1302 +1831 +1226 +1418 +1400 +1435 +1645 +1655 +1843 +1227 +1481 +1754 +1290 +1685 +1498 +71 +1286 +1137 +1288 +1758 +1987 +1471 +1839 +1545 +1682 +1615 +1475 +1849 +1985 +1568 +1795 +1184 +1863 +1362 +1271 +1802 +1944 +1821 +1880 +1788 +1733 +1150 +1314 +1727 +1434 +1833 +1312 +1457 +160 +1629 +1967 +1505 +1239 +1266 +1838 +1687 +1630 +1591 +1893 +1450 +1234 +1755 +1523 +1533 +1499 +1865 +1725 +1444 +1517 +1167 +1738 +1519 +1263 +1901 +1627 +1644 +1771 +1812 +1270 +1497 +1707 +1708 +1396 diff --git a/2020/01/puzzles.c b/2020/01/puzzles.c new file mode 100644 index 0000000..29384e0 --- /dev/null +++ b/2020/01/puzzles.c @@ -0,0 +1,39 @@ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +#define BUFFER 200 + +int +main(void) +{ + int nums[BUFFER]; + FILE *fp; + + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + for (int i = 0; i < BUFFER; i++) + fscanf(fp, "%d", &nums[i]); + + fclose(fp); + + /* Inefficient, but small sample size so it's fine */ + for (int i = 0; i < BUFFER - 1; i++) { + for (int j = i + 1; j < BUFFER; j++) { +#ifdef PART2 + for (int k = j + 1; k < BUFFER; k++) { + if (nums[i] + nums[j] + nums[k] == 2020) { + printf("%d\n", nums[i] * nums[j] * nums[k]); + return EXIT_SUCCESS; + } + } +#else + if (nums[i] + nums[j] == 2020) { + printf("%d\n", nums[i] * nums[j]); + return EXIT_SUCCESS; + } +#endif + } + } +} diff --git a/2020/02/input b/2020/02/input new file mode 100644 index 0000000..45e8c19 --- /dev/null +++ b/2020/02/input @@ -0,0 +1,1000 @@ +5-6 s: zssmssbsms +3-6 j: jjjjjrrj +4-7 k: kfkgkkkkk +2-3 n: nkbgfnn +7-12 h: hhhhhhdhhhhhfhhhh +1-4 v: nvvv +6-9 h: hhthplhgmpzsmhhxhh +6-7 r: rrtrrrgrgcc +10-15 h: sdbhvbhfjhwllmrpdv +3-4 s: bsss +5-7 s: sstjsswsspldr +10-14 b: bzbqbbbkpvbblbnrbs +4-11 s: sssmcskwsssssss +2-10 v: rlttvvnvvvvvvksm +4-5 x: xkrxx +2-5 m: bfmmmmm +11-14 r: rlprrtrcrxcrgrrhrr +4-16 l: dzllmllldnllblwcr +3-4 t: nplr +3-5 x: jcxxgkxtjwwgh +3-4 j: msjcjqjgxmjsjfjjj +1-6 z: zgkkdzww +3-5 q: pgqqbq +17-19 t: tttkttwtttttttttttt +5-11 n: nqnlfknntdn +11-12 c: ccccccccccgc +2-14 x: pxmvfrrwlbzxhk +4-5 g: gcggwggxv +4-5 h: phbzhhhqhl +4-5 h: hwbhk +1-2 t: tgmq +16-19 l: llllbjlfvnlhwlllqfp +4-6 r: srrrqggrs +1-3 g: nggwhvcl +1-8 f: pffffffff +2-3 l: lllll +13-15 d: ddrdkdddmdmdddd +11-13 r: rrrgrkrrdrwrrr +3-10 x: xxxxxxxtxq +6-7 p: pspzpvlpxnplhtpc +3-8 f: fsfkfbffvxfc +3-5 z: zzzvwzsfktz +4-7 c: cccgccc +11-12 n: nnnnnnnnnnzn +12-13 n: nnnnnnnmznnpnnn +4-7 q: wqqzgqgfg +5-13 p: tgplpbpmvgpppktps +12-13 x: zwcxlnhwpsvxm +7-10 r: rrrrrrnrrrrgr +1-5 r: rlrrj +15-18 l: nlllllslcllllllllcl +10-11 w: wnwwzwwwwwwwmwrwr +10-11 j: njmmjjjcjjv +3-6 z: vgbdvzgzzzzw +7-8 r: bbcvxzrqpqskcmhwsvx +4-5 c: rgvcgmccc +6-9 d: ddddddddd +6-7 g: gggsggg +4-7 c: ffclfbcdmcvnshw +3-5 n: xnznv +6-7 d: ddddddk +1-2 r: rjvprt +6-7 p: ppphppp +1-11 p: ppppppppppxppp +10-16 x: bxxnxpxxxcxjxtxnw +4-8 s: hzsvsswc +10-12 p: lpwswppppvppphp +2-3 d: bdcddnxc +4-6 s: ssscssp +18-19 k: kkkkkkkjkkkkkkkkkzk +4-6 x: ncxpxx +6-8 h: xhhhqxrhhhfh +15-16 p: qppjnpzfvppzdppgppp +1-7 d: dwvdddddc +3-4 w: wlshzvqw +4-16 s: sbwgjshsznhdsssjts +4-8 t: ptttbkbhtt +11-12 w: wwddwwwwwwwj +2-6 z: zkzzzzzhzzzz +3-6 b: bbxbbb +3-6 z: zztzzq +2-3 h: hhjhh +1-5 x: xptxl +10-11 n: nnwnnnnnndrnpp +5-6 s: jsswmjzkrspsms +2-7 n: nnnnnnnn +4-6 q: qqqhgxg +5-6 r: rrrrqrr +4-5 k: kstjksjbkhhfpzkl +5-6 n: nnnnqpldn +11-13 w: mptdwqgfkwwzb +3-4 x: ccxxmxfzfztxvxdg +2-13 w: wwwwwgjwwwwwwwwwwww +1-5 m: mrmkjqhdcqbz +7-8 l: lldllllh +7-17 d: ddvddddktmckjbmds +3-8 n: htnnnnqlv +3-8 v: chvkvjkvxl +8-12 t: rtffbltcbtttwtqbvt +1-8 n: nhnbvdwq +6-11 b: bblbbmbbbbbbbbbbb +4-7 s: rssbphs +8-9 q: wqqdqqqwqq +10-11 f: sfwfffdffhntffj +4-5 x: xlxbxx +2-4 d: lvdd +3-6 t: djtcsmjrrt +7-11 v: lvvvvvxvvvv +3-4 c: ccpc +3-17 g: nzgjkrpwbfcgzqjvtth +8-15 l: lnhlllgllvgllbgscl +10-11 z: zzzzmzzzzmzzjz +3-10 b: bwntlkjnfbm +5-6 f: vffxnfjffp +1-4 s: dvcssdw +11-13 c: cccctcfccckct +4-6 m: cmtzbmkqqgbmpsmbxwkw +11-13 j: jhjjcjmjjjqjvj +6-7 q: qqqqqqqq +4-10 f: fmxffftfnbm +7-10 n: cdnrfrnvpmmhpnmxbnx +8-9 z: zzzzzzzvz +2-9 h: zrvhddntmhjhhh +11-12 g: gggggggggggg +1-2 h: vhtgfg +1-2 g: gggp +1-2 r: nrktwt +2-8 b: bslkbbbbb +1-5 q: lrfqmq +10-14 q: qbqbqpqqqrqdqqq +7-16 r: nvrrzhsgrwthgbrqkqh +4-5 z: zzzzh +3-8 v: nkvwfvlvv +8-9 z: zzzzzzzfs +2-4 w: vrlrss +1-2 j: jnqswjgps +7-8 f: ffzffffwff +11-12 k: klwqntvkpcthq +5-13 k: kkkkkkkkkkkklk +2-5 w: wwwdxgwwszb +1-13 q: cqqqqtqqdmmnqm +3-8 q: bqtlqqzn +3-12 n: xnzdxdnndpnnqhcnnnnn +6-7 r: kqhrrrxldrmwr +3-5 k: hjkdp +5-6 h: hhhqhrmhbh +14-15 v: vvvvvvvwvvvvkvvvv +2-10 h: nbcpsmpvph +8-9 r: rjrrrrrrp +8-10 j: jjjjjjjcjt +8-13 l: jkfllllllxldvplvll +5-11 m: mmmmmmmmmmmm +5-6 v: vhvvgvv +12-13 n: nndnnnnnnnnnb +3-4 f: wfmfjfffnfflf +4-14 l: llllllvllllllf +10-13 f: vvtfcfxfwdfmnf +4-8 w: wxwwwghwpwrtwww +5-8 g: tsggmgcggg +9-11 w: wcwwwwwwwlqw +8-10 z: zzzzzzzpzz +2-4 m: mmrm +16-17 k: kdkkkkkkkkwkkkpklkkk +4-8 k: kkkkkkkn +2-5 p: wpppqtwkpbptmlds +6-8 f: ffbffnff +2-16 z: ffzjwnbbljfzgfrlz +3-18 j: jjqdrpcjjjjjjbfbjjj +10-11 v: vjvvvvvvvvm +3-8 f: fmnpffflfnd +13-14 n: nmnnnnnnnnnnnr +3-11 k: jrkrkjzccwhlxkgkh +1-4 z: pzzzhzz +6-7 k: kvknwkj +2-10 l: cllblhlwlq +3-4 n: nnnng +3-6 w: tjlzwwc +12-17 l: llllvlllllllllllw +2-4 h: dhhlmhqddhnh +1-2 r: rsqjd +10-13 s: zszlssssssjsswpssssz +2-6 v: vmvvdxvv +9-13 m: qpmdmzmmxjswmmmmm +19-20 f: pzjnfzfwfcffffxmfffl +1-5 n: nnnsknnnn +13-14 r: rrkrrrrrrrrrrr +9-10 h: hhhhhhphfh +6-8 x: ppcxlxhl +1-3 z: bzxwzjhcgwcjgfgrlc +8-9 n: nnnnnnnwwn +5-6 g: qcgghgg +3-4 p: ppxp +7-9 b: phbbtbsbffbjbbb +5-13 t: tcstttjtzdnhkt +10-12 k: mkckkkkkkbkkk +4-5 v: twcpvvzvjsvzqvwkbc +17-18 m: bflhwmndwmkcmqsmmgkm +14-16 t: ptttrtttpttttttfhtlt +7-10 b: bxbrbbbnmcbbvbb +6-9 r: rwvrrpmmr +10-11 h: hxhhhhhhhhx +4-5 h: hmhth +1-3 l: lldl +1-2 d: dqhsxsqmmndx +10-13 l: llllhlqllslld +18-19 z: zzzzzzzzzpzzzzzzzcpz +5-6 j: jjjjjp +7-9 t: tttttttttt +6-8 t: tttttttzc +5-17 x: xxxxxxxxxxxxxxxxxxxx +16-20 x: xdxxxxxwxxxxxcxpxsxw +3-4 f: ffxf +4-9 q: mqqcqqqqqqd +2-6 z: zdjnzjtr +4-7 p: phppppv +11-12 m: mgmshkmmbmqmmmmm +2-5 b: ztltbbpgxmbbptqb +4-10 v: vjvwlvfqmrhffvbkfv +1-3 k: xdcthk +3-9 s: ssssssssm +9-18 w: whjwnwwwkwbwwwwwwwww +16-17 j: jjjkcjjjjpjjjjjjdjjt +9-12 b: bdvjzbwbbgbbqb +2-6 f: ffrrsj +3-8 t: tttttttwt +5-7 c: cczcmcxc +5-6 z: tfwszq +8-9 k: kkkrskkdkkr +5-7 h: hhwhhhghh +8-14 m: smfgmmmkmmmmmmmpxmnn +8-9 w: gwwmplbkjf +1-8 z: kjzwvtvdhpkzjzlxpjq +3-5 b: mgbqbbb +3-4 g: skltgpcng +7-8 k: cxxkktkc +12-20 b: fbbmcbbhkbbbbhbbbbbz +6-19 k: gvflkkgqbkckcmlcqkl +10-11 l: llllllllkdll +3-4 g: ggqg +5-6 d: ddddzd +4-5 n: nvnnn +4-5 j: jsjsjj +1-4 m: mmmmmmmmmmmmmmmmm +11-15 c: fljcwwlnbfzxfqt +3-4 l: lwlndjl +7-10 w: wqwwvwwwwjw +15-16 k: fkkkvkkklbkkxkdkkr +3-4 z: zszz +5-7 z: xzzhlzzzplzzq +8-9 z: zzzzkzzzk +2-13 h: hhhhhhhhhhhhqbhh +6-9 n: dnnzwdnncqnjnnvm +6-10 r: rkwlrdsrrrzrrrr +1-4 b: bbbwbb +1-2 b: vbxm +5-11 m: jrkbkmmmmmmmw +2-3 n: wnmntnxdkl +11-12 f: ffwfnffffvxfffff +1-2 m: xhgmxvmkzj +10-14 s: sssrnsssssssssrsv +3-9 x: xxxxpxxxgx +2-7 d: pddwwpbv +2-5 l: lljslz +3-4 g: ggkg +9-13 r: crrrlwzbrvjzt +4-5 k: kkzpkfk +2-4 q: kqqxq +6-8 c: tcmcccccccfccgcchc +7-17 r: nrsdshrrqhjllsrjrjxr +1-3 b: bpgkwcbnb +3-8 t: zdnjtvttjgt +6-7 v: gpgnwkgnvkv +5-7 v: vmvcnjvvvmv +4-7 z: zvrjzxzzdxzlpz +3-9 m: cdlplfjrmvbdvm +7-8 w: wwjwwwwww +13-15 q: qqqqqqqqhqjqrqjjqrq +8-9 v: vvvvvvvvg +3-6 f: qfffffjf +2-4 d: nddpxd +1-3 q: bqmqqqqq +14-16 j: jjxjbjjjjjfjjjjfgj +5-6 t: ttttgtt +14-18 l: llllllllllllllllwbll +11-15 c: kscccdcdccdccccc +15-17 v: vvvvvjvvvlvvvvhqvvv +5-6 b: bbbbnl +3-10 r: rrrrrrtrqkjr +11-13 w: wwwwhwwwwwskw +13-14 h: hhhhhhhhxhhhhs +8-9 k: kkkkkkzkw +11-12 m: mmmmvmmmdmmcm +2-9 k: kffkknkfkkkkkgkk +4-13 d: dggdndznddddc +4-7 t: kksmtmdswzvt +2-4 z: ppzccxtbcnwswtlc +11-14 r: rrrrrprrrrrrrvr +14-15 x: xxxxxblxxxxxxtxxxc +7-9 b: bkxjjjbtbtlhgrtmb +4-5 p: fgzdp +5-8 l: ncrlljltnllll +1-2 x: mxgcx +7-12 x: xxxxxxxxnxxr +1-2 r: rkrrrrlnrrrr +6-10 q: qqbqbqqqqqqzrqz +2-9 b: bsbbbcvbcxcrbbbbgpcd +12-19 x: xtlrxvxsxxjxxxknxxcx +2-3 p: mzpptxpg +3-5 d: gkdzgdjlzbfvcbhtgl +5-9 t: ttttnzttt +15-16 q: qsqqqqqqqqkqqnwqqq +12-14 q: qqqqqqqqqqlfqpz +3-8 b: lslqgrzbgbjzthlgnrmc +9-12 m: wmxmmsmmvmcm +3-4 t: qxttt +3-11 m: kbzljjmbpxmt +14-15 n: nnnnnnnnnnfnnnvnsnnn +11-17 l: lclglllclzflllbllt +6-7 m: msmmmmskq +6-10 c: ccccccxccc +9-13 l: plpgntbglpbgfj +5-8 l: llxltljlws +3-7 z: zqzlztgzkzszb +11-15 k: kkkkkkkkkkkkfkqkk +15-16 l: mgxlzbvfwbdmptlbjwz +9-13 j: jjjjjjgjjjjjjj +7-8 z: zzkzzzzbz +14-15 j: jjjjjjjjjjjjjlv +3-7 q: qqdtqgqq +2-4 c: cccpzn +4-7 k: hkkxkkk +2-5 k: kxkkkk +14-15 w: jwwwwwvwwwwwwwpw +2-6 g: gmrgdgnwdbhggxgh +5-14 q: djqtxqxkmgqxqqcplwqq +14-15 q: qqqqqqqqqqqqqqq +3-7 x: dqxqxxtrx +8-13 j: jjjjjjjbjjjjjjjjjj +18-19 r: rrrrrrrrrrrrrrrrrcr +3-14 x: xxsxxxxxxxxxxxxx +7-14 s: kknsngsgkfswjlsns +3-4 z: zzjz +2-4 z: zzzd +1-3 d: dqzdgzwdjmdcpfpfd +3-4 p: jppj +14-15 c: lcccctcccccczzdcccc +14-15 f: fffffffmrfffffpffx +1-5 c: qcvvrcqm +2-11 t: trcltttgttttt +8-9 j: jjjljfjkjjj +1-12 t: wttttttttttttt +7-14 q: gsqqqqgmqqqqclqxdq +5-7 h: hhhhslrlhwsmphc +14-15 x: cxrxxxxxxxxxvxrz +3-6 k: rkkkkkk +3-4 t: dtmttt +1-8 z: zzzzzzzgzz +3-17 t: rtlwttmttttxtttttttt +4-7 w: wwwswww +3-4 w: qvsww +8-11 g: ggggdgqdgggnh +14-16 q: qqqqqqqqqqqqqqqqq +11-12 d: ddddddtddrbddd +10-12 v: wvhvxqpvvbvqvtvmv +6-11 c: cpckcmcctccc +5-9 r: djrcrrrrrrmr +5-9 t: ttbcmnbzt +6-11 f: lwxssffcfks +12-17 v: vvvvqjvvvqvzvvnvvck +11-13 k: kwvtzwczgdwqwp +3-6 l: zdglhlklllhk +15-17 x: xxxxxxxxxxxxxxpxsnx +2-7 s: swdsssx +4-8 v: xvxvxgmvvvqwvhtqt +17-19 n: nnnnnnnnnnhnnnnnnntn +2-4 p: jtppkrgpfph +15-16 v: vvvvvvvvvvvvvvrfv +6-9 q: wqxqqdvdqq +14-16 w: wpwwwwwtwwwwwcwwwdbw +5-6 k: kjrrnk +6-13 w: qfcjlwtlbwgvp +2-3 b: sbbbx +1-3 b: bpbf +2-7 r: dsrrnbmdf +3-13 w: wwwwswjmwwwwdww +3-5 l: dzhll +7-9 l: llqllfzxw +2-5 n: cdkhngnnf +4-12 q: dqqkqklqqqqh +14-15 b: twbbbbgbfkbbbbgcbt +10-16 q: qqnqzbqqzgqrqqqqqqqx +1-3 x: sjltfnnx +9-16 g: tcghdqfsqbcllvdsckx +6-9 w: pwhwjwwxdwjw +3-5 l: rlxlflz +7-18 p: pppppppppppppppppppp +4-14 t: wvfglxkbtrqxkjjtqccl +15-16 b: bbhnbbqqfbbbsbcz +3-4 n: znpnfntn +6-9 v: vvvvvvvhfz +17-18 p: pppppppppppppppprp +2-18 n: lnnnnjpnnnnnnnnnnt +12-14 b: bvtbbbbbbbbbbs +2-6 r: rrrwrrrr +3-4 f: fpfk +1-4 s: skcrmsczxwxrn +4-7 n: nnnpnkz +5-17 j: jkjjgjjjjjjjjjjjj +7-8 n: nnnnnnpnjsn +1-5 j: rdjhp +3-5 f: hdfff +1-3 j: qqjj +2-3 j: vhjrz +7-15 r: jrrrrrrrbrrrrrr +3-6 r: pwdpzr +6-10 n: lncrcndstsww +10-11 m: jmqqmmvshmj +3-5 s: sjjnsvshs +11-12 v: vvlvwvvhvgvkcvv +6-8 c: wcpcclcc +10-12 x: dxxxxxxxxgxxx +5-7 s: sssssst +2-6 j: jksjjkjj +3-4 w: wqrw +2-4 c: qgzdchzcsc +4-6 c: cwngwcxwdcpspfccgdcl +9-10 g: ggvggggxgrgg +5-17 h: hhrwhhfwtrfhzhhblxxv +4-13 g: ppcgtcqgdzswgjtp +3-10 r: rmhwrbtrrwktcqrr +2-7 l: vqhgljg +2-9 l: llgmcllqglllczl +14-16 c: zmccccccccbccnccccfc +10-11 z: zzzzzzzzfzz +5-10 b: bbbbbbhrxbbbb +7-9 b: bbnbbbgbb +9-11 t: tlttttttqtstm +11-13 p: pfmwgpzppppgppppp +14-15 d: ddqdddddddddddpd +5-11 x: xcxvxxqvgnlxzxfdp +12-16 x: xxtxxgrxlxzzwgxm +15-16 z: ztzzzzzzzzzzzzlz +2-6 j: jdjjjjjjjj +4-6 p: zqjkgfctlwqplppj +1-2 d: ddzdd +14-16 v: vvvvvvkvvvvvbjvvcvv +3-4 x: xxxxxk +16-19 t: ttttttrtttmttttqttc +8-14 b: pbcbsbhbbbbbbgbn +2-9 v: vkvvvvvvvvvv +3-6 x: xxxxxnxl +13-14 r: rrrrrrsrrrrrrjr +10-12 x: xxxmxtxwxvxxpxx +4-5 h: hntfhzwhhhv +11-16 z: zzzzzzzzzzqzzzzzz +3-8 h: qfhhhhhmd +1-4 r: rbrw +3-5 q: mqqqqqscq +2-9 n: nnnnnnnnnn +12-15 v: vvbvgvvvvvvvvvcqvv +8-10 j: jjjgjrjjjkjj +9-14 m: mmmmmmmmmmmzml +5-7 v: zvvvvvwx +13-14 t: tttttttttttttkt +3-6 l: lvwxlll +6-7 w: xhbgnlg +11-12 z: zzzzzzzzzzwzz +1-11 m: mmxrltjrmmmwm +9-10 b: bbbbbtbbbrbbb +6-8 n: xnnpkncnhlv +14-17 w: wwwjwtwwntsgwwrwm +12-18 z: zzzzzzzzzzbqzzdzzz +1-8 j: kjsjnjjm +14-18 h: hhhqhhhhhhhhhbhhhr +7-15 n: cpxrrxnvbmwktqg +6-8 w: twtwwdwnwww +1-2 s: sfwss +1-6 z: zzcrqfjkcrkcxnwzz +6-18 n: nnnnnnnnknnnnnnnnw +4-10 z: zzzzgzzzzzz +6-9 s: xvrcshqcsmslsshtscj +2-16 w: gwbljbgmwzgpfjtqnjkj +10-12 j: gwjjjjjkjjtjjjjjj +2-5 p: prpps +5-6 f: fffffr +4-5 r: rjnvr +6-9 c: csccccqpgccc +12-14 g: ggggggdggggdgg +9-12 p: pppkpfppppplp +5-11 f: mhfpffffdfzdrnskfwff +6-8 h: hhhhnxhhh +18-19 m: mmmmvsmmmmmmmmvmmzm +7-9 g: ggptdsgzg +1-7 f: kffzqmfp +10-12 p: pppppptppppk +10-11 f: vfftfffffffff +10-11 f: rxxlzzpvcfbtzfww +3-7 b: bbhrhrb +4-7 j: tjjgjwfnrh +10-12 g: gkggpgggggzfrggvgdhg +7-8 z: gpqfckkzknzrvgngpfh +6-9 c: cccgcnfckgt +2-11 x: zlfxsxslzcxp +16-19 j: jfjjkltpxlqjbvjjjbt +13-17 k: kkkkkkkkkkkkkkcknw +5-9 f: ffxhfxflf +7-9 g: gprnxtxlgndg +1-2 l: tjllwll +7-9 w: wwbwccwwvcwwwz +6-7 n: ntmklznfl +4-7 r: rrrlrrpr +7-12 v: vhmvvvgvvvvs +5-7 t: vfwgctwq +16-17 m: mmmmmmmmmmmmmmmjm +11-13 j: jjjjjjjjjjfjg +4-7 d: dfdddcdwzdrd +7-14 j: jgjjljmmjjzkgjjjqx +10-11 b: bdhbblbbbxhbbd +8-17 k: kkkkxvnrmkkskkkkk +13-15 v: vvvvvvvvvvvvvvv +3-7 t: ltptttf +1-2 q: qqqkj +11-13 t: tmttttntttttft +4-6 t: xgtxrt +9-12 q: fqqpvqqqhcqzqqq +5-8 s: qdjtcsfssss +2-17 c: ccdccccccczqcccccc +3-11 q: qqpqqqqqqqqq +4-12 l: qkqxllknxltdlzlsllj +2-8 r: qlrddbplz +16-17 l: xllllllllllllllgb +8-12 j: kjdfjjjjjjrpjfhjjrj +8-9 d: qvddsrddvpvbddbdddm +4-5 p: pptss +4-6 c: cccscc +4-5 c: cccrc +1-6 r: rzrzfd +1-4 t: tttzz +6-8 d: ddgdsjdd +6-8 c: cccdccccccq +6-9 k: kkkkkvkkk +1-4 m: pmrm +15-17 d: ddddddddddcdddzdd +6-10 b: cljmbjbtbbz +6-11 l: lllllwllllvlll +13-14 r: rrrrrrrrrrprrmrrrrg +3-5 w: hnwbd +3-8 f: fffxfffz +5-9 z: zhzzztzqnzzpl +3-4 x: jxvgxhrd +8-9 x: xxgxxxxxjxx +3-6 z: zlvzfzbzzzb +2-3 v: jvrvq +10-11 q: kqjqtpzqwbqzqh +9-10 g: ghgxgcggdg +5-8 r: srmrrqps +3-4 k: kgkkk +3-4 f: dfsflf +3-4 m: mmmxm +10-11 x: xxxxjxxmxwxx +16-17 n: nnnnnnqnnntnnnnnnnnn +2-13 l: lfblltnlrllll +1-4 l: blblllnnlllj +4-17 k: nkltzflkkjmmknxwkf +4-6 s: sstssfssssssssss +1-2 f: fkvbs +3-5 v: vvvhcvv +1-3 t: nttttttt +1-3 p: ppnnppph +10-15 q: qqqqqqqqqqwqnrqq +2-18 v: vvvvvvvvvvvvvvvvvv +2-3 r: zgrrbrmhqtxc +19-20 x: xxxxxxxxxxxxxxxxxxxv +10-16 n: nzvfnnnnnnnnnnffn +3-4 d: dvdcdw +3-16 l: vrqhbhvmlrllllfl +14-16 c: cccbcpcccccccwccc +7-9 l: lmlnllllll +7-9 r: rfrrrqlrrrsbr +9-19 s: snmbxvrcsssnhpswrss +5-6 s: ssssks +4-9 l: llllbllllllllz +5-9 w: wwwwdbwwwww +2-4 w: mvvw +17-18 v: vvvvvvvvvvvvvvvvrvv +8-9 h: hhhhhhhhh +3-4 n: ntcn +3-4 b: nbbr +8-11 b: bbkbbbbfvbbb +5-8 d: nddnjcdd +12-13 v: vvvvvvvvvvzvh +2-5 k: kfxlc +3-4 r: rrrm +10-16 k: kkkkkkkkkpxkkkkkkkkk +5-6 z: zzzzdm +12-18 p: rrpplpwppgppvpppppp +9-15 x: vxpfxftcxlmzccz +7-8 g: kpgmghgrkgggqbnhggg +4-13 k: kkkkkhbktkwbkcvk +2-7 g: bgggcgtxg +18-19 q: qqqqqqqqqqqqqkqqqhqq +12-16 r: rmdvrrrqrbgdxprrr +4-5 v: lrvxvjlxvfkcbsvv +1-10 l: lllwllllnllvlllll +1-5 t: ttttmt +1-3 v: vfrdvj +9-12 j: jhjwjbjjjjjpjw +3-10 m: mnrdhxmmmm +3-11 n: ngnzbxwgcddgtwvxtrt +2-4 q: dqqq +5-9 z: zgdzzzsfzzxslvzwzp +1-10 x: xjxxxxxxxlxx +3-4 x: gnlvxwt +5-10 q: dqqqqdqqfqqqqqqq +8-9 p: nmpcpppzpnpcpppn +5-6 f: fffffr +6-8 h: ghhphhnhmhhhhhz +6-9 h: hhkshhhkhh +3-4 v: cffvrv +7-8 h: qvzvlzxhhqlsrjrgjwf +5-6 t: ntjztwjttv +3-4 b: bbbs +4-5 k: kjkmk +5-7 k: bvbhkkv +6-16 j: jjqjjvjjjjjjjjjl +7-8 t: rtlmzxtr +9-10 n: nznnnnnnhnn +3-4 b: tmnbdrbjbnfksm +3-4 q: lqqq +5-6 b: bbbgbbz +6-8 l: llvtlllzll +12-16 s: stvsnzssssssssml +1-4 k: jkkk +4-7 t: ttttztttttt +14-15 j: jjrjjzjjjjjjjghj +4-11 j: jxqjjxjjjjth +4-10 v: fvsktttspv +3-7 g: tdgwkspnggpfg +2-18 r: rrfbmqhrldrcqrprrrrl +6-7 r: rrrrrfrr +4-6 f: fjffxqzdffr +8-10 l: llllllllkb +8-12 s: wsgssfssssss +14-15 d: xddddfddddwdtvddddd +2-10 f: fffffkfwcr +12-16 l: llllllllllgtldll +6-7 r: rrrrrkrrr +9-12 q: lqqqqmqhnqqq +8-13 q: qdfqqqqqqqqhl +2-6 g: gjfjgggvng +1-3 z: qzzz +8-10 p: ppppppppzbp +7-12 f: dstffffzfkczfffff +1-15 k: kkkkkpdkkkkkmxf +3-6 w: whwwwmkqf +16-17 g: gpnglggggggggggdcg +5-15 s: nsssnssgssssssssss +14-15 q: qqqqqmqqqqqqqqx +2-11 s: psslpssssrsssdssrmp +1-6 d: hdndpdd +3-6 q: sqpqqnpsqjrqq +1-5 b: qbbbb +1-3 v: vvsv +4-5 q: qqqqjqtfqqqtqqn +6-9 h: hhhhhhhhhh +7-8 r: rrrrsndrrr +3-4 r: brrtb +3-8 t: fjtkttxtzt +10-11 b: bcbfbbbbbbkb +1-6 l: llzssp +16-17 f: ffffffffffffffffn +3-4 l: clml +13-14 h: hhhhhhhhhmhnhnhh +9-12 t: lthttttbtthcctv +3-8 x: xxfkbjhxlqxvxxthxb +2-3 l: llrlmlw +1-10 h: hhhhhhhhkhhhhhh +14-18 l: llllllllflllbllllc +14-15 b: bspvbkbpkkbmgjn +10-12 z: zzzwzzxzzzsxzpz +5-7 d: dhmtldrqddmdw +1-4 g: bqzfgqg +7-10 j: wxjbgbjdlz +3-14 q: csqgmhfqgfqlcnw +1-3 m: mmkmltxmn +1-5 l: llllcll +1-3 b: bcbbjzwfdmmnsrtqbsnl +2-4 s: sszs +14-17 k: kkkmkzkkkkskkkkkbk +5-6 g: gnggcg +4-15 t: dfmlshpqhhmwptzkwgt +2-3 w: drwtngwhgw +5-6 t: tttttrn +15-16 b: bbbbbbbbbbbrbbbr +7-11 s: tswssqssfstsssbzs +8-11 j: jjjbdjjjjsjj +4-7 c: mjclkfccpccfcjchqg +11-13 q: qqqqqqqqqqqqqqq +4-5 r: rgrdrb +8-9 n: nnnnnnnntn +12-13 g: gggxgggggggzgg +7-8 q: qqqqqqqq +9-10 m: gcqmlctsmfmstprmmmkm +2-6 h: dhhhhlh +19-20 b: qkzbbbhbwbtbvqbdpfrt +5-11 k: skkkkkqkhkkkz +10-12 l: lllllllplwllf +3-5 x: hxxxb +4-5 z: zdzzwtzz +5-9 f: fmqfffffmpq +2-3 w: xwkg +6-8 x: xxxxxxckxnq +10-13 k: khkkkkkkkkkkbx +7-15 j: xjjjjjjtjjtjjdljjjjj +2-4 p: mpckqmgpbzcb +2-3 r: rwrz +5-12 t: xhgntttllqtpjzttltt +4-12 q: bwwfvqwrmmbqt +1-3 g: cgpggg +7-11 j: vjjjwjjjrvrjbj +6-11 j: jjjjjjjjjjr +4-8 k: klkkwjkkkvkfk +8-16 p: pppppppvppppjpzs +4-5 m: mmmhr +13-14 t: tstttttttttttw +4-6 n: hmnbznk +14-15 z: zzdzzzzqzzzzwzg +1-6 p: hsjlxpppwv +1-18 d: tddddddddddvdmddddd +2-4 n: nznjn +6-10 v: fqvvszfvvtx +13-18 k: qbckrkkmkkktnkknkk +1-6 n: lnfxntnznnbq +3-9 n: lvnwnlnxnggnvdnqpz +1-3 k: skkjb +1-7 m: mwmrcjt +3-5 k: kfkmw +6-7 f: crfbrfcjdjvm +10-11 m: mmmmmmmmmmz +6-7 t: ttsgttzb +4-6 f: fjfbff +10-12 m: mmmmmmmmmmmmb +10-11 z: wzzzzzzzzszz +6-11 z: nbdmzzztpzh +10-13 f: ffdfdfffxlffgf +3-4 s: vcksscsk +1-5 f: ffvfcpffgfww +13-15 c: cccccccpcccchcc +1-16 x: xxxrxxxxxgxxxxxxx +6-9 v: kfxvvvgvlvvjvvs +14-17 f: cfxfdffbjmbjdfptg +6-7 s: sssssss +15-16 b: bbbbbbbwbbbbbbpb +2-4 w: wdww +1-7 m: mpmtmsmmmpm +4-7 z: tzzpzzz +1-2 q: qdqx +6-12 g: gcggwxrjkjgtrgt +14-18 m: mmfmmmvmmdmmjmmmmq +17-19 j: jjjzjjjjzmbsjjqjplj +2-5 m: ljxmmcnmmgmt +3-8 w: wwwwwwwt +5-7 b: bbbbbzsn +1-17 t: btttttttttttttttttt +1-2 s: svsss +5-6 p: pppmmr +2-7 m: vrgmmjmhm +15-16 w: wwwwwwwwwwwwwwgw +10-11 q: pqqqqqqqqlqqq +7-8 k: kjbkkjdkzc +5-9 x: xmxxtxxxxxx +13-14 v: vvvvvvvvvvvvqvv +1-4 z: lzzszz +4-5 x: xxxkxf +13-14 h: hhhhhshhhhhhpfhh +6-8 s: sssgsssvn +14-17 l: nsgfxplzbmljjstld +6-13 j: jjjjjjjjjjjjjjjjvjjj +10-11 q: qqqqqqlqqrq +7-8 l: llfplllwll +13-16 h: hhhhhhhhhhhhhhhp +5-8 s: ssfsssgc +3-4 b: bbbn +16-17 p: ppppppppppppppppn +5-7 w: wwwwcww +6-14 d: ddlhgjtldncddvdrsd +10-12 h: hhhhhhhhhhhrh +4-5 s: ssrss +1-7 z: wkzcvczpcskxfzxxxmzh +4-7 h: rphjtkh +3-5 k: mdtzkjfkq +2-3 c: cwcc +2-6 r: rrnrrmrrlrrr +10-14 n: ntjrrpfpxxwdznjvmh +3-10 h: flhtwzhhhh +3-8 v: vvnkvvvp +6-8 n: bnnnndnnnnnnnn +2-11 p: hpnppgfmpbp +3-8 h: khhmlhxjshsbf +3-4 l: jllnlglrqz +4-9 g: ggqbghggg +5-6 w: wwwwlwwb +1-9 s: hssssssssssss +1-5 j: jjjjbjj +8-10 s: dssrssssgstssss +3-6 c: cctccccp +7-9 v: vvnvvvvvpv +5-16 t: zmspstpctqgrbmlt +8-14 m: mpmmmmjqmmmnmmm +13-16 c: cbdxwzfbjpkvcpdp +3-19 w: wlwwkfxwfwzkvjxjnthw +13-14 l: ldllllllllllmll +8-14 s: spssshxjfnsjsssskkkj +2-7 c: cmccdcpcw +5-14 t: psntttqxbxdqstvkttb +8-9 z: zzzzzzzzbz +4-9 n: lnmnwcvntmhrznc +1-4 v: tvvv +2-8 d: ddqddqtdscsfddblqk +1-2 t: wttttv +5-6 n: nnrnxnnn +4-14 c: zccscgzpzvwlwcjqpfjl +3-11 g: gglggggfggg +11-18 d: ddddddddddfddddddd +1-7 q: qsqkgpf +2-11 q: qqfqqqqnqqhlqqq +8-9 c: ccccsccwcp +4-7 m: mmmqmmmm +7-17 c: cxscnqkjdfkcgqzccdkc +4-5 b: bbbzb +3-4 l: llll +1-2 j: ljcn +11-16 r: rrdrrrrrrrrrrrrz +1-15 l: rrlkklllllllgqllk +14-15 b: bpbbbbbbmbbbbbpwb +2-3 q: xcqqh +1-3 q: qwckphmm +1-6 d: dwdtsfxzvdqbbhlhwtk +3-6 n: nmmzcnnmn +6-7 q: qqqqqzq +1-2 z: jzpzz +2-6 r: rrrfmrvlr +3-4 n: nncn +2-3 l: plblwq +2-7 g: gggckcqgwsk +12-13 q: qqqqqqqqqzqxqqq +16-17 s: sssssssjsssssssqs +1-10 h: hjvvvknhmh +11-12 z: zzzzzpzzzczlzz +6-13 q: qqqjrbqcqqqqqxq +6-9 p: ppcpkfpppptp +15-16 p: pplpppppppppppjdh +7-9 c: hqswstxxcnl +2-4 x: ngbxbqszx +1-2 g: sgfxt +6-7 x: bxgnxxt +16-18 j: mjjtjjjjjjjjljjzjjj +13-14 c: ccpccvcccccccgc +3-7 s: fksrgsbcnfmkxdwd +1-4 q: qwpmqjlbhqfnpdjgqjqx +2-3 p: ptpp +4-8 k: sbkkskgc +4-11 j: gjjbjnjjjnnj +1-16 f: fffbwjwfmfqcjffmf +6-8 b: wbbbbwbbbb +1-3 z: rzzv +2-4 v: wvcjnjmdbjjjvptcsv +4-7 b: bmjdfpfwqvgpbb +9-15 f: fdfqffhfpfnffpwfffhf +4-7 t: ttwbttjtdt +3-14 d: ddhdddddddmsdddddddd +3-4 z: vsmm +7-8 w: wwwwwwhw +3-4 r: rrrlvwvqztszhmr +4-5 c: ccctkcn +1-3 g: ggmpdspfbvb +3-4 c: cccc +5-6 p: pqgppspbkpgxvcsp +7-13 n: nnnnlxnvnnmng +9-14 l: lqlllllxlllllzll +6-12 l: llllllllljlxll +3-8 g: jbkzsshsmsngghn +1-4 r: trrrrz +3-4 p: kppg +1-5 w: whljvw +11-14 v: svnrvvtmvccgcxjfbpkd +12-18 q: rqqvfqqqqqtvqqqmqq +12-18 m: mxmmmqmpmmwmmmmmmm +8-9 k: hkvnxnmkpkmplkkkkkkv +6-8 p: ppppppppp +3-5 t: qpxdtctb +15-18 z: zzzzzzzzhzzzzzbtzzt +10-11 t: ttswttttmttttt +10-11 f: ffffxffffffs +2-3 j: hjrj +6-10 x: xxxctxxjgdz +10-11 r: brrcrrrhwlz +9-10 s: sxssssqssksq +7-13 n: bnkwlnnncnnvnnnnn +11-13 f: lffffffffgffcfffffc +2-4 z: qczzfcztz +10-12 q: qxqqqqqcqqjqqqw +6-9 h: hhjhhhhhrqhch +3-4 l: xjmllb +2-5 m: mmmhm +1-2 w: pwkzww +3-7 s: sgccssszvssnqssj +6-8 j: jjgpjjnj +9-13 s: zjhskrssshssvqdxsrns +7-9 b: bbbbbbfbd +8-10 c: cwczgzcccgcctscfx +4-8 s: ssssmgssslrssp +14-20 z: jzjszzzzzzzzptzlzzzz +5-6 d: dsdddhd +6-7 z: zzzzzzh +2-8 f: fpzsgwsh +2-4 d: dddd +5-6 w: wwwdwc +3-4 r: crnr +4-7 s: zssdvsz +19-20 x: xxxxxxxxxxxxxhxxxxhx +7-8 g: ggggggkg +8-10 f: fffwfcfvdfffff +5-6 v: vvvvmv +9-14 k: wkpkknkkklkknkkkkkc +3-4 h: hhhjhhht +1-5 c: cbccrcbcdczgccfct +13-15 x: xxxxxxkxxxxdxpzqxxx +13-15 b: bbbbbbbbbbbbgbb +1-4 v: wvvvnm +5-8 v: zczvdvmvjvzv +8-9 p: gsppkptps +8-17 r: srrrrhjnrrdrrvrrhrv +9-13 l: lmlclllglqllmlll +1-4 g: gfgj +2-8 c: jtvmkcccdmccfxh +5-7 l: llztkvlb +2-7 v: fvlbrrtdpv +7-9 b: bbbbjbwbbd +6-8 j: jsjjjjjjj +3-5 w: wwwbwbgjmlrvfhkvfqp +15-17 l: llllllllllllllfll +13-14 z: dzzzzzzzzzzzzwz +11-13 z: zzzzzxzzzzzzg +3-4 b: pgbntlqbtbbbnp +7-12 z: zzpzjzzzmzzzzjzjzz +2-11 h: dtjsvvjkvghq +3-5 p: zpcjpp +14-17 z: zzzbzzznwzzzzzzzzzzz +3-6 h: nxhlfxlxngphhbdb +7-10 n: tjnnnncwnnvnnn +1-2 b: bfbm +13-16 t: ttdttttttrttztttt +9-10 t: jthtfttttttttt +8-9 z: cvfzzfnzzzzzlfzz +15-16 b: bbbbjbbpbbbcbbmm +3-9 x: rrqxxgxxt +4-18 j: qqqjlzcjfnjddjnqzvh +3-14 q: qqzqqqqqqqqqqdqq +5-6 h: hhhlch +5-11 z: zzjdzjzdtzww +2-9 w: wwwswwgbftlr +3-4 l: hlllbgdczpl +5-8 c: wwcvccckcccc +1-3 j: czjzxblj +1-3 z: vjzjz +11-16 m: mmmmmxrmmmmmtmxkmmhd +4-10 h: gzkhhxplhhhh +3-7 d: smdxmdfpn +12-17 t: tttttttntttdttttt +3-4 f: kfffjwhbllp +4-10 h: hhgkvhhhnqhh +14-18 w: whlchwwqwwlrwjdbwww +4-6 z: szjzhjhpzzmgz +3-9 x: xxxxxxxxq +5-6 x: rxprlx +3-4 b: pbbbbb +11-13 g: ggggggggggggh +2-3 b: bfbb +6-7 d: dddddvd +2-10 p: ppskvdctvpsn +12-18 r: rrrrsrrrrrrfrrrrrrr +4-5 c: ckclcc +8-13 v: vvtmtvvvvvvvvvzwp +4-18 j: qmdwjqqlpznldltqvjm +1-4 j: dbcjpzk +4-5 f: ffmfqvzf +8-10 p: pprptnfvpphvppp +7-8 z: zzzzzzzzz +10-11 n: xnnnnnnnnnnn +10-17 v: jwmqwvplsvvvfhhll +5-6 w: wwwwqtw +5-13 c: cccwbcccccccncfc +13-17 r: rrrrrrrrrrdrrrcrldn +2-15 b: nbnknkblbdbbhxxn +17-19 n: jwmjbxxvcrqlwpsknnz +5-16 x: xxxxxxxxxxjxxxxnx +1-7 m: mmmmmmvm +4-5 r: rrrrv +6-7 c: xkdzcscg diff --git a/2020/02/puzzle-1.awk b/2020/02/puzzle-1.awk new file mode 100755 index 0000000..77971dc --- /dev/null +++ b/2020/02/puzzle-1.awk @@ -0,0 +1,10 @@ +#!/usr/bin/env -S awk -f + +{ + split($1, bounds, "-") + freq = gsub(substr($2, 1, 1), "&") - 1 + if (freq >= bounds[1] && freq <= bounds[2]) + count++ +} + +END { print count } diff --git a/2020/02/puzzle-2.awk b/2020/02/puzzle-2.awk new file mode 100755 index 0000000..24398e7 --- /dev/null +++ b/2020/02/puzzle-2.awk @@ -0,0 +1,19 @@ +#!/usr/bin/env -S awk -f + +{ + split($1, pos, "-") + split($3, str, "") + char = substr($2, 1, 1) + + # Count the frequency of char + freq = 0 + if (str[pos[1]] == char) + freq++ + if (str[pos[2]] == char) + freq++ + + if (freq == 1) + count++ +} + +END { print count } diff --git a/2020/03/input b/2020/03/input new file mode 100644 index 0000000..6673c40 --- /dev/null +++ b/2020/03/input @@ -0,0 +1,323 @@ +....#..#.......#........#....#. +..##.#.#.#...................#. +....#.#.##..#....#......#...... +.........#.#......##.....#..... +..........#.###.##...##........ +#....#.#.......##.....#..#..... +#...........#.#...#..#..##.##.. +......##.............#.....#... +..##..........###..#.#..##..... +...........#........#......##.. +..##...........##.............. +..#......###.#.....#.#.#....... +..#..#..#..........#.#....#.... +.#.....##...................... +...#...##..#...#.........#..##. +.#......#..#..#...#......#.##.. +..##.##.......#..#.....#..#...# +..............#..#..#...#...... +...#...#....##.....#...#...#... +......................#...#.... +.......#......#...#..##...#.#.. +##......#..#.....#....#.....#.. +....#.#.##.#.#....#............ +#.....##.............#......... +..........#...........#.#.....# +...#...##....#.#........#..#... +................#..#.##.##....# +......#...#...##...##....#..... +##....#..#..#...#..#........... +#..................#...#.#..#.. +....##....##.#....#..#......#.. +.....#...........#.........##.. +..#..............#.........#..# +......##....................#.. +..#.....###...####...#...#.##.. +#..#.#......#.....#.......#.#.. +##.#.........######........#... +..#....###...#.#..............# +.....#..............#.........# +....#......#..#.........#...#.. +.....###.....#.###.......###... +#.#..#.....#....##...#........# +..##....#..#.........#...#.#... +..#..##.............#....#.#.#. +..##.#..#.#.#.........##....... +#.#..#.........#..............# +#..#.........###.......#.#..#.# +.............#...#....#......#. +..........#.#...##.###.....#.#. +..#.....#...................... +.......#......###.#.......#.... +....#....#.........#...###.#.#. +.#.............#............#.. +....#..#.............#.#....#.. +....#.....#...#...##.#......... +..#...#...#..................#. +........#....#.....#........... +.....##.......#...#.#..#..#.... +...#............#..#.#......... +......................#........ +....#......#.....#.#....#...... +.....#..#.........#.........##. +...............#.....#....##... +...#.#.#...#..#...........#.... +.#....###......##...#.#.#.#.... +.....#...#....####....##....... +..#......#..#.....##.#...#..... +...#.##..#....#..##.....#...... +..#......#...#...##.....#...#.. +......#.....#........#......... +..#.#....#..............##....# +..#...#......##............#... +.##.#.......#.......#......#..# +...##.##...#.....#.......#..#.. +......##..#....#.......#....... +.....#..#..#.#.....#.....#...## +##.#...#.#.#.....#...#.#.#.##.# +...................###...#..#.. +.#.....##.#......#........#.... +.##...##.#..........#...#....#. +......#..............#.#......# +...#.......#..#...........#.... +.###...#............##..#...##. +##..#.#.........#............#. +#...#.#......#.##...........#.# +.#.#...#........#......##...... +....#...#...#.....#...#....#... +...##...........##.........#... +.........#...#..###............ +..#........#...............#... +.............#....#.#.......... +........#......#.#.......#....# +.................#....##.#.##.. +..#...##........#.............. +#..#........#...#....#......... +......#.#.....#.....#..###.#..# +....#............#...#.#.#..... +............#..........#...#... +..........#....##.#.........#.. +..............#...#...#..#..... +#......#....#..##....#......##. +...#....#.................#.... +.#.##.............#...#....##.. +....#..#.........#..#....#....# +..#.....##..#......#.#..#...... +..#..#.....#........#...#..#..# +.........##.#.##.#.......#....# +..#.......##.##...#.....#.....# +.............##...#...........# +..#......#..#....#...#..#.##... +....#........#......#.........# +.......#........#..#.#.#..##..# +..#......#...........##...#.... +.....#..#.#...#..............## +.#..#......#......#........#..# +...##...............#....#..... +.......#...#.......##..#....... +.....#....#...#...#..#.....#.#. +...#.........#.....#........... +...#.....###....#....#...#...#. +#..#.....#.........#.........#. +.................#.#.....#....# +...........#..........#..#..... +........#.#....#...#..#.....### +#............................#. +..##..#..#...##.........#...... +......##....#.#...#.........#.. +......#..##.#......#..#.....#.. +...#.......##....#.#....#...... +.....#........#...#............ +#.......#...#.........#......#. +......#......#....#..#......... +..#.#........#..#......#....#.. +.#..#.#..........##....###.#..# +...#....#.##..#...#....#....... +..#.....#......#.###.......#... +..............................# +.....#..#...#...........#...... +.##...#....##....#.#.#.#....#.# +.#...#....#...#........#....... +....#............#...##..#..... +....##..#....#....#.....#....## +.............#..##.#.#.#....... +#.......#.#.#.......#..#..#.... +#..#...........#.......###..#.. +.#..##.#.....#........#........ +..#.#.......#............#..#.. +...........#..#............##.# +.....#.......#.....#..#.##.#..# +......#......##.....##......... +..##.#..#.#..#..#.............. +.....#.............##...#.#.##. +.#......##.#..........#........ +..#..#.........#.....#.#.#..... +..#.....#.......#.....#..#..... +#.#.#........#.#...#....#..#... +.#.#.......#............#....#. +......#..................#....# +.#...#...#.....#.#..........#.. +.#..##....####...........#.#... +..##.....#...#.#....#....#..... +#.....................#....#.#. +###..###.#.#...........#.....## +......#......#..........#...... +...#......#.##.....#......###.# +.............#..#.#...........# +..#.............#.#..#.....#... +...#...............#....##...## +........#.................#.... +#..###.....#.......##.#......## +....#.#..............#......... +#..........#.....#..##...#..... +................#...#..#....#.. +..#...#....##..........#.#..... +......#........##......#..#...# +...#....#..#.....#.......#...#. +.#.....#..#...#..###....#...... +....#.........#....#.#.#.....#. +#.#....#...#....#.....#..##.... +.......#..#..#..........#...#.. +..#.#..#.....##.#.#............ +..#....#.....#..##..#..#.#..#.. +..#.##.#...........#...#..#.... +.........#........#...#........ +..#.#.#.......##.........#.##.. +#.#..........#.#...#..#......## +.#..#....................#.#... +.##......#................#...# +..##.#######......#....#....... +....#...##.#....#.#............ +.##....#...##.......#...#..#... +...........#...#...#...#..#.... +#...#.....#.......#....#.....#. +.............#................. +........#.#.......#...#.#.#.... +..............#............#.#. +......#......##..#.......#....# +##...#..................#...... +.....#......###.....#.......#.# +.....#.#............#.#........ +..#.#..#............#....#.#... +##.#.###.#.#.#..#......#....... +...##........#..#.....#.#.#..#. +##......#.##.....####..#....... +............#...#..#...#..#.... +...#..#................##.#..#. +.#....#.#...........##.#.#...#. +####..#...........#.......###.. +.......#.................#..... +.......#....#.......##....#.... +..#.........#...#....#......... +..........#..#...#.#...##..#... +....##..........#.........##... +#.........##..#.#..#.......#... +.#...........#....#...#...#.#.. +....#..#.....#...##....#.#....# +.#....#.....#......#..##.##.#.# +#......#..#.......##........... +...#..#...#.#.................# +......#.......##....##.#......# +....#....#.#.#.....#....#....#. +..#..........#.##...##..#...... +...#..#........#....#.#..#....# +##.......#........#..........#. +.#........#.......#...#..##...# +..#..#..##..#...........#...### +..#......#..........#..##...... +.#.....#..#.#...#...#.........# +#.#......##.................... +#...#.....##...........#....... +........#...#....#.......##.... +...#.##...#....#....#..#..#..#. +...#..#......##....#..#..##.... +#...#..........#.#............. +##..#........##.....#.........# +.....#......#.#...###..#....... +#..##.#..#.###...........##..#. +.....#....#..........#.......#. +##.........##.#................ +....#.........#............##.. +.......#........#......#..#..## +.#...#...##..#....#..#......... +.............#...#.#........#.. +......#..#...#..#.###..#....... +........##.#..#.#..#..#........ +#.##..#..#..........#...##..### +.##...#............#.#...##..#. +................#....##.#...#.. +#.................#..........#. +...#..#..#..................... +..#...##.#.#................... +.....#...#.......#............# +..#..#.........#..##.#..#.#...# +.....#.#.....#.#.......#.....#. +..................#..#....#.#.. +..#.....###.##.......##....#.#. +..#......##.......#....##.#.... +....#...................#..##.# +.......#....#.##.#.......#....# +..#...#......#..#...###....#.#. +..#..#.#....#...........#.....# +.....#..#..#.......#........#.. +......#.##.#......#...........# +#...#....#.#..##.##..#..##..... +#...##....#.#...##........#.... +..##............#.#.#.......... +....#.....#.#..#.......#..#.... +#..#.#.....#..#..##...#..##.... +...##........#...........#...#. +.####......#..##.........#.#... +.......#....................... +.................#....#..#..... +.........##......###........... +.##......#.#.#....#.#...#..###. +....#......##.###.#.#..#....... +..........#.......##......##..# +...........#.......#..##....... +.....###..#..............##.... +........##..#.#.#......#....#.. +#....#......................... +...........#...............##.. +......#.................#...... +.....#...#..##...##...#...#.... +..........#.#...##.####......#. +..#.#.....##....#...........#.. +..........#....#..#....##...#.. +.#.......#..##...#...#.....#... +...##....#.#......##...##....#. +#.......#.......#.##.#...#.#... +#...#..................#......# +..#.......#...............#..## +#.....#..................#....# +.##.....#.....#......####.....# +..#........#...#.#........#...# +..##.....#....#...#...........# +..#..#.....##..#.##...#........ +..........###..#....##.....#... +...#...#....#.##.#...#.#....... +..##......#.......#.......##... +............#............#..... +.##....#.........#............. +....#....#....#........##...#.# +.......##...................... +..........#.#.................# +......##.#...#.........#.....#. +..#...#......#..#.............# +..........###.#..#.#...#..#..#. +#..#.#..#....##...#...#.#...#.. +.#........##...#......#.##..... +...###.#...##..............##.. +#.#.#...#...#..#....#.#..#..... +.#.#.##..#....#......#.#....... +...#..#.#....##...........#..#. +.....##..##......#.#........... +......#.....#....####....#..... +.#.#.#...#..#..#...........#... +.....#......................#.. +.........#.........#.###.##.... +.....#......##..........#...... +..#...........##...........#... +..............#.........#.....# +..#....#..#...#...##.#......... +.#.#.#....#..........#......... diff --git a/2020/03/puzzle-1.awk b/2020/03/puzzle-1.awk new file mode 100755 index 0000000..3eac2ba --- /dev/null +++ b/2020/03/puzzle-1.awk @@ -0,0 +1,14 @@ +#!/usr/bin/env -S awk -f + +BEGIN { x = 1 } +{ + len = split($0, obs, "") + + if (x > len) + x -= len + if (obs[x] == "#") + count++ + + x += 3 +} +END { print count } diff --git a/2020/03/puzzle-2.awk b/2020/03/puzzle-2.awk new file mode 100755 index 0000000..88e0625 --- /dev/null +++ b/2020/03/puzzle-2.awk @@ -0,0 +1,36 @@ +#!/usr/bin/env -S awk -f + +BEGIN { + slope[1] = 1 + slope[2] = 1 + slope[3] = 1 + slope[4] = 1 + slope[5] = 1 +} + +{ + len = split($0, obs, "") + + right = 1 + for (i = 1; i < 5; i++) { + if (slope[i] > len) + slope[i] -= len + + if (obs[slope[i]] == "#") + count[i]++ + + slope[i] += right + right += 2 + } + + # Specific code for slope 5 + if (NR % 2 == 1) { + if (slope[5] > len) + slope[5] -= len + + if (obs[slope[5]++] == "#") + count[5]++ + } +} + +END { print count[1] * count[2] * count[3] * count[4] * count[5] } diff --git a/2020/04/input b/2020/04/input new file mode 100644 index 0000000..c49fb69 --- /dev/null +++ b/2020/04/input @@ -0,0 +1,1135 @@ +eyr:2029 pid:157374862 +byr:1991 ecl:amb hcl:#a97842 hgt:178cm + +byr:1962 pid:547578491 eyr:2028 ecl:hzl hgt:65in iyr:2013 hcl:#623a2f + +hgt:71in eyr:2037 +ecl:#8e276e hcl:z iyr:2019 +byr:2022 pid:157cm + +hcl:#733820 hgt:175 eyr:2028 iyr:2011 +pid:87786389 +ecl:hzl byr:1980 + +hgt:163in hcl:z pid:8261494508 cid:136 ecl:grn eyr:1958 +byr:2030 iyr:1991 + +iyr:2021 +hcl:6708a3 +ecl:zzz eyr:2034 byr:2010 +hgt:189cm +pid:466438311 + +iyr:2012 pid:9720867166 byr:2006 eyr:2022 hgt:72cm ecl:utc hcl:#c0946f + +ecl:#353bc9 +iyr:2020 pid:874363951 cid:113 +hcl:z eyr:2040 hgt:76in byr:1975 + +eyr:1971 +byr:1955 pid:193cm hgt:189cm hcl:#ceb3a1 ecl:grn +iyr:2023 + +byr:2014 +iyr:2026 eyr:1978 hcl:z cid:312 pid:8294818417 +hgt:169in ecl:#82bb02 + +ecl:amb +byr:1936 hcl:#7d3b0c pid:429853734 +cid:342 iyr:2010 eyr:2025 hgt:160cm + +byr:2025 hgt:176in hcl:a490ac +ecl:#956d3f iyr:2027 +eyr:2021 pid:9858101884 + +hgt:142 pid:175cm +eyr:1952 byr:2004 iyr:2007 ecl:#da035e hcl:#623a2f +cid:194 + +hgt:156cm +pid:349122810 hcl:#b6652a eyr:2026 byr:1948 ecl:lzr iyr:2020 + +byr:1997 ecl:blu +hcl:#888785 pid:381094641 iyr:2014 hgt:192cm eyr:2027 + +hcl:7b10a2 ecl:lzr byr:2022 +eyr:2035 +pid:#38b715 hgt:190in iyr:2029 + +pid:188cm byr:2014 +cid:241 ecl:#dda9bd hcl:#8f6ebc +hgt:188cm iyr:2014 eyr:2029 + +hgt:76cm ecl:gmt hcl:z iyr:2024 +pid:3283057785 +byr:2019 eyr:2026 + +iyr:2010 pid:284327216 hgt:191cm +byr:1970 +hcl:#18171d +ecl:grn +eyr:2023 + +byr:1929 eyr:2026 cid:194 ecl:oth hgt:156cm pid:224596482 hcl:#b6652a iyr:2013 + +eyr:2030 byr:1958 hgt:190cm +pid:162950579 iyr:2010 +ecl:brn +cid:250 hcl:#fffffd + +ecl:xry iyr:2025 pid:#0155c1 +hcl:#341e13 +eyr:2027 hgt:163cm byr:2025 + +hcl:#602927 pid:908859481 byr:1962 ecl:hzl +iyr:2021 eyr:2028 hgt:180cm + +iyr:1966 eyr:1976 pid:#bbfe21 hcl:63454a cid:259 +ecl:blu +byr:2024 hgt:69cm + +ecl:#644daf +byr:2021 eyr:2040 +hcl:bc83fe +iyr:1976 hgt:59in pid:60311335 + +iyr:2018 +pid:121801570 hgt:182cm ecl:blu byr:1922 cid:265 eyr:2024 hcl:#888785 + +byr:1933 +pid:232653422 ecl:gry hcl:#18171d +hgt:171cm eyr:2035 iyr:2011 + +ecl:oth iyr:2015 byr:1937 +pid:828621370 hcl:#602927 +eyr:2026 +hgt:193cm + +iyr:2010 ecl:grn eyr:2022 +hcl:af37d1 pid:761632482 hgt:65in cid:93 +byr:1993 + +hgt:169cm cid:121 +iyr:2018 +hcl:#6b5442 +pid:059725560 ecl:oth +byr:1972 eyr:2028 + +eyr:2024 byr:2023 ecl:gry +iyr:2017 +pid:778551716 cid:256 hcl:#733820 hgt:184cm + +hcl:#ceb3a1 pid:613277258 byr:1941 hgt:67cm eyr:2029 +ecl:hzl +iyr:2017 + +ecl:hzl iyr:2012 pid:498418959 eyr:2022 +byr:1929 hgt:164cm hcl:#a97842 cid:226 + +hgt:157cm eyr:2029 +byr:1922 iyr:2014 ecl:grn cid:233 hcl:#888785 pid:802870003 + +hgt:184cm +ecl:oth hcl:#888785 iyr:2010 byr:1929 eyr:2030 +pid:063671905 + +hcl:#888785 hgt:144 eyr:1961 +iyr:2005 +byr:2027 +cid:164 pid:41787324 +ecl:utc + +hcl:#7d3b0c +pid:570743051 byr:2022 eyr:1975 +iyr:2018 ecl:utc hgt:188in + +eyr:2028 pid:970460968 +hgt:161cm +iyr:2017 ecl:amb +cid:318 byr:1967 hcl:#cfa07d + +hgt:183cm eyr:2036 hcl:070713 iyr:1959 +cid:242 byr:2011 pid:#0855a5 ecl:lzr + +hcl:#ceb3a1 eyr:2023 iyr:2016 +ecl:oth hgt:84 +pid:156cm byr:1949 + +eyr:2025 ecl:brn hgt:172cm pid:487559063 iyr:2013 +hcl:#efcc98 +byr:1985 + +eyr:2023 hcl:#6b5442 byr:2021 hgt:75cm iyr:1943 +pid:427375038 ecl:#70c167 + +ecl:hzl +eyr:2028 byr:1957 iyr:2010 +hcl:#602927 +hgt:151cm pid:755290924 + +cid:184 hgt:172cm +pid:7056500139 iyr:2016 byr:2016 +hcl:e40e08 ecl:#d21247 + +ecl:oth +eyr:2025 +iyr:2010 byr:1971 cid:128 pid:932834922 +hcl:#602927 +hgt:167cm + +ecl:brn hgt:61in iyr:2016 hcl:#341e13 +pid:918193693 byr:1972 eyr:2029 cid:56 + +byr:1956 iyr:2020 eyr:2030 hgt:72in +pid:179969841 +ecl:blu + +ecl:#09fd92 cid:209 hgt:69cm iyr:2014 +eyr:2028 pid:#2ad9c0 hcl:#b6652a +byr:2012 + +ecl:lzr byr:1980 cid:104 +iyr:1965 pid:57029893 hcl:z +eyr:2030 hgt:64cm + +pid:496149551 +hcl:#6b5442 hgt:181cm byr:1978 iyr:2017 +eyr:2026 +cid:291 ecl:hzl + +iyr:2018 hcl:#ceb3a1 +eyr:2021 cid:183 pid:612653062 +ecl:oth +byr:1982 + +hgt:153cm pid:877597531 ecl:gry +iyr:2014 hcl:#866857 cid:333 +byr:1953 +eyr:2022 + +iyr:2015 +ecl:brn +pid:823959694 byr:1998 hcl:#18171d +eyr:2025 hgt:174cm + +iyr:2012 cid:93 +ecl:oth pid:142618419 byr:1955 hgt:193cm eyr:1977 hcl:#602927 + +hcl:z ecl:dne iyr:1926 eyr:2026 pid:175cm hgt:150 byr:2023 cid:234 + +hgt:61cm iyr:1965 byr:1956 +pid:224946350 cid:105 +eyr:1951 hcl:#733820 ecl:amb + +hcl:#866857 +byr:1970 pid:447859408 +eyr:2030 +hgt:65in iyr:2011 ecl:grn + +cid:184 eyr:1976 byr:2021 hgt:187cm +pid:858786336 ecl:#0d63e1 hcl:z + +hgt:178cm iyr:1986 hcl:51ac0c ecl:dne eyr:2023 pid:180cm + +hcl:#cfa07d pid:002093179 +ecl:oth +byr:1983 hgt:159cm iyr:2016 eyr:2025 + +ecl:gry hcl:#c0946f +byr:2009 pid:#e00fc8 +hgt:62in cid:150 iyr:2013 eyr:1957 + +byr:1942 ecl:oth eyr:2020 pid:765036664 hcl:#6b5442 iyr:2015 cid:155 + +ecl:hzl iyr:2014 +hcl:#efcc98 hgt:179cm eyr:2028 +byr:1921 pid:#666905 + +ecl:utc eyr:2040 hcl:669f5b pid:981368190 +byr:2006 iyr:1949 +hgt:179in + +ecl:#062fcd eyr:2035 byr:1962 iyr:2026 hcl:z hgt:161cm pid:75591618 + +hcl:#b25ef5 pid:434943296 +ecl:oth hgt:165cm +iyr:2013 eyr:2020 +cid:78 byr:1924 + +iyr:2018 ecl:oth byr:1972 eyr:2028 pid:035313920 +hgt:59in hcl:#fffffd + +hgt:185cm +hcl:#6b5442 +cid:102 iyr:2020 byr:2001 +eyr:2028 pid:003365121 ecl:amb + +pid:90937712 hcl:z hgt:173in byr:2012 ecl:blu iyr:2009 eyr:2039 + +pid:509460932 eyr:2026 +hgt:71in iyr:2010 cid:138 byr:1929 ecl:grn + +ecl:xry +hgt:119 +pid:051834447 eyr:2033 +iyr:2030 hcl:z byr:2030 + +pid:443984745 eyr:2026 ecl:oth +byr:1948 hcl:#a97842 hgt:168cm +iyr:2017 + +hcl:#602927 iyr:2020 cid:161 pid:069708283 hgt:178cm byr:1960 +eyr:2022 ecl:hzl + +iyr:2026 hcl:766b30 eyr:2032 byr:2030 pid:40361792 hgt:158in ecl:#b300dc + +eyr:1998 pid:#5c21e4 iyr:2029 ecl:#bef182 +byr:1944 hgt:166in +hcl:#b6652a cid:317 + +ecl:amb +eyr:2024 +hcl:#a97842 +pid:086765271 hgt:183cm iyr:2018 cid:314 byr:2001 + +hgt:163in pid:491612094 iyr:2028 +cid:82 ecl:#8a052d +hcl:#ceb3a1 +eyr:2018 + +byr:1970 eyr:2039 +hgt:174in hcl:#623a2f +iyr:2020 cid:154 ecl:grn pid:103138652 + +pid:73895324 eyr:2026 byr:1952 ecl:brn hcl:#733820 hgt:159in iyr:2015 + +hcl:#623a2f ecl:brn eyr:2026 hgt:185cm pid:791563822 iyr:2019 byr:1951 + +hcl:#fffffd +iyr:2014 hgt:83 cid:101 pid:724483094 +eyr:1995 byr:2015 ecl:lzr + +hcl:#ceb3a1 +iyr:2013 +eyr:2021 byr:1994 ecl:hzl +pid:037849486 hgt:60in + +pid:63340670 iyr:1995 hcl:b54c2b hgt:71cm +cid:184 byr:2004 ecl:dne eyr:2026 + +hgt:169cm +ecl:brn byr:1947 iyr:2014 cid:224 hcl:#7374df + +hcl:#623a2f +pid:471948403 ecl:gry +hgt:154cm +eyr:2023 iyr:2016 byr:1925 + +eyr:2024 hgt:180cm hcl:#efcc98 iyr:2020 ecl:gry byr:1961 pid:318184801 + +ecl:blu iyr:2012 eyr:2020 hgt:190cm +byr:1977 +pid:331654452 hcl:#cfa07d + +pid:812502106 byr:1938 +eyr:2020 hgt:169cm ecl:oth hcl:#341e13 iyr:2011 + +cid:286 byr:1942 eyr:2034 hgt:116 +ecl:utc +iyr:2023 hcl:#602927 pid:181cm + +ecl:amb iyr:2011 hcl:#cfa07d eyr:2029 byr:1975 +hgt:183cm pid:548900689 + +ecl:utc pid:182cm +hgt:60cm +eyr:1989 iyr:1993 hcl:z + +iyr:1985 hgt:186 byr:2018 +eyr:2001 pid:9257131167 +hcl:261a65 ecl:lzr + +hgt:152 +byr:1922 pid:72992226 +iyr:1968 +ecl:dne eyr:2028 hcl:5c2950 + +ecl:grn +byr:1943 hgt:74in eyr:2022 +pid:135491924 +iyr:2011 hcl:#623a2f + +iyr:2026 pid:7955389103 +cid:311 +ecl:#b81171 hcl:z eyr:1935 byr:2024 + +byr:1974 iyr:2010 hgt:165cm +ecl:amb cid:343 eyr:2023 +pid:972786259 hcl:#6b5442 + +iyr:2020 byr:1936 +ecl:gry hcl:#efcc98 hgt:170cm eyr:2021 pid:520354073 + +hgt:185cm hcl:#ceb3a1 +pid:317012754 byr:1991 +cid:199 iyr:2011 +ecl:blu eyr:2028 + +ecl:#e4e01f byr:2008 +cid:293 iyr:2013 hcl:z pid:#368f7a eyr:2036 + +eyr:2022 pid:424388475 iyr:2008 hcl:z hgt:61cm +ecl:zzz byr:1985 + +hcl:#18171d iyr:2014 +cid:88 +byr:1951 eyr:2021 pid:812441789 hgt:181cm ecl:blu + +ecl:amb eyr:2029 hgt:70in pid:580245172 +iyr:2010 byr:1927 +hcl:#a97842 +cid:284 + +hcl:#3b85ed +ecl:gry eyr:2029 pid:417534919 byr:1960 +iyr:2010 hgt:71in + +hcl:#c0946f +pid:824103775 hgt:157cm iyr:2018 ecl:brn eyr:2024 byr:1961 + +pid:673501373 +eyr:2033 +ecl:#06523f hcl:z byr:2030 iyr:1978 hgt:153cm + +iyr:2019 +hcl:#a97842 byr:1951 hgt:183cm eyr:2024 ecl:blu +pid:346079429 + +eyr:1937 pid:964649406 +hgt:162 +cid:66 +ecl:#f89cc0 +hcl:#866857 byr:2024 + +hgt:114 ecl:#e7ed3a +byr:2029 cid:190 +eyr:2026 iyr:1986 hcl:z pid:185cm + +hcl:#cfa07d hgt:192cm +pid:12494711 eyr:2028 +iyr:2020 +ecl:brn byr:2004 + +pid:710015269 +byr:2011 eyr:2033 hgt:181cm +ecl:#fb2702 + +cid:259 pid:208799387 +eyr:2025 hcl:#623a2f byr:1947 ecl:oth hgt:164cm iyr:2014 + +ecl:brn eyr:2025 pid:432178809 hcl:#341e13 +cid:50 +hgt:192cm iyr:2012 +byr:1994 + +hgt:150in pid:4902585462 ecl:#7074ad cid:230 iyr:2019 eyr:1931 hcl:z byr:2007 + +ecl:gry +byr:1942 +hcl:#602927 cid:178 iyr:2014 hgt:193cm pid:349100081 eyr:2030 + +byr:1923 hcl:#cfa07d eyr:2021 ecl:brn pid:591544598 hgt:157cm +iyr:2016 + +hcl:e15737 +iyr:2017 byr:2030 +eyr:1994 pid:470833249 +hgt:181cm cid:70 ecl:grn + +eyr:2030 +hcl:#866857 pid:569423049 byr:1948 +ecl:oth + +eyr:2026 +byr:2006 +hcl:#ceb3a1 +iyr:2010 pid:094156115 hgt:64cm ecl:oth + +byr:2002 cid:215 ecl:hzl +hcl:#602927 iyr:2015 pid:53150410 hgt:168cm eyr:2028 + +iyr:2016 hcl:#7d3b0c hgt:162cm +byr:1937 eyr:2020 ecl:hzl pid:728906226 + +byr:1921 +iyr:2018 hcl:#888785 +eyr:2026 hgt:185cm pid:164432370 ecl:brn + +ecl:gry iyr:2011 +eyr:2026 hgt:190cm +hcl:#866857 pid:884570088 byr:1996 + +ecl:blu +cid:257 +iyr:2016 byr:1989 +eyr:2024 hgt:179cm hcl:#c0946f pid:418340261 + +pid:9367990743 hcl:z hgt:182in ecl:utc +byr:1988 eyr:2025 + +ecl:hzl hgt:157cm +iyr:2010 eyr:2027 +hcl:#fffffd byr:1956 + +eyr:2024 pid:834302242 ecl:hzl +iyr:2015 cid:97 hgt:188cm hcl:#888785 byr:1927 + +ecl:brn eyr:2021 byr:1958 +hcl:#a97842 hgt:170cm pid:256795932 iyr:2017 + +hcl:756c4a +pid:812879747 +byr:2002 +eyr:2027 ecl:blu iyr:1952 hgt:66cm + +pid:#c5e14f +iyr:2026 byr:2028 hgt:162 hcl:87ba57 +eyr:1952 ecl:lzr + +hcl:#341e13 hgt:81 eyr:2021 iyr:2029 cid:262 ecl:amb pid:61006868 +byr:2011 + +pid:#e58702 cid:145 hcl:#866857 +ecl:grn iyr:2028 hgt:192in eyr:2025 byr:2017 + +iyr:2026 byr:1969 +ecl:grn +hgt:70cm cid:140 hcl:e0f231 eyr:2027 +pid:2832019 + +cid:112 eyr:2028 iyr:2018 hcl:#7d3b0c pid:868808117 byr:1985 ecl:blu + +iyr:2017 +pid:350399038 +cid:72 hcl:#ceb3a1 +ecl:gry +hgt:151cm byr:1946 eyr:2029 + +eyr:2026 hgt:174cm iyr:2010 pid:534641153 hcl:#733820 byr:1965 + +hgt:66cm +byr:2010 ecl:gmt eyr:2039 +iyr:2024 hcl:z + +pid:626085326 +byr:1971 eyr:2024 +hcl:#cfa07d hgt:170cm +ecl:hzl iyr:2019 + +hgt:185cm pid:995661846 ecl:hzl iyr:2016 byr:1963 hcl:#a97842 eyr:2023 + +ecl:grt iyr:1976 byr:2010 +pid:170cm +cid:343 hcl:#7d3b0c hgt:171cm + +pid:732695396 +ecl:zzz hgt:151in byr:1955 +eyr:2035 iyr:2026 hcl:z + +hgt:187cm hcl:#341e13 iyr:2015 pid:556697270 eyr:2025 ecl:blu byr:1926 + +ecl:oth +pid:515980529 +hgt:168cm eyr:2023 +byr:1983 iyr:2012 hcl:#341e13 + +byr:2010 +hgt:189cm iyr:2016 +hcl:#8ff71e +eyr:2010 +ecl:blu +pid:317940449 + +iyr:2013 hgt:157cm hcl:#a97842 pid:967988435 +ecl:blu cid:214 eyr:2027 byr:1960 + +pid:2666548509 cid:208 hgt:72cm hcl:#7d3b0c eyr:2040 byr:2008 +ecl:amb +iyr:1926 + +eyr:2039 +pid:203432895 hgt:154cm byr:1949 +iyr:2010 +hcl:z cid:144 ecl:xry + +pid:984689798 byr:2016 iyr:1999 ecl:utc +eyr:2037 hgt:68cm hcl:z + +byr:1969 cid:230 hgt:72cm eyr:2032 +ecl:gry pid:849701444 +hcl:#c0946f +iyr:2012 + +eyr:2026 +pid:588870142 +hcl:#ae5619 hgt:173cm +cid:189 +ecl:grn byr:1996 iyr:2013 + +byr:1973 +hcl:#cfa07d ecl:blu +hgt:193cm eyr:2028 cid:115 pid:786380485 iyr:2011 + +hcl:#fffffd eyr:2028 hgt:155cm pid:499022582 +ecl:blu byr:1977 iyr:2014 +cid:212 + +ecl:#92bb4b +pid:815154669 byr:1923 eyr:2023 +hgt:183cm iyr:1929 hcl:#ceb3a1 + +byr:1966 eyr:2021 iyr:2020 hcl:#6b5442 ecl:hzl +pid:3508035599 +hgt:70in + +ecl:amb +hcl:#18171d +byr:1927 +hgt:177cm pid:555764540 iyr:2018 eyr:2025 cid:90 + +hgt:139 ecl:#878a7d byr:2006 cid:275 iyr:1980 hcl:60fca6 eyr:1952 pid:001439727 + +byr:1985 +hgt:174cm ecl:gry +iyr:2018 +cid:204 hcl:#733820 +pid:141048398 eyr:2027 + +ecl:gmt hcl:#6b5442 hgt:158cm +iyr:2025 +byr:2030 pid:966397365 eyr:2029 + +byr:1962 hgt:166cm pid:261989937 cid:320 eyr:2026 +iyr:2015 hcl:#c0946f +ecl:hzl + +pid:852283506 iyr:2018 eyr:2020 byr:1981 hcl:#733820 +ecl:hzl +hgt:162cm + +pid:3873488100 iyr:1982 ecl:grn +hgt:63cm eyr:1936 +byr:2011 hcl:8d118a + +iyr:1937 +hcl:817646 +byr:2026 eyr:2031 pid:#47591d hgt:183in +ecl:blu + +eyr:2025 hgt:153cm iyr:2015 pid:498382864 +cid:307 +byr:1943 +hcl:#f66fe1 ecl:oth + +iyr:2017 hgt:66in byr:1948 hcl:#b6652a eyr:2025 +pid:188366364 +ecl:amb + +ecl:lzr +pid:453174702 iyr:2028 eyr:2032 cid:228 byr:2011 hcl:z +hgt:172cm + +hgt:186cm eyr:2030 cid:316 hcl:z byr:1994 +iyr:2012 ecl:amb pid:993162839 + +hgt:160cm +ecl:grn pid:523473760 byr:1993 +iyr:2016 eyr:2025 hcl:#602927 cid:261 + +iyr:2016 pid:520973843 ecl:gry +eyr:2023 cid:232 +byr:1944 hgt:159cm hcl:#cfa07d + +byr:1969 hcl:#1d37de hgt:184cm eyr:2027 pid:088048141 +iyr:2016 cid:307 ecl:hzl + +eyr:2040 iyr:2012 pid:723592140 +hgt:61cm hcl:#18171d ecl:dne + +eyr:2025 +ecl:oth pid:4697392468 +hgt:183cm iyr:2017 hcl:b07d71 +byr:1996 + +ecl:amb eyr:2022 cid:143 pid:806594272 hgt:158cm byr:1977 iyr:2014 +hcl:#866857 + +ecl:blu +eyr:2022 iyr:2018 byr:1983 hgt:167cm cid:321 hcl:#efcc98 +pid:344179526 + +byr:1925 eyr:2021 +hgt:193cm iyr:2020 ecl:grn +hcl:#888785 + +iyr:2018 +cid:319 byr:1972 hgt:181cm hcl:#fffffd eyr:2023 pid:493780616 + +eyr:2021 +hcl:#733820 +ecl:#e91c71 +iyr:2020 pid:451676066 hgt:166in +byr:1993 + +eyr:2026 +hcl:#b6652a ecl:blu byr:1999 iyr:2020 +hgt:163cm pid:955741810 + +iyr:2016 hgt:179cm hcl:#602927 +pid:673271332 byr:1963 eyr:2027 ecl:amb + +byr:1927 +iyr:2015 hcl:#866857 +ecl:oth +hgt:159cm +pid:992992996 eyr:2030 + +pid:283188332 hgt:168cm hcl:#6b5442 +eyr:2027 byr:2028 ecl:hzl iyr:2030 + +byr:1944 pid:628012522 eyr:2020 +hcl:#866857 +iyr:2019 ecl:amb +hgt:168cm + +cid:317 pid:333228098 hgt:158cm iyr:2014 byr:1958 eyr:2024 hcl:#a97842 ecl:oth + +hcl:#733820 +cid:314 ecl:oth byr:1938 eyr:2030 hgt:71in +pid:790938694 iyr:2014 + +iyr:2020 ecl:grt eyr:2018 +hgt:155cm +pid:1034925815 hcl:#623a2f cid:304 + +ecl:brn hgt:158cm hcl:#38fe6c eyr:2030 byr:1926 pid:0860404500 iyr:1993 cid:348 + +byr:1998 +hgt:185cm +ecl:brn eyr:2021 pid:567032567 hcl:#733820 cid:328 iyr:2017 + +pid:491430863 cid:146 hgt:181cm eyr:2026 iyr:2015 ecl:amb byr:1950 hcl:#c0946f + +eyr:2033 cid:289 +pid:396679011 ecl:oth byr:1988 +hgt:156in +hcl:#cfa07d iyr:2029 + +ecl:grn iyr:2015 +byr:1986 hcl:#a97842 hgt:62in +pid:403990108 eyr:2030 + +pid:42635067 cid:301 +iyr:2027 hgt:173in +byr:2004 hcl:z +eyr:2034 + +byr:2020 hcl:#fffffd +hgt:180in eyr:2040 pid:304951921 +iyr:2030 ecl:#1aaf20 + +iyr:2020 hcl:#888785 ecl:hzl hgt:181cm byr:1992 eyr:2021 pid:936006959 + +hgt:172in ecl:#fd71a7 +hcl:787715 pid:363058480 byr:2020 +iyr:2022 +eyr:2034 + +iyr:2018 ecl:blu eyr:2029 hcl:#cfa07d hgt:155cm byr:1937 pid:851148031 + +byr:2014 +cid:222 ecl:zzz hgt:67cm eyr:2040 pid:#8ab0e2 hcl:z iyr:2027 + +hgt:180cm hcl:#375883 eyr:2027 byr:1925 ecl:brn +iyr:2011 +pid:158752719 + +byr:1935 ecl:oth eyr:2027 pid:041108579 +hcl:#602927 iyr:2011 hgt:190cm + +hcl:#a97842 pid:131728607 ecl:blu iyr:2014 hgt:176cm eyr:2020 +byr:1921 + +pid:11754457 +iyr:2018 +hgt:65cm eyr:2038 +ecl:dne hcl:z +cid:293 +byr:1940 + +eyr:2023 +iyr:2016 +byr:1930 +ecl:hzl +cid:212 +hcl:#733820 hgt:59in +pid:319501919 + +cid:278 +eyr:1967 hcl:#ceb3a1 pid:#9f5254 hgt:177in byr:1977 iyr:2030 + +hcl:#ceb3a1 byr:1998 hgt:72in cid:202 ecl:gry pid:463378493 iyr:2015 +eyr:2030 + +hcl:#7d3b0c hgt:164cm ecl:hzl byr:1960 eyr:2023 +iyr:2017 + +ecl:hzl hcl:#866857 byr:1986 iyr:2018 eyr:2027 hgt:176cm pid:928057092 + +pid:431113230 hgt:186cm eyr:2025 +iyr:2018 ecl:amb byr:1973 hcl:#623a2f + +hcl:#cfa07d hgt:179cm iyr:2017 pid:760075190 ecl:amb eyr:2030 + +hcl:#602927 +iyr:2012 +pid:571020910 ecl:#b6715d byr:1943 eyr:2028 +hgt:161cm + +hgt:176cm cid:121 pid:654127593 ecl:brn hcl:#160d38 iyr:2015 +eyr:2021 byr:1997 + +eyr:2021 byr:1929 +pid:192025713 +hcl:#c0946f iyr:2012 ecl:oth hgt:179cm + +eyr:2024 ecl:gry +hgt:158cm byr:1932 hcl:#ceb3a1 +iyr:2010 +pid:521188306 + +eyr:2028 ecl:brn +hcl:#efcc98 +hgt:157cm +iyr:2012 +pid:212547203 byr:1970 + +eyr:2029 pid:182693366 hcl:#623a2f hgt:130 byr:1972 +cid:310 +iyr:2010 ecl:amb + +byr:1944 iyr:2013 +ecl:brn cid:335 +hgt:163cm +eyr:2025 hcl:#7d3b0c pid:405230824 + +hcl:#ceb3a1 iyr:2015 pid:572001387 byr:1962 +ecl:amb hgt:151cm + +byr:1928 +eyr:2022 +iyr:2018 ecl:blu +hcl:#602927 pid:767081131 + +byr:1948 hgt:180in pid:188cm +ecl:hzl +eyr:2013 hcl:e0b9f3 iyr:1975 + +hcl:#c0946f byr:1989 +eyr:1980 hgt:67cm pid:538025041 +iyr:2014 ecl:gry + +eyr:2028 pid:958756919 hcl:#733820 byr:1945 cid:158 ecl:blu +hgt:168cm iyr:2018 + +cid:200 hcl:#fffffd +byr:2015 ecl:gry eyr:2031 hgt:59 pid:065027646 +iyr:1967 + +byr:1999 ecl:hzl pid:813536928 iyr:2015 cid:296 hcl:#6b5442 +eyr:2025 hgt:186cm + +byr:2000 iyr:2012 +hcl:#fffffd +cid:263 hgt:68in pid:105489529 +ecl:amb eyr:2024 + +eyr:2026 hcl:#602927 hgt:181cm +byr:1982 +pid:603871531 iyr:2018 ecl:blu + +cid:302 pid:387895477 eyr:2027 +hcl:#cfa07d hgt:191cm iyr:2015 +ecl:hzl byr:1940 + +iyr:2018 cid:165 +ecl:blu hgt:181cm byr:1994 eyr:2026 pid:077013268 + +eyr:2022 hgt:174in iyr:2010 byr:2023 +hcl:#733820 ecl:oth +pid:311692961 + +ecl:#10f2a9 pid:964417986 +eyr:2024 hcl:#0aeec7 byr:1965 iyr:1943 hgt:167cm + +hcl:#341e13 iyr:2020 +ecl:brn +hgt:188cm eyr:2021 byr:1952 +pid:077471062 + +byr:1950 cid:110 hgt:160cm eyr:2026 +hcl:#623a2f +iyr:2013 +pid:972823574 + +pid:553704996 hgt:171cm +eyr:2028 iyr:2017 +hcl:#18171d byr:1954 ecl:blu + +hgt:180cm ecl:brn eyr:2029 pid:707999496 hcl:#cfa07d byr:1960 + +pid:9325738036 iyr:1996 hgt:152in byr:2004 cid:292 hcl:14a56f +eyr:2031 +ecl:#dbd99d + +byr:1957 +eyr:2021 pid:557648216 ecl:amb hcl:#7d3b0c hgt:186cm +iyr:2020 + +hcl:#602927 hgt:186cm pid:604175608 +iyr:2013 eyr:2026 ecl:oth byr:1991 cid:65 + +ecl:gry +iyr:2012 hgt:154cm +pid:872898058 eyr:2030 hcl:#341e13 byr:1994 + +pid:228236326 +iyr:2013 cid:347 byr:1942 +eyr:2021 ecl:brn +hgt:165cm +hcl:#fffffd + +pid:392777182 cid:189 hcl:#cfa07d eyr:2027 hgt:191cm ecl:blu byr:1978 + +hgt:158in iyr:2028 +pid:5145408095 byr:2012 ecl:#94c57d hcl:z eyr:1996 + +byr:1949 eyr:2021 +ecl:#5ffbeb iyr:1948 pid:42650064 hcl:z hgt:167cm + +iyr:2013 ecl:xry cid:100 +hgt:138 byr:2013 +eyr:1944 hcl:92b68c + +hgt:187cm +ecl:grn hcl:#602927 +iyr:2010 +eyr:2022 byr:1949 cid:280 pid:251802347 + +ecl:grn +cid:219 +iyr:2018 hgt:165cm +pid:703878503 eyr:2024 hcl:#b6652a +byr:2002 + +hcl:#18171d cid:341 ecl:amb byr:1941 eyr:2021 iyr:1990 pid:865132177 hgt:153cm + +byr:2008 pid:861480549 +cid:97 eyr:2028 hcl:#efcc98 +iyr:2015 +hgt:191cm ecl:#232b23 + +hcl:#cfa07d +eyr:2030 iyr:2013 cid:304 +ecl:gry pid:199056608 hgt:192cm +byr:1926 + +pid:355135528 hgt:153cm byr:1998 iyr:2019 eyr:2027 +ecl:amb hcl:#18171d + +eyr:2028 hcl:8eed9c ecl:grn +iyr:2010 byr:2005 hgt:107 +pid:64892698 + +pid:601671623 hgt:153cm iyr:2011 hcl:#b6652a byr:1975 ecl:grn eyr:2029 + +ecl:grn hcl:#18171d hgt:157cm +eyr:2023 pid:507932715 byr:1920 iyr:2020 + +eyr:2022 byr:1933 hcl:#fffffd iyr:2016 hgt:181cm pid:826522507 ecl:blu + +byr:2002 hcl:#866857 hgt:177cm pid:240202426 +ecl:gry cid:127 +eyr:2022 +iyr:2014 + +byr:1971 +iyr:2017 +pid:733985576 hcl:#c58c6c hgt:178cm +ecl:blu +eyr:2023 + +ecl:blu iyr:2017 pid:558732458 hcl:#1b3ab5 eyr:2025 byr:1967 hgt:176cm + +eyr:2025 ecl:gry iyr:2020 byr:1988 +hcl:#733820 +hgt:189cm cid:151 pid:934827751 + +ecl:gry eyr:1951 +iyr:1932 +pid:309366394 byr:1945 hcl:#623a2f hgt:179cm + +pid:462345884 ecl:hzl +cid:206 eyr:2021 hcl:#733820 +byr:1982 hgt:180cm iyr:2010 + +iyr:2020 hgt:155cm hcl:#341e13 pid:110467532 cid:92 ecl:hzl byr:1975 eyr:2028 + +hcl:#18171d iyr:2010 +hgt:182cm byr:1930 +eyr:2024 +cid:226 + +byr:1956 hcl:fb0c6f pid:181cm eyr:2012 iyr:2020 +ecl:#d38822 +hgt:69cm + +ecl:gry iyr:2018 +hgt:169cm byr:1981 +pid:534824014 cid:287 eyr:2021 hcl:#c0946f + +eyr:2039 hcl:#328e90 iyr:2015 +hgt:170cm pid:#9fa2a4 byr:1999 +ecl:#cd1fd7 + +hgt:190cm hcl:#733820 +pid:302244363 +ecl:brn +byr:1965 iyr:2013 + +iyr:2012 +eyr:2021 +pid:579705743 +ecl:brn hgt:190in +byr:1954 hcl:#888785 + +eyr:2036 hgt:154cm +pid:800720865 byr:2023 ecl:oth iyr:2010 hcl:z + +pid:#92f6a9 iyr:2028 eyr:1943 +hgt:191cm ecl:hzl hcl:z byr:2018 + +hcl:#c0946f +pid:419930442 hgt:167cm +byr:1969 +eyr:2020 ecl:brn + +pid:137802946 +eyr:2020 byr:1947 ecl:grn hgt:192cm iyr:2016 hcl:#888785 + +ecl:#f66cce eyr:1958 iyr:1954 +pid:833131572 +hcl:z +cid:212 +hgt:109 byr:1924 + +hgt:179cm ecl:gry pid:065881341 byr:1985 +hcl:#fffffd cid:204 eyr:2026 + +hgt:167cm +iyr:2017 pid:898571403 byr:1929 +ecl:blu hcl:#d506d0 eyr:2028 cid:100 + +byr:1991 pid:2795214253 iyr:2011 +cid:152 eyr:2028 +hgt:170cm hcl:#a45065 ecl:lzr + +hgt:188cm eyr:2030 iyr:2010 +pid:297292695 byr:1955 hcl:#fffffd +ecl:blu + +hgt:170cm eyr:2029 pid:913242036 byr:1993 cid:89 hcl:#888785 +iyr:2010 +ecl:blu + +iyr:2028 eyr:2025 hgt:150in ecl:grn +byr:1995 +pid:974802728 +hcl:#cfa07d + +eyr:2021 byr:1989 +hcl:#18171d ecl:blu hgt:168cm +pid:626530259 +iyr:2020 + +hcl:#6b5442 hgt:158cm pid:798732187 byr:1922 eyr:2020 iyr:2011 ecl:gry + +hcl:#341e13 pid:092679330 byr:1997 ecl:oth hgt:159cm iyr:2010 eyr:2026 + +hgt:185cm +iyr:2020 byr:1947 +pid:105846744 ecl:gry cid:134 eyr:2027 + +pid:252016128 hcl:9016ff cid:158 hgt:161 ecl:gry +byr:1952 eyr:1955 iyr:2018 + +iyr:2020 hgt:154in byr:1958 +eyr:2029 ecl:#2feb89 pid:99780178 + +hcl:z +eyr:2001 ecl:gmt +byr:2022 hgt:73in iyr:2029 +pid:388744230 + +hgt:186cm +byr:1939 pid:622948608 ecl:oth eyr:2030 +hcl:#c0946f + +cid:272 +eyr:2025 byr:1979 ecl:brn hgt:180cm pid:456545466 +hcl:#fffffd iyr:2012 + +pid:946657041 byr:1999 +iyr:2014 hcl:#ceb3a1 hgt:150cm +ecl:grn + +byr:1957 pid:177cm ecl:blu eyr:2020 hcl:#cfa07d +iyr:2010 hgt:183cm + +pid:161cm eyr:2025 hcl:#b6652a +cid:213 +ecl:xry +hgt:150cm +iyr:2024 byr:2012 + +hcl:ea1960 +ecl:grn +pid:#7127b2 iyr:2012 eyr:2011 hgt:150 + +pid:178699291 +hgt:66in eyr:2027 +byr:1985 iyr:2014 ecl:amb + +iyr:2017 ecl:blu +eyr:2027 hgt:191cm byr:1990 hcl:#b6652a pid:074411798 + +pid:528782860 +hgt:181cm hcl:#c0946f byr:1965 iyr:2012 ecl:grn eyr:2020 + +pid:#ba10da hgt:176in byr:2006 +ecl:grt +iyr:2030 eyr:1949 hcl:d3ca76 + +hgt:66cm ecl:#898478 hcl:#e9f7a5 eyr:2030 iyr:2022 +byr:2025 +pid:159cm + +byr:1994 hcl:#ceb3a1 +pid:028071950 eyr:2022 ecl:gmt hgt:151in iyr:2016 + +byr:2001 iyr:2011 +ecl:brn +pid:487702556 hcl:#602927 +hgt:167cm eyr:2026 + +# The above line MUST be blank diff --git a/2020/04/puzzle-1.awk b/2020/04/puzzle-1.awk new file mode 100755 index 0000000..4c0c474 --- /dev/null +++ b/2020/04/puzzle-1.awk @@ -0,0 +1,30 @@ +#!/usr/bin/env -S awk -f + +length == 0 { + valid = 1 + for (i in fields) { + if (fields[i] == "") + valid = 0 + } + + if (valid) + count++ + + fields["byr"] = "" + fields["iyr"] = "" + fields["eyr"] = "" + fields["hgt"] = "" + fields["hcl"] = "" + fields["ecl"] = "" + fields["pid"] = "" +} + +{ + for (i = 1; i <= NF; i++) { + split($i, data, ":") + fields[data[1]] = data[2] + } +} + +# Why do I need to subtract one? This code is so old I can't remember +END { print count - 1 } diff --git a/2020/04/puzzle-2.awk b/2020/04/puzzle-2.awk new file mode 100755 index 0000000..bb88145 --- /dev/null +++ b/2020/04/puzzle-2.awk @@ -0,0 +1,67 @@ +#!/usr/bin/env -S awk -f + +function between(x, l, h) +{ + return (x >= l) && (x <= h) +} + +BEGIN { + eyecolor[1] = "amb" + eyecolor[2] = "blu" + eyecolor[3] = "brn" + eyecolor[4] = "gry" + eyecolor[5] = "grn" + eyecolor[6] = "hzl" + eyecolor[7] = "oth" +} + +length == 0 { + valid = 1 + + if (!(between(fields["byr"], 1920, 2002) && between(fields["iyr"], 2010, 2020) && + between(fields["eyr"], 2020, 2030) && length(fields["pid"]) == 9)) + valid = 0 + else { + # Test eyecolor + valid = 0 + for (i in eyecolor) { + if (fields["ecl"] == eyecolor[i]) { + valid = 1 + break + } + } + + # Test height + split(fields["hgt"], height, "[^0-9]") + if ((fields["hgt"] ~ "cm" && !between(height[1], 150, 193)) || + (fields["hgt"] ~ "in" && !between(height[1], 59, 76)) || + (fields["hgt"] !~ "cm|in")) + valid = 0 + + # Test haircolor + if (fields["hcl"] !~ "^#[0-9a-f]{6}") + valid = 0 + } + + if (valid == 1) + count++ + + fields["byr"] = "" + fields["iyr"] = "" + fields["eyr"] = "" + fields["hgt"] = "" + fields["hcl"] = "" + fields["ecl"] = "" + fields["pid"] = "" + next +} + +# Non-blank lines +{ + for (i = 1; i <= NF; i++) { + split($i, data, ":") + fields[data[1]] = data[2] + } +} + +END { print count } diff --git a/2020/05/.gitignore b/2020/05/.gitignore new file mode 100644 index 0000000..e2451f9 --- /dev/null +++ b/2020/05/.gitignore @@ -0,0 +1 @@ +seatids diff --git a/2020/05/Makefile b/2020/05/Makefile new file mode 100644 index 0000000..48f7dd4 --- /dev/null +++ b/2020/05/Makefile @@ -0,0 +1,6 @@ +all: + ${CC} ${CFLAGS} -o seatids seatids.c + +.PHONY: clean +clean: + rm -f seatids diff --git a/2020/05/input b/2020/05/input new file mode 100644 index 0000000..e3bc909 --- /dev/null +++ b/2020/05/input @@ -0,0 +1,908 @@ +FBBFBBBRLL +FBBFFBFLLL +BFFFFFFLRL +FBFBFFFLRR +BBBFBFBRLL +BFBBFFBRLL +BBFFFFBRLL +BFBFBBBLRR +FFBBFBFLLR +FBBBBFBRRR +FFBFBBFRLR +FBBFFFFRRR +BFBFFBFRRL +FFFBBFFLLL +FFFFBBFLLL +FFBFFBBRLL +FBBBBBFLRR +FFFBFFFLRR +FBBBBBFRLR +BFFBFFBLRL +FBBFBFBRRL +FBFBFBFRRR +FBBBFBFLRR +FFBBFBFRRL +FFBFFBFLRL +BFBFBFBLRR +BBFBBBFRRL +BFBFBBFRLL +FBBFBFBLLR +BFFFBFFLRR +FBBBFFFRLR +FBBFFFFLLL +BFFFBBBLRL +BFBBBFBRLR +BFBBFFFLRL +FFFBFFFRRR +BBFFBFFRLL +FFBFBBFRRR +BBBFFBBLLL +FFBBBFFRRR +BFFBFBBRLR +BBFBBFFRLR +FFBFBBFLRL +BFBBFBBLLL +FBBFBFBLLL +FBBFBBFLRL +BFBFBBBRLR +FFBFFFFLRL +FBBFFFFRLR +BFBBBFBRLL +FFFBBBBLLR +BFFFBFFLLL +BFFBFFFRRR +FBFFFFBRLL +BFBFFFBRLR +FFBBFFFLRL +FFBFBFBLLL +FBFBBFBRLR +BBBFFFFLLR +BBFFBBBRLR +FFBFBFBLRR +BFBBFBFLLL +FFBFFBBLLR +FBBFFBBLLL +BFBFBFFRRR +BBFBBBFRLL +BFBFFBFLRR +BBBFFFFRLR +BFFBFBFLRR +FFFBFFFRLR +FFBBFFBLRL +FFBFFBBLRL +FFBBBBFLLL +FBBBFBBLRR +FFBFBFFRRR +BFFBFBFRRL +FFBBBFFLLL +BFFBBFFLLL +BFBFFFBLRR +FFBBBBFRRR +BBFFBBFRLR +FFFBBFFLRL +BFFBBFFRRL +FFFBBBFLLL +FBBFFBBLRR +BFFFBFFLLR +BBFBFB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FBFBLLL +BFBFFBFLLR +BFFBBFBLLL +FBBBBBBRRR +FBBFFFBRRL +BFFFBBBRRL +BBFBBBBRRR +BBFFFBFRRL +BBFBFFFLLR +BFFFBFFRRR +BFBFBBBLLL +BBFFFBFRRR +BBFFBFBRLR +FBFBFBBLRL +BFBBFFBLRR +BBFBFFBRLL +BFFBBBBRLR +FBBFBBFRLR +FFBFBBBLLR +BFBFFBBRRR +FBBBFFFLRL +BBBFFFFLRL +BFBBBBFRLR +BFFFBFBRRL +FBFFFFFRRL +BBFFFFFRRL +FBFFBBFLRL +FBBFBBBRRR +BFBBBBBRLR +BBFFBFFRLR +FBBFFBBRRR +BBBFFFBLLL +FFBBBFFRLL +BBFFFBBRLR +FFBBBBFLLR +FFBBBFBRLL +BFFFBBBLRR +FFFBBBBLRR +FFBFBBBRRR +FFBFBBBRRL +BBFBBBFLRR +FBBFBBBLRR +FBFBFFBRLR +FBFFBBFRLL +BBFFFBFLRL +FBBFBFBRLR +BFBBBBFLLL +FBBFBBFLRR +FBFFFBBRRL +BBFFBFFLRL +BFFBBBFRRR +BFFBBFBLRR +FBFFFBBLLR +BFFFBFBRLL +FFBFBFBRLL +BBFBBFBRLL +BFFBFFBRRL +FFFFBBFLLR +BFBFBBBRLL +FFFFBBBRRR +FFBBBFBRRL +BFFBFBBRRL +BFBFBFBLLL +FFBFFFBRLR +FFBBFBFRLR +FBBBFFBLRR +BBFFBFFRRR +BFFFBFFLRL +BFBBFBFLLR +BBFBFFBLRL +FBBBFBBLLL +FFBBBBBRLR +BFBBFBBRLR +FBBBBFBRLL +FFBBBBFLRR +BFFFFFBLRL +BBFBFBBRRR
\ No newline at end of file diff --git a/2020/05/puzzle-1.awk b/2020/05/puzzle-1.awk new file mode 100644 index 0000000..831c127 --- /dev/null +++ b/2020/05/puzzle-1.awk @@ -0,0 +1,2 @@ +$0 > max { max = $0 } +END { print max } diff --git a/2020/05/puzzle-2.awk b/2020/05/puzzle-2.awk new file mode 100644 index 0000000..8b9b823 --- /dev/null +++ b/2020/05/puzzle-2.awk @@ -0,0 +1,11 @@ +{ ids[NR] = $0 } + +END { + n = asort(ids) + for (i = 1; i <= n; i++) { + if ((i + 35) != ids[i]) { + print i + 35 + exit + } + } +} diff --git a/2020/05/puzzles.sh b/2020/05/puzzles.sh new file mode 100755 index 0000000..2066d76 --- /dev/null +++ b/2020/05/puzzles.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +./seatids | awk -f puzzle-1.awk +./seatids | gawk -f puzzle-2.awk diff --git a/2020/05/seatids.c b/2020/05/seatids.c new file mode 100644 index 0000000..9c3b797 --- /dev/null +++ b/2020/05/seatids.c @@ -0,0 +1,37 @@ +#include <math.h> +#include <stdio.h> + +/* Parse the input file `input` and print out all of the seat IDs which can be piped into both awk + * scripts + */ +int +main(void) +{ + FILE *fpt = fopen("input", "r"); + /* +2 for \n and \0 */ + char bpass[12]; + while (fgets(bpass, 12, fpt) != NULL) { + int lower_r = 0; + int upper_r = 127; + for (int i = 0; i < 7; i++) { + if (bpass[i] == 'F') + upper_r = (upper_r + lower_r) / 2; + else + lower_r = round((upper_r + lower_r) / 2); + } + + int lower_c = 0; + int upper_c = 7; + for (int i = 7; i < 10; i++) { + if (bpass[i] == 'L') + upper_c = (upper_c + lower_c) / 2; + else + lower_c = round((upper_c + lower_c) / 2); + } + + int seat_id = upper_r * 8 + upper_c; + printf("%d\n", seat_id); + } + + return 0; +} diff --git a/2020/06/input b/2020/06/input new file mode 100644 index 0000000..7153597 --- /dev/null +++ b/2020/06/input @@ -0,0 +1,2167 @@ +adgvrhblps +pghsdrbmalv +hrlbpdasgv +bgvsdplahr + +lgnpfhrm +hwmng +gunhmo + +txkeafsbgjuizd +etmcgdbfajuz + +xdtzjioqavmchsbfrkp +bzjkriqmvxedotpcf +azjckxmqovtidbprf +fcxmevrkojzpdibqt +roifztvxmbpwcndkjq + +ylcixrdoejn +dyoejlrcxin +dnorleijxyc + +u +u + +nfjrt +hvgqxculeszok +pmwryfdiab + +gh +ebzkr +byqusikr + +b +b +alyr +t + +jzbafspmynwgqdeuklxc +anbkgduyexjlzmpcfwq +zxdkiujqeglcfynwpamb +qwcubamjpxyngkdlzfe +upadgfkywmnxeqbhjzcl + +g +l +g +g +pg + +mazi +mnzdai +zmia +izma + +pqzl +pzql +zvciplq +szpqrl +plczqi + +mquiosghkwtjz +tgnewskmjuozqi +gjwzmqcntosuik +ybtjoqzuwmfgisk + +nvwocedxyqiahgt +zbjvipyfeacuwrt + +ojkhxmwqs +kqxhmrzjwo +mqkjxhwo + +t +t +t +t + +dhrxaqejfng +fhdlbxejqra +fqaeldhjrx +seaqjxzdfthr +adjhrqlxef + +t +bczrx +ueit +nu + +idtmkhnlpbsqfxcevjry +pricynubfvdhjqesmktlx + +wt +nw +w + +mhqe +ey +e + +kwclmuovtihabd +aqheucldfwno +adwnhoclqugez + +lbwnohgs +osnbghw +swogbhfn +hnbosgw +gsowhnb + +jsxyihpaotdlvckgeznqfbmwr +xkhfnwitojasqyrgcelpmbvd +synvibmdpfxwqltgcjohkare +grxicqelsovtdfhujwkanypmb + +druazhicbm +spqizhucrdabmv +imucbayhgzdr + +fnx +unqx + +zjm +qfwrycva + +uktvygcmf +yfktcxmv +ctlkvqysfmb + +j +jng +j +j + +t +tw +t +t + +vogs +ogsv + +tzgqxfauw +wgfxqkuaz +dkzawuftgq +gbuwaqzfjo + +iphexunlbs +tayqgzmkjfdcrvow + +fcdplxkhjbngwzqmiry +khuyrlgvxnpfbdmosqizjc +djzyxikqnmbrlgfhcp +jxycgeidnhlkzqpbmrf +xckrhgbzfnjlpdmiyq + +lezco +ezloc +zolec +ocelz +oeczl + +emgluf +flebmhg + +knafibd +kbrnfd + +xktmidfrz +fajlidmrtzy +wftzdm +omeqbfgdzpnut + +tndpxaveifhcmzyjrsqlub +oyanuslpqdcevfih + +hblawudzknspf +gxnstrmiyqpejo + +lesyaikhnvoguwftzrmqdcpx +pxuqoayiwjzvglstrhfkmcend +uvyfepmxokdrhzlcsniagtwq +ynfmkwxqalpdrezhoguvstic + +grscfn +azlgdcn +ovcgzn +lwxgctan +mgkbiyjhpnc + +ji +ji +iaj + +ivtkp +ikwp +ipko +pkiw + +p +p + +yushxnqa +uokzcaxni +xalvuyn + +elw +wle +wlre +wleq +uwel + +bvfxe +ebvfx + +roaygfv +udazcljhy +pbaryv +aptxy + +zdpkslmvnhyfua +czhfkylumrvgoqaspb +twenpsyzkjmihavuflx + +zsv +bnzjfcamkw +rvdzq +ltypirz + +q +w +q +q +q + +uic +uic +uic +iufc + +rdve +cvzre +fqls + +gxmnabhd +xdbwjngmra +gmxebadny +bgahdxomn + +gnoyc +olgy +poyfjg +wsdouiyghqe +jyog + +q +e + +adszvgclfomph +qavsicdlghozpfm + +czfhs +hzfo +zhf + +luzrpeivwagyfktjhnob +tlwynevkojgpbfuihr +gklbpjvyoituefrwhn +vhypwujfrbktonedigl +byknejlowfrptghivu + +xbu +xbu +xub +bux +xub + +vcqtxyf +tqcvfy + +vumkixjhaozgfbneydpr +yxeazjmvbnhukpigodfr +pjnomhaxuvdkbiryzfge +oezrxngvpajfkdmuyibh + +mkgdruoiawfh +dsumegkpjoq + +oucrtxbqienfvsmlzjkdwgpa +akrqisvxbudelwgpmnozcj +xreauzqglpcvmoidbskwjn +mwgpljcusakrbozxvndeqyi +jdrlvcimoewkpxgqasnuzb + +dshfqywgbc +eiqflapjh +vrmjfhnq + +kojresxi +ubclnpghf + +kuitbfh +ofdkqt +fztk + +lsawunycojgvi +ornsyijx +yojpdsnbxri +tjysrinoe + +ezuqslamgi +alimgeuqz +amgfqzluiew +nmalugivwqze + +lrm +mr +vmrgt +mr +mlr + +ybcnizhwt +ycbmztih +octgiqsyhxz +hktzcfyilew + +mqigxepzwudokytanf +ayztcxbigunordqlmhk + +wnfy +wzfp +fjlewksb +pcfwyn + +o +c +na +qku + +zg +gtl + +syr +pbnmqc +j +sk + +abenmqvsyotzrcjwglfdx +cnmqrxatjvowbylfgdezs + +kfzlgphuwqv +levuhkwqcpfg + +iazxrty +xryz + +ikxcpebaruwhlm +iqtxadbeyckuvsh + +wkfsrvgbyjxpq +rqbyxwfpkjgsv +fgwsyjqkxovrbp +frpyqxbjvwsgk + +po +o + +arbnupkvxqodcg +znpobhraxugvdckqt +mkaupgobdvscnqrjx +cbqknjavpgwxuord + +ftpka +vtifcl +dfwusmbyrhto + +y +q + +drsleaqghypbtinmfuo +gzinmrwudjbpyloefqahs +fiomngyurlpheqdabs + +v +bx +c +v + +kh +zk + +qkzicvjbgawfdpxmtsloye +ylofxwpvkqemsaigzjtcdb + +qf +fq +raf + +cbvxjytmsa +tbmxcvyjsa +ybmstxjacv + +aekpuyliz +eqpyxls +rwyepchjflomg +oedybpl +evnyclxqp + +yxtfnavdhopmcw +qlugbvjcz +xvcnymkrh + +yksamve +yksmvxea +mskavye +yamdswevk +eksayvmx + +p +k + +psrgzxmaif +ifraxgzo + +aehoplsvfqr +jfqvkpoas +vsjfxpqcoma +asmfoqpv +uvospqaxf + +ercgdyism +msrvebzc +mgrescq +desfrmico + +dborguxznkyqciavtfs +kzoymfndrsaihqtcbvgxu +anbcwfrdgjxktlyivouzsq +bgifuzsrekocxydqtnva +dtpsikyavoucxqgbhfznr + +jvyhfbpxtkizmlesw +fvmjhkesbpzywixtl +btlezmshjwpxiyfvk + +jawdspkghblyvornxmicuq +nrujdhxokcwgylimvqpba +lcrnhktgvipyubwqdomjax + +vhiatyrwksodemcxn +hdsamtvuikjqecnwryox + +ixthorcaevkp +xiyhrknlboczwjfm + +ck +kc +czkmyet +kc + +wxjqkpgnshue +qojwkefphzcrgaxn +ektphqjxgnwu + +raksq +mdu +a +asb + +putzomyciwaqkvbfsldng +absdvyntgikruqpzoflcmw +dkscznaiwulvogqfybmjpt + +sxbqjv +jqvxbs +vlqsxjbo +xsbqjv +jvqxbsy + +ynbakgvc +yvtnlbsjg +vrqxephwfby + +xhdjkrpltfoe +qjplehkotdbfrx +kxfdaotsperlhj + +ewgsmi +jafkti +yqkf +copzldurbx + +xc +ex +r +rtwce +slk + +zimewg +nmzrj + +qylbm +byqml +lqmyb +mxyqlbr + +egsktr +erskdgt +rkesgt + +zkgqireysupwjthdb +swkoyzdcqibpvnr +kyvmwzpirdqsfbclx + +jvytcgmkeqalzonhx +kvcjnwztxdmlyoaqg +lznqaxcvjytogkm +vabgfulyxkjoimqztcn + +q +q +q +fh +q + +xykitfhn +xnhytzilf +tiznfhx +tfxihnre +xhilzytfn + +zmxyoakgt +yawiomrgsd +oafgmyqr + +lpgqshiyuxjvabz +lzbuhyiqsjagepx +urisxlzjabpyqgh +xsuiqljypzgabh +gkylpamihsotqfdxzcbjwu + +jhf +htdejm +jtabh +cjeigmzh +suljqyorxh + +hcjkbvmlaoen +faojknvxmehblyc +nhmovlejcbka +vonhckilembja +kojnmvebtclha + +clamzrewgonksuqvpb +zusorlkmqpnvwaecgb + +uka +ea +aw +a +lxa + +lg +lwtg +tgl +glw +rlg + +vfsxidctgah +dvhcftsxgia +vdhxgimfsant + +tschpyqa + +ckn +xckznb +mnsvlfqaitjpdk +cwkzn +kzoyenb + +ro +ro +or +or +oer + +icumvltoqafdy +tfsxarpnh +atsfgw + +btfenmovgusqzijxpcrhdakl +diapqfxrnevlzutsycjgbkom + +utvbhgw +vbhgtwu + +nkfgajmvbpyowthxr +cwxrtknpmgfazjoy +rwxmfatgouckjypnd + +kdlubgiap +podcivgyueafkhm +purgnkixazd +sukdgixap +udkpglia + +ajnumbsgr +ibmjsrkagc +bsgozmra + +vkbso +ykglhto +gmodikp + +sxupqv +xvuqps + +x +r +c +x + +fjoyuhztseqrawpciglx +igfeplsxtrhaqyzojwuc +rpwgucisoyhflaxtzejq +yqzjphegfuxltawicsor +wzahifloypuxegjscqtr + +xeironzdugvqc +quevgsfronxzc + +wdjrsknlbihcqzxuv +bzlxjnukvhrsdicwq +cuqiwsxkzvjbrndhl +ubclivhszjdwqrnxk +jldqkihxrzuvsnbwc + +dzklrogfvmn +xuwpaqcetij + +d +o +m +d + +xhgzbj +jvbhg + +snbcamefqhuovxkjpz +htckmpybdgvrsaoeuj +pkcbewsgvojmhauidl + +i +k +tqj + +koyawh +auo +qaoer +zrapo +ioa + +broqhaylgsmxzkjtuvf +hatgluorzvkyxsmfjb +whytbkrvsumgzxoalfij +tzabxgfrqnusomvhjykl + +hoplnck +ayqxdjofr + +dmjspac +dhoazjp +idxfrwepyjo +qlpjgtvndub + +riabvstyxphgoez +projxgyhietsavz + +jhfqikpmz +kfpiyjvmzsqh +vphkqizjmsf +wpqfmlzkjheid + +diap +zkhacy +waog +fojgas +roa + +rujzxoygliqnmvkpc +vlonrgpjqzyxmfkic +zgxqkjocirpvlynm + +lzgja +jlza +kjazrcl + +vteiqrpkjybsmndhfl +lsndjpqertkvhbimyf +lpjmnbyqshvtdfirek +vpibqrehmsnflykjdt + +iwqlhotpjsa +slhjyuiotrdk +szjhlocimt +tiajhwsofl + +poz +dp + +yeqdmto +zgtqyvoli + +ahkfsocmdgnwp +cpwhjsmgodakf +clhudwakftvogsepi +dkargcowsphf + +p +p +p + +eqbcr +jceq +xeocqmi +fqwcve +mjebocq + +xkei +ivuaexqk +kxie +ikxe +kxei + +jsmzk +cmdpyf +xshm + +hdwlcgzyuvke +gjlaqpry +rlgomxy + +comszwhfrqlpnvytei +iqpvwolsmnfhray +oulphgswymvfrqnix + +lcisfxnzwy +csixywfbnlz +zelcfyiwsxn + +lmrsia +gowals + +lyknfogpu +zoiw +tesjova +moes +odi + +ktfajxloz +ojaxzflk +akzlfoxj +fxkolazj + +iwxzmukbhoy +xlzkymbiuwo +bkuzomwxtiqyd +wmokbizxyul + +kr +kr +skr +kr +rk + +bdpfgnwxtk +gwtkdflnjpzx +kngxpfwdt + +xkhmzvylowsgucrfepjai +xriqvhjlozpdkuemcfa + +avxoebdgzmqphfytcn +cvfrmneolxtyzdgpqh + +wjvslhmufgqxcnodz +fswclgdvxnumo + +t +uqi + +xopmekybt +pkrxytebm +mtpxbyek + +vkxcrizwuhtad +wairuvhdmzcxkt + +vrlpifawedksqzhcgnybtjxo +qoplwufekztbhdnvxgarjsciy +svzmteygfbkrlxohjqcpaidwn +rakocwstbpidlhxjgeqzfnuvy + +o +o +o +o + +ihzarybenqmtpg +zqbiyhanpgetrm +hqizynrpbagetm +yhbgrzeqnipatm +gteahmprbyqinz + +jv +uxkasvt +jrgv +qv +ivbpld + +sxigewcouvbj +xjwobcsugive +cbjvxsuowneig +uxobwigsjcev +ejogiwbxvcus + +enmvubp +pvubm + +qrjythvlzubgeikafo +necadbmrtzulvwypx + +rbuslgk +lgsbuzkr +lbkugrs +sgkbulr +rublgks + +whb +wbh +whb +bwh +whb + +khtcw +wkcth +wtkch +ckwth +kwhtc + +mkzdbo +dkjz +kbnzlmd +duytksvzgq + +brkxvtjpdhqw +ntjqizashkpvwd +dqfrptwkshmvzj +phegdjolwvkqtu +dkhnwqacjpmtvf + +bdrioxsqahp +adishrbqoxp +oiqpsbdtyrha +dapobrxsqih + +oqsgiptmzlwcxkhvrfedu +rpwhtlgkcuidvqfosazxjem +rmgkeisxzhqwopltcfvud +vfcxiruwlhgoszmekqdpt +hmprfdvoxetulgizsqwkc + +luzam +mwuplz +mlurjz + +xlpmhzudwriytscobnkfq +uinamwhrtpobfvqceyd +ibflutdsohnqrpcymw +nqprtwuyfdcmiohb +ufhwmrinodkcbtpjyq + +ns +ns +sn +sn + +dufzbegpjrsaiqcthv +pfzqdjhatbuvescrkig +tbehcpfsvagdqirjuk +tebiravqjpfushwgcdx + +gpjafzel +mzgftlead +bleynhgvfcs +egdqfalmz + +zbarcdwiukgoqhmtnyjps +sujqytgrbnwzdmhalicok + +fyvgdcbqx +fqcgdyin +etfmoqgdsjyc +gqfcdy +fyqcngd + +am +bjm +sdm + +frvkaupe +qzipevkya +vzabpkesd +bevpymka +pkxeva + +t +t + +dcveyjgtfkbuo +ebogjfydkvcut +gkoyfeudtcvjb +mvygqckjftuodbe +tujbkeocdgvyf + +bkthnlgp +tnghb +gthnb +gnhbt + +hpkybmeowacsrgnijfl +jzrsgyuwickpfbmolneh +hcflvrgqpwmdoknsjeyib + +qxincam +zdjrlksqhgt +cbafqwo +vqyei + +izdkxrpuqgjte +asyngkxrudpvmie +bdkwpgmexruci +opdiknuxger +gecixdrpluok + +jymuwvfrixclhga +invyhuglxmcjw +imwghculxvjny +gjmlhiwvyctux +yvjhixugwolnmc + +xbcwhv +chdwgxbv + +ujycfnsvgqkpwheal +erugwaykpqcnhomlf + +gyk +glhrk +gwk +qowygk + +vcnju +vuoijbczt +dvcujg + +rlsy +ryls +ylsr + +tjn +t +n +rixz +t + +i +i +i + +elq +qle + +ksahwvdjbtfle +lfksaebjhtwdv + +qfacst +qfaskg +fqasoktb +vmfuilqzprasd + +apuxh +uxpah +onahmwupxb +hxpqau +huqapsx + +hjbnwua +huwbranj + +dj +z +h +hz + +hzqo +oqz +uwsozq +zyqxo + +ckotpfx +lhrcnpmgfviwobd + +wecahmszdjnoix +hmxaijswzydtcgn +njcqtmzixsadlh +cudmxzeasjnh +mxzahjckbnpdvrs + +lsqahvixforkw +fxiqskaohw +afjhnxqowsik +xstiqkhmoafpbw + +htdcbm +ex +sxq + +pfgkrjhub +nptjfixgraubykhld +pmufkbrhjvg +jhrfbgpvuk + +sptnugvdfmckehw +wknfhmsucertpvg + +zolicbnrvtdwhy +oqdunzywp +zodykuwxgspn +wsanojdzxqy + +druisbhpckvwofna +wvcboafsnhipukd +bpsadlcvnkhfziuo +bqfujsvmhcoakitdpne +visaodpfuchkngb + +ewniqoulvgstzchkxdmpyajrbf +cbyihmnuradvlktxpjwsogzfeq + +zgsdqwj +qdzsg + +ombl +yeulqbnimw +hljodbmk + +wtzkorqhupxby +yzxhtkwpord +skwzpjtgyrxho + +mstgrlwo +rpyowgdts + +pidn +ipesrfv +owpdim +pibt + +tu +tu + +pcdatkohjgbelmqvfxwnu +ukevynsprjtclaxhgmdqfwb +twqungiobxflhckapedjvm +pgqvtowflujnmadbeckxh +damfntwkjlcvhbqepxgu + +ilksfovqamrhngcdjyexbt +htkvnbrqaefsloxgciymjd +qfgvrxmbaoeldnkyiswjhtc +ftxpoyhbjkcevdasmigrlqn + +oq +qdo +sdlqoa +eopbizq +sndqo + +iblpgzoekrnmwhjstay +tsropbkwgyaexilujn +salrwjgbtikpeyon +bsyirktpjonxualewg +teaqljpowyrigbknsd + +d +d +d +d + +zgqmhnlvekcyutxsbifw +zmkqgwvyjrcdfbu +ckoawvyzgumrfbqd +fdqbypumcgwvzk + +krqlncwuxvgbdpsmyjfa +lmuybxdqsvkrjfcpwnga +zkbqnhjspdcumrxgaelyfwv + +vafsedqzyrtnjpwug +gvcustypjedaw +owpydujgtaivsmke +tvadlgweiypsju +jebvtoysphugadw + +pyixcohfrvtenaugsdmjq +catjqrivdfseogunymx +tvquyscedoxrgifjman +qagtfiocrjmuvdsenyx +gmeufoqaxcrnjdvstyi + +p +p +p + +jagycukemiqdxw +cmuyadqgkewixjl +fqawimgzjkyuxbdec + +mahdekwibs +admswkhei +debamswk +maovdyeskw +mbsdkweaf + +wfqimrc +rtqhcwlgdxnkvpo +arwysquc + +kroumefnixa +lcn + +hvaugnsf +nfxqkugas + +wheyqtmdvljucnsbia +hvmyteblnuqacw +ehnultwbyacmqv +mlybuhqtcewvna + +pxhafcvymglkzoq +xhwkctlgabz + +or +jodr +or +gro +forha + +fzmohqld +szqf +iqawckfrp + +hkxuwmsbdrpt +ptysjhxkwbmru +tpmbsrkgwh +kphmtrusvwbq +krmhpftsbwzn + +r +r +otr +r +r + +sxtlkvjacpbngoziewq +jiskzqanlowbxpvtge + +r +r +r +r +r + +bqwsz +wsfb + +zwvyqaichxjre +whvayjrzicxqe +arxcivhewqyzj + +mpzasbnregjdwlxuqoft +dnxlrwubzkaosypq + +gfaizbqlchy +zibatqykfu +bsufzjqxyiam + +fsy +sf +efs +fs +fs + +asmugcxhbekl +dkhcluwsmegaxb +kubhcmalegsx +cgluxmbhekas +bajrhelscgumknx + +qdpwfec +wjdqfecy +cwdefqj +wqvdclsfe +dcqpfew + +r +jcowmyplv +itdru +shbfr + +soublfhe +lksfzjdymaw +ywfnrskcl + +zsybelirjfwm +sfxiznhmablgtj +jbcifusqlopmdz +znhjerlkfmybis + +knvmejaydo +mjoaevkw +jkmhcoave +agomevkyj +elqftajmoskvi + +ziajfk +zakifj +kazfij +zfajki +fziajk + +ujzyfat +tyuafjz + +xihdrjyzvl +axujhtldyr +xdohklyjr +xrlejhyd +bxolyrfkjdh + +i +i +i +i + +ocnxzlprutqmhsij +xgmloizutqj +xmtlgioujqz +guoxlamzitjq + +jhoepxcuwvn +xeuvnfaodjwpc +upjoxwcevn +xncelrvojupwg +qeusjvwynkpotxc + +etdilxy +lytdiex +hdeltgryiw +lyixvedt + +rge +gr +grp +gr +grp + +iquzsnh +qsfunwh +qtsgprvhcn + +lipmbftsh +myho +uqzngarkvw + +ybrtackvdgqsmonlezuw +ywlzmsgbtocakedrqnv +rbceqauytzgmowkldvns +tyncgkldqserbjoavwmzh +oydsvatnmwzgceqkrlbx + +qjb +irgfqjope +jkq +jqb + +ncjlbpzedywkshfmqvagxi +jfipaqbmevkgdxnschztl +gbvxnclahmsiqjdekzfp +kedsxbzcvijglphmqfna +szcadkbnpeghjvqifxml + +nfteow +ytewforn +estonfuw +erwtnfo + +vhawcorfpxydzieqmbg +opyqhzdabfwcegrximv +vbpfqzcierhdgawoxmy +dvprwqzfioagxbycehm +yhdvpxzimqeorcabgwf + +bfnrkixsut +jhywbrncziaxkp +iodknxrb +xbrknli +xkfironbu + +xwpqbhyakf +rxayi +ogaxy + +tnwl +wbnl +lhwn + +wjuroesafgizkmvplxc +nxvgfoeucjmprikwlsy +glwrfcumhejisvkpox +kjmuvrwclifaxepogs + +kjxygrvsodimabecwuzh +ihmxrogvjsaudbkwcezy +ykwovzjimbgashrudxec +jsewruvymigxdzkohabc +icmleouvhyzxdabjsgkwr + +wm +wm +miwkg + +slcdjyhbnpi +bxqvejnzwtfag + +a +a +a +a +a + +jxwonlf +jox + +wxhytgp +tpgywx +pgwyuxt +pgxyfwta +dpyzwxrg + +uygwfkxvane +hsdicwzkrenfgalqx +jaknwfxge + +mxs +msk +smx +msoqz +ms + +bxfwc +wcbxf +cxfbw +wkcbxf +cfwxbl + +om +om +a +n + +ikp +wi +iu +biej +i + +aokgqimrnlfbdxzjs +tmqxrbislngykoajd +lsgvboxnkjdqrima +orijsalbqnmdkgx + +zfpd +biok +bxcqnk +yikx + +sulwztbnqkvioafxchemr +qhmcvlexkazuinfrwbsto +mnfutiblxecdqwvkoszhar +bmxzpqrlkafheouvcsntwi +zmchneutwlqoakxbsifrv + +equacsmywgpkixfdv +anxwlcuypskjgfivbqr +iyaksgxmvoufehwpqc + +twfzqxsnr +aqdsp + +yj +dyoje +yj +yhqj +jy + +bhwsczaxunjr +xgcswaflpznruqb +ubzwjxkcsyrnmahd + +xyvgkjo +kgjvoyx +vxyokjg +govjkxy +jgyxokv + +hneolzrtywq +atbs +mtipgd +vts + +flu +lfu +ufcl + +ad +da +da +ad +tgqad + +xfw +bufw + +simdubgowtap +wgbsdomaiutp +bsmodwauigtp + +qi +o + +n +dthokli +nveq + +nvdt +cdglvi + +sdxfaveuwlqzgircnhyobtkjp +uiqjrdenyagwkzhvpxscobtfl +otiungzxecdbyksrfwqjhvlap +dtbcyojehfwvsnrpkliuzgaxq + +zgovqbryphxmjcasuktfl +bwcpqoutvfjykmashrzlgx +iecjhpmxsqytzorflungvabk +vacztqslhmkgoxyrpufdbj +amgfxjqsptdrhovclkzuby + +s +s +fs +s + +b +b +bm +b + +uzc +zbc +cz + +clmeswqpuahi +spahequmlwci + +hrclmu +nhlcdurfxzi +orshcluv +uheclr + +r +k +r + +da +ad +ad + +hlfmnga +amhgn +hgamn +geahwnm +malgnuh + +bhpgndjwecroq +iwxklmtyzsopf + +uqosfv +lmbihrxtedk + +gyrtdosqjnkalicmwvh +rmlygiwktqcoshdavnj +wimjknqvaglhdsocrty +wkosyadhtqgnmcrvijl + +tcpsjerzykogwmqbxinlad +iyzxcgrtqosnbkjaleudmw + +dyzsmnkvuegbwlt +iwrcgs +fpswgqc + +nawtjrgmpyxlibcshfudvkzq +jiblrgwyhtmxvucqz + +vcruatwneqxi +myhgldscjnfb + +qakljbptgwryiuxnmoh +mtquwoagbjknxyrlpih +aktuhpgmqxbwjyonril +wqriogjmubxpknvyltha +mpkuhlxgjtanwoiyrqb + +ptjrmc +ucfjpm +pjcsm + +jofrkgdves +gsdkrivfe +dgsevqkxrf + +fvs +vclsd +s +rehtuyi +vfk + +eafupodb +eyrdpgbujfoa +ukadqobefiwxp +pfgudeobay + +i +p +i +i +i + +udlqpozmayew +dsyalxmupwe +lipydaumwe +delyumpwsa + +zthwnjiuyosakfpxbclm +lcpyfmisbztuknaxo +xsnlcyfzbpokmatui +zblkpsficaxmyoutn + +n +nt +r + +meskuctxrwaflovdpzhj +koxzmhvrcydlbwpsjuae + +l +pqd +lh +f +h + +otzqusgdeyvc +aetugnycqrxz +fhzwtgjqmkyulip + +o +o +o +o +o + +frejdvqokushlxtcgwani +dmfesnxhwgluorjiayt +zdtispaxeobgjhunwfrl + +retxhvnmzsjqpbodif +txnphyomczqfisedrjb + +nmwra +rmvawn +arnwm +mnrwa +wnmra + +yatwdlfbuc +flydbtwacuo +upaybixdlfvtcrw +tncdbalyswfu + +lenfcbjv +jfecnvlb +jlvefcnbr +lvcgqfnaetbji + +bkuycegrnpimoxvfzl +xpmklivbuyrcega +lbktipremguxcyv +pbmirkvglyceux +ykibxregmlupcv + +rwjeyxizhgt +ywxetqgajzriol +wrigyezjtx +werygtjizx + +az +ja + +sumxgwqydjhe +whtdyeqguxsp + +pncwmq +ansluwbycmxoe +cwdnmj +wqhkmcn + +flucitkw +ilucwjktf +lwukticf +lcwifktu +flcubitwk + +qlhnvft +hnvtfl + +bwsegp +bmpgsew +gpsewb +bgwqesp +pgwbse + +ib +mgjsb +bzk +bpmsgj +xb + +bjerpdfuo +wjrbf + +dkmxn +nkmdx +ndxmk +ndmxk + +rnouk +j + +m +m +t + +mrzq +zpqj +qiz +vzq +zhqi + +tkn +nrkt + +yj +jsyqp +awyj +yj +jy + +xl +dlx +olx + +kqdluj +jlkvdqu +qdukjl +qdklpju +ukqldj + +wzy +zy +zy +zy +yz + +vea +aewk +berga +waek +lyaen + +miaoyj +yjvmoiza +yimajo +jymaoi +yjoiam + +azcrbo +bzero + +fig +jbsagif +gfi + +ed +de +ed +de + +naezbtk +ubat +batku +baqvtglmo +treba + +gozafjiuerdpyscb +lxuhqvmktwn + +ysqdjnvwhagmzitpf +vszdapqhijcyln +pcazqibvhsdjyn +rjuaqhspydikznv + +qhgazndtiwb +wtbqdahviou +zbqjhwgtai +qiabwntckh +siawbyfpmxtrheql + +ej +je + +vtqgbimyo +dpwihgamzovlbtf +tmgvboi +emntbvgcio +btgimvoy + +kisynhablrjwempcouxqgdftz +xnzrkiufjpmghsqcadotwebyl +rdqezcmgajpwoylnbusxfhkti +shejiunzgdpwxylqmatrbfkoc + +lcqenihaktdgurpvmysjfxzow +sldaifypqrkhcumextwvjongz +piyslcrajgfenhmdwuovtkzqx +esxwujvtarpzkoldmyfncihgq +xqfvgosbyruephwjdaztklincm + +gyofwzc +jyluxh +dpimyv +rtsbyqa +myluej + +iwcedhs +etdich +cwihaeb +ecihby +licvfeh + +nwlfiydcst +wnldtsfy +lsnwdtyf +fdwytsln +tfsywdnl + +diphkr +ihf + +osagihfnuptwcyxqevz +ynzjfrpqoicklmuvbw +nckfilwvquozjpmy +qzwoivcfpyjun + +tbjh +noyjvqt +ejzuligpxm +hnj +jysha + +fycqbrk +kcndb +czblkq +blfcky + +wpgk +putk +lqamxiv +rd +dcw + +wmludkgnozfe +aoezwflgkmdun +uzekmdgflnwo +kgflnuzowedm +goezkndmwufl + +zmbsxkiwqrh +grjcyiwptzseqxofd +iubrwqlkxzsvn +zaqswibmxr + +soealywdutckrfnbigpxz +dntrgfaopclubeykzwsix +gnswdzialxrckybtfuope +fwodizuepagysxnktlbcr +sbdiefgptynkuwzocxalr + +tkbry +fyxr +ory + +sio +oi +oi +oi + +fipqkjmorwcluenvzx +mvowrcjxsuqpfgikenl +cxrmwvkeulpfqnoij + +jhqfvlnetysazio +osjqykft +otqyjfuxs + +opfrbnw +dbqnhoftpruz +bgeyxrpnfol +royngfpbw + +rvmxfogsbcjkpqltyhandi +xafqvhinsodltpkcwy + +pqrkslwfijgdo +pymoxvzsg +vpszyog +sehgop + +qnmxjglwavzirceu +advwiomgshuqnclzjer +zjqumrcgaiwlevn +kvugjnewclizasqmr +jilzanmtbgfrequvcw + +szkftpg +stkpgzf +ptzkgsf + +mefgopznxlusjych +iocqfmjlzgyxkpunhe + +zemltjrnbso +stbxojkrzgmneqv +zpsjernombt +stjobrmzne + +yblxcozivekmqa +epsrvyigmc + +xs +s +s + +bnmz +fhqg +dxsin +zsm + +brpge +tpm +ptm +p +sp + +utpsykci +ituxbykcwr + +zvxityphsdnuagbmcjwoqrfl +qiuwkplbtczmnvyrsoxhafjgd +qynizxpujhfmbvdcgwleasrot + +y +tx +y +h +y + +fsqatkdlmpux +yxinuvasdpfml +tsdpxafblzomu +axtfpulsmdg +lxwfqpsajudmk + +joanzmhfldbsgwcipkxuqrey +oclnpxwkyqszdjreagiumfhb +ufvoiyxzbrpwdgkcmjsqlanhe + +ciqxenmrlh +ctrfhxiqpnl + +uoxfbrglpwjkhzstidmcyq +hzslfyjxbdgecairompwkqut +ygolzckfbxdmqtpivjshrwu +kpoxzdlhurgimcsftbqywj + +xhgfmplcvwrqneztju +vqbwxtiprfhl +wxaoytfrvhbsldpq + +iop +qvxihy +io + +ftlgqpix +bpigfl +ufbgiplr + +ek +ekb +kclifmge +key +ersk + +ytqglpedjriu +jidgqytrulpe +tgjyudrqplei +jeiytpurgdlq + +anuqyij +auczniy +yanklsxivou +byacinu +inazyue + +tmryzavsnfdoq +ngmjxatvosz + +yurzemitvfqnksxpbdlhgjwa +juwvmadgcpytrkfqnbezishlx +wzudtksjrpevnxagfihlbyqm + +a +xa +ya +a + +gnukiszbvj +nyzbvpksjgmu +sgujnbzeivk +uzgbnksjv + +xoq +qox + +xlberjukaztfnoycqsgwip +tscfaexqwgkrpouzbylijn +owaruypenjqtbslizcgxkf +jzcuswiqgkrbnpyoxletfa + +pxzmb +rzmxpb +bpxznmrc +umbgpzkyox +tzbmxp + +grspmxbyhojdizwlevqfkctu +fixgbtedqomczrjhswupkyl +tlsgyobzpmcqkhrdxewfuij + +xrhelazymwntkv +lhvamxeyrznw +vrmwalyhnezx + +mdbjcizwxh +jpcbzdmxiwh + +xakdgjtimlvzcshw +iskdxfjnlhwrmvtcz + +yrli +lriz +rli +irol +ilr + +lfamcngvojeqyzrkdspwi +slqcznmwdivkrfjopebayg +cwgodjahrqzyfivepknmsl +kyeuvpjmlnftsizrdogqcaw +kjvrcgypqzinwadmoefls + +hfmuzdvyibakcwnsor +cezounhbsydwakmif + +vsajkf +jvf +vofj + +q +v + +h +h +i + +frgo +ogfr +grfo +rofg +gfro + +saomp +mpdosa +posam +mspao +ompsa + +qbxi +xbiq +bixoq +axbqi + +oix +xoi +ixo + +zqkved +ztvydqe +vdekzq + +ubg +vgcub + +wdotn +akp +hv +ipj + +xfcprnv +dfpcrvu +jpvfirc +frphqvwboc +pcvfxr + +prx +rlxp +rxp +ixpr +pxr + +uaozgkwlbfxyvmi +zbkgoxalfwuvymi +yimugvxbkfolwaz + +hwvlbzcauseydgpxrkq +lamwdrzhsbqefkvytxoicu +zktxwlnhysevqbraducj + +vjuprhcl +vjfrlpm +jbplvr +pnvljrbfe + +cwygrulzbe +elyzgwbu +uygezlwb +yebuglzw +ygzwuble + +wbzecjtdrgiyqls +wlsycjgeizdr +zslyderwigcj +dwzcyjgerisl + +qkvegzmnobpuc +pogzvqmkbn + +cnepixbwhklmqzodvyautjgrfs +oepszjgmlcxkdiartnybwhfvqu +gvcxaintlrweupbzfsmykdjqho +xalwvjenruhpkmgfqtoysbdizc + +omrc +tcer +bguaf +vhtk + +rtednpkyxgcs +kxlsredupynt +bartsexnypfmqk + +lqrabmznuhgjfi +chligsdnbjrazum +jpghuibarnzlkom +bamhwrngzjfliuye +yuignrzsamhlxbjt + +aoslfqnjcghb +cnbflgjqaohs +oqshfljbncaxg + +av +av +va +dvqa + +lghqidarnczwfxyu +ylfnhqwczaiuxdg +wfdglzixauchnqy + +pfgknomr +nfegr +vihnlcfdqgy +fgrns +awogfn + +kfdntirsmqap +thjdknbugmr +nxfetkrmd + +ydabnisroqeghk +gryenohbaiqsk +sqbingvyoakehr +ngbkyfaicsrhqeo + +ghxtulq +ntgqxlsz +lgzqtxsi + +qvr +mqljsu +wlqu +gpoqytkbzf +evqw + +khybpm +rhboj + +rmcqdblnto +qlcnmor +rhmzalcsoq +lgxcrmnqovd + +wdfkpmalijbncuvr +qhnmikpzaygxwsovej
\ No newline at end of file diff --git a/2020/06/puzzle-1.awk b/2020/06/puzzle-1.awk new file mode 100755 index 0000000..71d55a8 --- /dev/null +++ b/2020/06/puzzle-1.awk @@ -0,0 +1,14 @@ +#!/usr/bin/env -S awk -f + +BEGIN { RS = "" } +{ + split($0, chars, "") + for (i = 1; i <= length; i++) { + if (chars[i] != "\n") + answers[chars[i]] = 1 + } + + sum += length(answers) + delete answers +} +END { print sum } diff --git a/2020/06/puzzle-2.awk b/2020/06/puzzle-2.awk new file mode 100755 index 0000000..98224ac --- /dev/null +++ b/2020/06/puzzle-2.awk @@ -0,0 +1,23 @@ +#!/usr/bin/env -S awk -f + +BEGIN { + RS = "" + FS = "\n" +} + +{ + for (i = 1; i <= NF; i++) { + len = split($i, answers, "") + for (j = 1; j <= len; j++) + count[answers[j]]++ + } + + for (i in count) { + if (count[i] == NF) + sum++ + } + + delete count +} + +END { print sum } diff --git a/2020/07/input b/2020/07/input new file mode 100644 index 0000000..4e9e60a --- /dev/null +++ b/2020/07/input @@ -0,0 +1,594 @@ +dotted salmon bags contain 2 dark lavender bags, 1 muted red bag, 1 vibrant magenta bag. +vibrant purple bags contain 1 pale cyan bag, 1 dotted lavender bag, 3 striped blue bags, 5 clear magenta bags. +vibrant fuchsia bags contain 4 posh violet bags, 3 bright aqua bags, 1 light silver bag. +mirrored purple bags contain 2 dim yellow bags, 4 dim green bags, 3 vibrant beige bags. +faded coral bags contain 1 vibrant plum bag, 3 pale gold bags, 5 dim purple bags, 1 drab teal bag. +wavy cyan bags contain 4 dark teal bags, 1 dotted magenta bag. +dotted gold bags contain 3 dotted gray bags. +shiny maroon bags contain 2 light white bags, 5 bright salmon bags. +vibrant cyan bags contain 2 dull beige bags. +clear fuchsia bags contain 5 bright bronze bags. +clear violet bags contain 4 clear white bags, 2 drab fuchsia bags, 4 plaid lavender bags, 4 drab beige bags. +wavy tomato bags contain 3 wavy yellow bags, 4 plaid maroon bags, 1 dark beige bag. +shiny indigo bags contain 4 posh aqua bags, 2 dim salmon bags, 3 dotted olive bags, 1 dull gray bag. +dotted indigo bags contain 3 muted bronze bags, 1 striped salmon bag, 5 vibrant violet bags, 3 drab crimson bags. +mirrored magenta bags contain 1 shiny aqua bag. +pale green bags contain 4 striped orange bags, 3 plaid red bags, 3 clear olive bags. +dim crimson bags contain 5 posh violet bags, 3 mirrored crimson bags, 2 striped white bags, 1 dark indigo bag. +light white bags contain 1 dark indigo bag, 1 wavy orange bag. +striped green bags contain 2 clear beige bags, 4 dim coral bags. +dotted lavender bags contain 1 striped white bag, 5 dotted coral bags, 3 striped orange bags, 1 dotted gray bag. +light purple bags contain 5 dim tomato bags, 4 dull plum bags, 1 dim green bag, 3 dotted magenta bags. +shiny violet bags contain 1 shiny white bag. +dark lime bags contain 4 mirrored crimson bags, 2 wavy crimson bags, 4 dim green bags. +dark teal bags contain 3 mirrored orange bags. +muted maroon bags contain 5 dim fuchsia bags. +posh tomato bags contain 3 bright violet bags, 3 dim crimson bags, 4 mirrored beige bags, 3 drab lime bags. +plaid violet bags contain 1 shiny tomato bag, 5 dotted gray bags, 1 muted magenta bag, 5 mirrored crimson bags. +shiny bronze bags contain 3 dim red bags, 2 drab plum bags, 3 striped yellow bags, 1 mirrored yellow bag. +muted tomato bags contain 2 vibrant maroon bags, 3 vibrant beige bags, 5 light coral bags. +muted fuchsia bags contain 2 clear violet bags, 4 shiny gray bags, 1 shiny gold bag, 3 wavy crimson bags. +pale teal bags contain 2 bright beige bags, 3 vibrant cyan bags, 4 bright salmon bags, 3 plaid red bags. +posh salmon bags contain 2 dull beige bags, 1 faded maroon bag. +dim white bags contain 2 dull tan bags, 3 dotted coral bags, 1 light silver bag, 1 dim gold bag. +posh tan bags contain 4 clear blue bags, 4 dim olive bags, 4 striped green bags. +dim lime bags contain 2 drab chartreuse bags, 5 striped magenta bags, 4 striped purple bags. +mirrored white bags contain 2 dotted white bags, 3 striped salmon bags, 3 dull green bags, 3 plaid orange bags. +shiny fuchsia bags contain 3 striped bronze bags, 1 plaid violet bag. +dull indigo bags contain 5 wavy tomato bags. +posh maroon bags contain 2 dark green bags, 4 posh red bags, 3 drab tomato bags. +clear coral bags contain 5 pale yellow bags, 2 muted green bags, 3 faded black bags, 1 striped teal bag. +posh gold bags contain 3 wavy yellow bags, 5 mirrored crimson bags, 1 dotted lavender bag, 2 plaid purple bags. +muted yellow bags contain 3 wavy tan bags, 1 dark beige bag, 3 drab lavender bags. +pale cyan bags contain 5 clear black bags, 3 dull lime bags, 3 wavy olive bags, 5 plaid indigo bags. +drab white bags contain 2 dull green bags, 3 wavy aqua bags, 4 dark indigo bags. +drab lime bags contain 2 drab aqua bags, 5 light turquoise bags. +dotted tan bags contain 1 dotted beige bag, 5 faded maroon bags, 5 light indigo bags, 3 light bronze bags. +muted crimson bags contain 5 faded gold bags. +striped turquoise bags contain 1 shiny silver bag, 4 vibrant salmon bags, 5 dotted yellow bags. +plaid yellow bags contain 2 dim crimson bags, 5 bright tan bags, 3 wavy yellow bags, 1 clear silver bag. +shiny salmon bags contain 2 vibrant yellow bags. +pale maroon bags contain 5 faded silver bags, 3 dull lavender bags, 4 dotted magenta bags. +dotted orange bags contain 4 mirrored brown bags, 2 clear fuchsia bags. +muted gray bags contain 5 dim purple bags, 3 wavy yellow bags. +vibrant gold bags contain 2 wavy maroon bags, 5 faded chartreuse bags, 3 light indigo bags, 4 dark brown bags. +bright fuchsia bags contain 4 pale crimson bags, 3 striped orange bags, 1 shiny tomato bag, 5 bright tan bags. +light cyan bags contain 1 dim teal bag, 3 wavy indigo bags. +pale olive bags contain 3 light fuchsia bags. +dim brown bags contain 2 dotted indigo bags. +mirrored silver bags contain 3 plaid violet bags. +posh cyan bags contain 5 wavy maroon bags, 4 dim gold bags. +bright turquoise bags contain 5 posh bronze bags, 4 shiny aqua bags. +faded fuchsia bags contain 3 dotted gray bags. +dull beige bags contain 3 posh bronze bags. +dark purple bags contain 4 dim salmon bags, 4 faded maroon bags, 2 drab red bags, 1 clear bronze bag. +drab tan bags contain 5 striped maroon bags. +faded green bags contain 3 dark lavender bags, 4 posh lime bags, 2 light purple bags, 2 dark plum bags. +posh indigo bags contain 4 dark tan bags, 2 dark lavender bags, 1 shiny cyan bag. +drab maroon bags contain 3 wavy red bags, 1 dim fuchsia bag, 5 mirrored indigo bags, 2 drab lavender bags. +dim magenta bags contain 4 striped orange bags. +striped teal bags contain 2 dark lime bags. +plaid green bags contain 5 mirrored salmon bags, 4 mirrored brown bags, 2 dark lavender bags, 4 faded indigo bags. +dull blue bags contain 3 faded lime bags, 2 faded violet bags, 4 dull tan bags, 1 shiny tan bag. +muted turquoise bags contain 5 dim silver bags, 4 wavy crimson bags. +dull teal bags contain 1 faded blue bag, 3 light violet bags, 3 faded black bags. +mirrored salmon bags contain 4 muted magenta bags, 3 dotted tomato bags, 2 light cyan bags, 2 vibrant lavender bags. +shiny coral bags contain 1 striped teal bag, 1 drab lime bag, 5 mirrored red bags. +muted chartreuse bags contain 2 striped white bags, 3 bright turquoise bags, 2 faded silver bags. +mirrored green bags contain 2 bright maroon bags. +light brown bags contain 2 clear bronze bags, 4 dark lime bags, 3 muted teal bags, 5 wavy yellow bags. +vibrant indigo bags contain 3 dotted bronze bags. +light coral bags contain 2 dotted bronze bags. +dotted turquoise bags contain 3 plaid red bags, 3 shiny fuchsia bags, 4 faded lime bags. +dark white bags contain 1 dull blue bag, 5 shiny cyan bags, 3 dark beige bags, 2 mirrored brown bags. +pale purple bags contain 5 faded gold bags, 2 drab maroon bags. +wavy beige bags contain 3 faded violet bags, 4 mirrored silver bags, 4 clear gray bags, 2 dotted tomato bags. +light teal bags contain 4 bright magenta bags, 2 drab coral bags. +bright tomato bags contain 3 mirrored crimson bags, 1 muted blue bag, 4 dim brown bags. +plaid turquoise bags contain 4 vibrant blue bags, 1 wavy chartreuse bag, 2 pale magenta bags. +faded tomato bags contain 3 light salmon bags, 2 wavy chartreuse bags. +faded salmon bags contain 5 dark aqua bags, 4 faded bronze bags, 5 bright crimson bags. +light salmon bags contain 2 mirrored silver bags, 3 dotted coral bags, 3 wavy crimson bags. +mirrored lavender bags contain 4 shiny silver bags, 1 wavy crimson bag. +vibrant plum bags contain 5 light orange bags, 4 dull lime bags, 2 dim aqua bags, 5 shiny violet bags. +vibrant tan bags contain 1 drab salmon bag, 2 dull beige bags, 3 dotted bronze bags. +faded red bags contain 3 light indigo bags, 2 dotted tomato bags. +bright purple bags contain 3 light tomato bags, 3 clear gold bags. +plaid magenta bags contain 5 muted orange bags, 3 pale plum bags, 5 faded plum bags. +wavy tan bags contain 1 dull lavender bag. +faded olive bags contain 5 mirrored silver bags. +plaid white bags contain 4 bright bronze bags, 2 dotted cyan bags, 2 dark lavender bags, 5 shiny lavender bags. +striped aqua bags contain 5 light salmon bags. +drab tomato bags contain 1 dark lime bag, 2 muted magenta bags, 5 clear gray bags, 3 dotted gray bags. +clear tomato bags contain 5 plaid bronze bags. +posh teal bags contain 1 plaid maroon bag, 3 light tan bags, 1 clear crimson bag, 5 vibrant aqua bags. +dim tan bags contain 2 drab fuchsia bags, 3 dark beige bags, 3 plaid green bags. +dotted lime bags contain 4 dim red bags. +mirrored beige bags contain 1 bright orange bag, 3 light purple bags. +plaid silver bags contain 2 bright gold bags. +faded orange bags contain 5 faded plum bags. +dim indigo bags contain 4 muted orange bags, 5 vibrant tomato bags. +shiny blue bags contain 3 drab crimson bags, 2 dim green bags, 1 clear violet bag. +dull olive bags contain 2 plaid lime bags, 5 muted maroon bags, 4 shiny crimson bags, 3 dim plum bags. +striped maroon bags contain 1 dim tomato bag, 2 dotted tomato bags, 1 muted magenta bag, 5 faded maroon bags. +dull green bags contain 4 light salmon bags, 1 dim green bag. +vibrant crimson bags contain 4 clear plum bags, 2 faded white bags, 4 wavy crimson bags. +striped chartreuse bags contain 2 plaid lavender bags. +bright chartreuse bags contain 2 vibrant orange bags. +drab lavender bags contain 4 dotted coral bags. +dull crimson bags contain 2 faded silver bags, 2 bright magenta bags. +striped magenta bags contain 4 dull crimson bags, 4 faded maroon bags. +clear bronze bags contain 1 bright bronze bag, 2 shiny red bags. +plaid tan bags contain 5 pale silver bags, 5 muted teal bags, 3 faded beige bags, 2 faded chartreuse bags. +dim black bags contain 2 faded indigo bags. +shiny black bags contain 3 dotted bronze bags, 5 clear olive bags, 3 dark orange bags, 4 pale coral bags. +striped gold bags contain 3 dotted coral bags, 4 faded orange bags, 2 striped purple bags, 4 light cyan bags. +drab chartreuse bags contain 4 dull crimson bags. +bright yellow bags contain 3 wavy crimson bags, 4 bright turquoise bags, 3 plaid red bags. +dark orange bags contain 3 wavy yellow bags. +clear salmon bags contain 5 wavy turquoise bags, 4 shiny aqua bags, 1 shiny brown bag, 1 vibrant tomato bag. +plaid fuchsia bags contain 1 posh olive bag. +wavy magenta bags contain 5 vibrant beige bags, 5 faded chartreuse bags, 5 light purple bags, 4 wavy indigo bags. +dull gold bags contain 2 shiny bronze bags, 4 plaid beige bags, 4 mirrored silver bags, 2 bright lavender bags. +drab magenta bags contain 1 posh red bag. +shiny silver bags contain 4 dark lavender bags, 2 dull tan bags. +shiny crimson bags contain 3 plaid violet bags, 4 muted purple bags. +posh black bags contain 2 dotted magenta bags, 4 dotted gray bags. +vibrant salmon bags contain 1 clear silver bag. +dotted tomato bags contain 4 wavy crimson bags, 3 faded plum bags, 4 muted magenta bags. +dark turquoise bags contain 1 dim beige bag, 3 dotted coral bags. +pale orange bags contain 2 striped silver bags, 1 dotted salmon bag, 3 dim black bags, 4 posh turquoise bags. +mirrored indigo bags contain 5 posh yellow bags. +muted lavender bags contain 5 striped olive bags, 1 muted indigo bag. +light yellow bags contain 5 dark chartreuse bags. +drab bronze bags contain 3 clear beige bags, 3 bright purple bags, 3 bright brown bags. +mirrored blue bags contain 5 dotted bronze bags, 1 dark green bag, 5 clear silver bags, 5 dim maroon bags. +wavy violet bags contain 4 light tan bags, 1 vibrant lavender bag. +clear red bags contain 4 faded orange bags, 1 drab gold bag, 4 dim teal bags, 4 dotted indigo bags. +striped indigo bags contain 5 dim indigo bags. +striped olive bags contain 3 dotted green bags, 4 mirrored cyan bags. +dim fuchsia bags contain 3 vibrant gray bags, 5 wavy brown bags, 2 muted beige bags. +plaid plum bags contain 3 shiny tomato bags, 4 striped orange bags. +striped white bags contain 1 plaid red bag. +mirrored coral bags contain 5 drab teal bags, 4 dotted coral bags, 4 striped chartreuse bags, 5 dotted gold bags. +dull bronze bags contain 4 dim olive bags, 5 posh turquoise bags, 2 clear gold bags. +pale white bags contain 3 vibrant gray bags, 4 wavy coral bags, 5 drab purple bags. +drab green bags contain 1 dim teal bag, 1 faded bronze bag, 3 clear silver bags. +dotted black bags contain 3 drab tan bags, 2 vibrant orange bags, 3 striped maroon bags. +light gold bags contain 5 posh olive bags, 3 striped orange bags, 3 dull orange bags. +pale tan bags contain 1 mirrored fuchsia bag, 4 light silver bags, 5 dim plum bags. +plaid lavender bags contain 1 dim teal bag, 5 shiny aqua bags, 5 wavy crimson bags. +wavy lime bags contain 1 pale chartreuse bag, 5 mirrored white bags, 4 faded olive bags. +bright crimson bags contain 1 plaid green bag. +pale fuchsia bags contain 4 light aqua bags. +striped crimson bags contain 4 shiny plum bags, 3 dull violet bags, 5 clear tan bags. +mirrored fuchsia bags contain 3 posh red bags, 3 plaid violet bags, 5 shiny brown bags, 5 striped chartreuse bags. +faded cyan bags contain 3 striped yellow bags, 3 clear indigo bags. +mirrored plum bags contain 2 vibrant silver bags. +dull turquoise bags contain 2 plaid white bags, 5 striped salmon bags, 5 clear purple bags. +dim orange bags contain 5 dim black bags. +dull orange bags contain 3 dotted magenta bags, 2 mirrored crimson bags, 3 striped bronze bags. +dark gray bags contain 4 dotted crimson bags, 2 vibrant salmon bags. +drab orange bags contain 5 dotted gray bags, 5 muted maroon bags, 5 faded aqua bags, 2 pale maroon bags. +striped bronze bags contain 3 striped white bags, 5 striped orange bags. +light bronze bags contain 2 plaid red bags, 2 faded olive bags. +drab olive bags contain 2 striped salmon bags, 3 drab white bags, 4 pale silver bags. +bright cyan bags contain 5 muted blue bags. +drab black bags contain 1 shiny blue bag, 1 drab yellow bag, 5 muted tan bags, 2 drab violet bags. +shiny green bags contain 5 dim purple bags, 1 dotted crimson bag. +wavy blue bags contain 3 shiny white bags. +pale lime bags contain 1 dotted maroon bag. +dotted red bags contain 1 dotted bronze bag, 1 vibrant lime bag, 4 clear plum bags. +faded bronze bags contain 4 pale magenta bags, 1 faded black bag, 1 faded orange bag, 3 dark crimson bags. +dark green bags contain 1 striped magenta bag. +faded blue bags contain 2 dim maroon bags. +dim violet bags contain 4 posh yellow bags, 5 dim lime bags, 5 faded olive bags. +dark tan bags contain 2 mirrored green bags. +dim teal bags contain 5 mirrored yellow bags, 2 dull tan bags, 2 vibrant lavender bags, 4 clear lime bags. +plaid crimson bags contain 3 striped black bags, 1 faded plum bag, 3 muted red bags. +clear white bags contain 1 shiny gold bag. +dim silver bags contain 5 dull tan bags. +dark cyan bags contain 2 clear black bags, 5 plaid yellow bags, 2 posh coral bags. +dull violet bags contain 5 wavy teal bags, 5 shiny white bags. +muted coral bags contain 5 faded violet bags, 2 drab red bags, 3 muted olive bags, 4 mirrored tomato bags. +vibrant white bags contain 3 muted brown bags, 4 mirrored red bags, 4 dull orange bags, 4 dark crimson bags. +posh red bags contain 2 clear gray bags, 2 bright turquoise bags. +wavy chartreuse bags contain 5 light tomato bags, 5 posh black bags. +striped black bags contain 1 faded green bag, 1 wavy green bag, 4 wavy orange bags. +drab indigo bags contain 4 clear cyan bags, 4 mirrored crimson bags, 4 clear silver bags. +pale gold bags contain 1 dim lime bag. +dark olive bags contain 5 bright white bags, 5 clear lavender bags, 2 vibrant coral bags. +muted salmon bags contain 4 drab beige bags, 3 plaid violet bags, 4 mirrored brown bags, 3 dark lime bags. +posh gray bags contain 1 clear beige bag, 4 vibrant blue bags, 1 shiny aqua bag, 5 dim tan bags. +bright white bags contain 5 muted bronze bags, 5 clear cyan bags. +dull white bags contain 1 vibrant tomato bag. +striped tan bags contain 4 mirrored brown bags, 5 faded chartreuse bags. +wavy teal bags contain 3 plaid red bags. +faded purple bags contain 4 muted orange bags, 3 clear salmon bags, 5 drab cyan bags. +dotted yellow bags contain 4 light indigo bags, 5 drab violet bags, 3 dull tan bags, 3 bright lime bags. +wavy plum bags contain 2 dim aqua bags, 5 dark brown bags, 1 bright gold bag, 2 dull orange bags. +muted blue bags contain 5 plaid tan bags, 4 dim salmon bags, 5 striped tomato bags. +dim green bags contain no other bags. +light lime bags contain 3 mirrored orange bags, 2 muted red bags, 1 dim black bag, 4 posh maroon bags. +mirrored brown bags contain 4 dotted gray bags, 3 clear lime bags, 2 dim green bags. +drab fuchsia bags contain 5 mirrored yellow bags, 5 plaid plum bags. +drab gray bags contain 2 dim violet bags, 4 posh purple bags. +vibrant teal bags contain 4 pale tomato bags, 2 posh lime bags, 2 mirrored silver bags, 1 wavy crimson bag. +dotted plum bags contain 5 bright gold bags. +shiny gold bags contain 4 shiny tomato bags, 5 wavy indigo bags. +bright bronze bags contain 2 faded maroon bags, 2 dim white bags, 5 drab violet bags. +drab yellow bags contain 4 mirrored green bags, 5 faded fuchsia bags, 1 drab turquoise bag. +dark bronze bags contain 5 muted salmon bags, 3 posh cyan bags, 2 shiny tan bags. +light magenta bags contain 3 dark silver bags, 2 striped tan bags. +pale yellow bags contain 5 drab tomato bags, 3 striped orange bags, 4 striped maroon bags. +shiny cyan bags contain 2 light tomato bags, 3 clear purple bags, 2 shiny tan bags, 3 dull tan bags. +pale gray bags contain 2 drab purple bags, 5 dotted turquoise bags, 3 pale salmon bags. +mirrored cyan bags contain 4 faded chartreuse bags. +dotted bronze bags contain 2 faded silver bags. +faded beige bags contain 1 bright red bag, 3 dotted red bags, 2 striped lime bags. +dotted beige bags contain 4 muted turquoise bags, 1 dull beige bag, 3 bright gold bags. +drab plum bags contain 4 clear chartreuse bags. +pale blue bags contain 1 dim chartreuse bag, 1 dark lavender bag, 1 drab tan bag. +faded teal bags contain 1 vibrant tan bag, 1 dim tan bag, 3 dull gray bags, 4 plaid red bags. +plaid beige bags contain 3 plaid tomato bags. +dotted chartreuse bags contain 1 pale maroon bag. +bright gray bags contain 2 bright coral bags, 3 bright turquoise bags, 4 posh tan bags. +bright olive bags contain 1 dotted bronze bag, 4 mirrored yellow bags, 4 light bronze bags. +dotted olive bags contain 5 clear purple bags, 5 muted bronze bags, 5 vibrant tomato bags. +pale tomato bags contain 4 clear gold bags, 4 clear tomato bags. +clear gold bags contain 1 striped lime bag, 1 striped chartreuse bag, 2 muted fuchsia bags, 5 clear salmon bags. +dotted gray bags contain no other bags. +striped brown bags contain 3 pale maroon bags, 5 faded gold bags, 4 wavy yellow bags, 3 bright turquoise bags. +shiny lime bags contain 4 pale violet bags, 4 clear violet bags. +mirrored tan bags contain 1 vibrant magenta bag, 3 mirrored violet bags, 5 faded plum bags. +dull maroon bags contain 5 posh salmon bags, 5 dull coral bags, 2 plaid plum bags, 3 striped teal bags. +dim purple bags contain 1 light tomato bag, 3 shiny violet bags. +bright brown bags contain 1 shiny aqua bag, 1 shiny lavender bag, 1 drab fuchsia bag, 3 faded olive bags. +light maroon bags contain 4 mirrored brown bags. +pale violet bags contain 4 wavy turquoise bags, 5 dull orange bags, 4 dotted black bags, 5 muted fuchsia bags. +mirrored black bags contain 3 dotted silver bags, 2 bright crimson bags. +drab aqua bags contain 3 plaid red bags, 1 plaid violet bag, 5 dim tomato bags. +clear green bags contain 4 dark coral bags. +mirrored aqua bags contain 4 shiny crimson bags, 4 wavy bronze bags. +pale coral bags contain 2 wavy olive bags, 2 muted silver bags, 4 dim tan bags. +mirrored gray bags contain 5 clear plum bags, 5 dark yellow bags. +light blue bags contain 3 dull bronze bags, 3 dotted plum bags. +dark silver bags contain 2 plaid chartreuse bags, 5 plaid lavender bags, 1 wavy indigo bag, 4 dark brown bags. +posh silver bags contain 4 shiny lavender bags. +shiny orange bags contain 4 light magenta bags. +dark blue bags contain 5 pale purple bags. +wavy white bags contain 1 posh olive bag, 1 dotted fuchsia bag, 4 muted maroon bags. +striped orange bags contain 2 faded plum bags. +dull lime bags contain 1 pale yellow bag, 1 clear turquoise bag, 5 faded silver bags, 4 dim beige bags. +dull red bags contain 1 bright aqua bag, 3 light maroon bags, 5 light tomato bags. +light tomato bags contain 3 dull crimson bags, 1 dim beige bag. +bright blue bags contain 3 plaid olive bags. +bright red bags contain 4 muted teal bags, 5 dotted magenta bags. +striped gray bags contain 2 dotted purple bags, 4 dull green bags, 4 dull salmon bags, 4 muted silver bags. +drab salmon bags contain 4 mirrored indigo bags, 5 mirrored silver bags, 5 shiny cyan bags, 1 plaid brown bag. +posh olive bags contain 3 faded silver bags, 5 plaid violet bags, 2 striped bronze bags. +dim salmon bags contain 5 vibrant lavender bags. +mirrored orange bags contain 2 bright white bags, 5 plaid orange bags. +posh fuchsia bags contain 5 vibrant coral bags, 2 shiny plum bags, 5 pale silver bags. +wavy fuchsia bags contain 5 posh cyan bags, 2 bright silver bags, 1 wavy tomato bag, 1 wavy plum bag. +clear olive bags contain 4 pale maroon bags, 2 muted bronze bags, 4 mirrored crimson bags, 2 dull blue bags. +clear blue bags contain 5 shiny white bags, 5 plaid lime bags. +dotted coral bags contain no other bags. +clear black bags contain 4 dull beige bags, 2 mirrored crimson bags, 2 dim beige bags. +mirrored turquoise bags contain 2 light green bags, 4 dull lime bags, 2 drab olive bags, 3 drab purple bags. +muted teal bags contain 2 dim gold bags, 1 light salmon bag, 3 dark crimson bags, 3 muted olive bags. +clear gray bags contain 2 dotted coral bags, 5 shiny tomato bags. +vibrant black bags contain 2 dull blue bags, 1 light magenta bag. +clear yellow bags contain 3 vibrant yellow bags, 2 plaid red bags, 1 dull plum bag, 4 faded violet bags. +dull fuchsia bags contain 4 dim maroon bags, 4 wavy plum bags, 5 dim teal bags. +mirrored gold bags contain 4 mirrored brown bags, 3 dotted coral bags, 4 faded plum bags, 1 mirrored indigo bag. +faded lime bags contain 3 plaid violet bags, 2 drab tan bags. +wavy olive bags contain 3 muted silver bags, 1 pale maroon bag, 5 posh silver bags. +pale bronze bags contain 2 striped purple bags, 5 bright magenta bags, 4 pale crimson bags. +posh crimson bags contain 4 mirrored purple bags, 2 shiny silver bags, 4 bright tan bags. +clear plum bags contain 1 mirrored indigo bag, 4 clear purple bags, 2 dull blue bags, 5 striped bronze bags. +vibrant chartreuse bags contain 5 vibrant yellow bags, 1 faded red bag. +plaid red bags contain no other bags. +dim maroon bags contain 2 pale yellow bags, 4 dotted cyan bags. +pale silver bags contain 2 dark crimson bags. +bright magenta bags contain 5 plaid red bags, 4 faded maroon bags. +dark crimson bags contain 2 bright magenta bags, 1 mirrored silver bag, 2 mirrored brown bags, 1 shiny lavender bag. +dull yellow bags contain 1 dull salmon bag. +dark maroon bags contain 5 muted turquoise bags. +clear indigo bags contain 5 posh purple bags, 3 striped magenta bags. +shiny olive bags contain 3 drab yellow bags. +vibrant bronze bags contain 4 plaid indigo bags. +light plum bags contain 5 faded aqua bags. +dim lavender bags contain 3 drab purple bags, 2 clear salmon bags, 1 wavy bronze bag, 1 plaid tan bag. +mirrored chartreuse bags contain 3 wavy plum bags, 2 muted tan bags. +bright teal bags contain 2 bright lavender bags, 5 plaid plum bags, 3 clear bronze bags. +dull tan bags contain 4 clear gray bags. +shiny magenta bags contain 2 plaid gold bags, 2 dotted turquoise bags, 4 muted teal bags, 3 shiny gold bags. +clear aqua bags contain 4 dim cyan bags, 3 dim plum bags, 5 dim violet bags, 1 plaid yellow bag. +clear tan bags contain 1 shiny brown bag. +faded lavender bags contain 3 faded white bags, 1 faded purple bag. +plaid maroon bags contain 5 plaid orange bags, 4 striped green bags, 2 striped gold bags, 5 bright bronze bags. +wavy lavender bags contain 5 dim black bags, 5 clear fuchsia bags. +plaid olive bags contain 3 dotted crimson bags, 2 pale plum bags, 3 bright orange bags, 1 clear coral bag. +shiny lavender bags contain 3 faded plum bags, 2 mirrored crimson bags, 5 striped orange bags, 5 bright magenta bags. +plaid chartreuse bags contain 5 clear silver bags, 5 pale crimson bags. +bright coral bags contain 4 vibrant orange bags. +wavy yellow bags contain 3 dull plum bags, 4 bright yellow bags, 5 mirrored violet bags, 3 plaid red bags. +dark chartreuse bags contain 4 striped bronze bags, 2 bright tan bags. +mirrored tomato bags contain 1 clear yellow bag, 1 dark lime bag, 2 mirrored silver bags. +plaid gray bags contain 4 muted cyan bags, 4 dark silver bags, 1 wavy orange bag, 4 muted tomato bags. +mirrored red bags contain 5 pale crimson bags, 5 light cyan bags, 1 posh yellow bag. +vibrant silver bags contain 2 dull brown bags, 1 vibrant orange bag, 5 striped red bags. +plaid purple bags contain 2 striped maroon bags, 1 faded olive bag. +dull silver bags contain 4 shiny lavender bags, 5 plaid fuchsia bags, 1 plaid plum bag, 2 light cyan bags. +dark plum bags contain 2 vibrant gold bags, 4 plaid brown bags, 1 drab teal bag, 4 dotted yellow bags. +mirrored teal bags contain 3 drab orange bags, 4 shiny fuchsia bags, 4 mirrored lavender bags, 1 clear brown bag. +light red bags contain 5 striped violet bags. +shiny aqua bags contain 4 wavy indigo bags, 3 posh olive bags, 2 clear gray bags, 2 dim tomato bags. +dull magenta bags contain 1 bright crimson bag, 1 bright bronze bag, 2 drab gold bags, 2 clear lavender bags. +muted gold bags contain 1 striped chartreuse bag, 3 posh olive bags. +dark brown bags contain 1 bright yellow bag. +dull brown bags contain 5 dark brown bags, 1 dim gold bag. +shiny chartreuse bags contain 1 shiny aqua bag, 5 faded chartreuse bags, 4 wavy beige bags. +vibrant maroon bags contain 1 dotted yellow bag, 2 striped green bags, 2 muted olive bags, 2 muted turquoise bags. +faded maroon bags contain 1 striped bronze bag, 5 dotted coral bags, 4 dim green bags, 1 faded plum bag. +wavy salmon bags contain 1 dim white bag, 4 clear purple bags, 5 dark fuchsia bags, 5 vibrant cyan bags. +light beige bags contain 3 dull lime bags, 1 plaid lavender bag. +plaid teal bags contain 2 muted black bags, 2 dull salmon bags, 5 faded red bags, 2 muted turquoise bags. +plaid cyan bags contain 5 faded maroon bags, 2 posh chartreuse bags. +dim chartreuse bags contain 5 muted red bags, 4 dark lime bags. +clear magenta bags contain 1 clear tomato bag, 1 striped orange bag, 3 striped chartreuse bags. +dotted blue bags contain 5 plaid green bags, 3 mirrored crimson bags, 4 dotted magenta bags, 3 clear bronze bags. +clear silver bags contain 4 vibrant lavender bags, 1 wavy turquoise bag, 2 posh purple bags, 5 dull blue bags. +posh beige bags contain 4 muted aqua bags, 3 wavy orange bags, 1 muted coral bag. +dim coral bags contain 1 clear purple bag, 2 plaid purple bags, 5 light gold bags. +faded white bags contain 2 striped orange bags, 3 posh silver bags, 4 shiny tan bags, 5 faded green bags. +pale aqua bags contain 5 shiny tan bags, 5 drab violet bags. +clear brown bags contain 5 shiny tomato bags. +faded tan bags contain 1 pale gray bag, 2 dull beige bags, 3 wavy teal bags, 1 bright maroon bag. +striped silver bags contain 3 shiny green bags. +vibrant brown bags contain 5 shiny aqua bags, 2 pale violet bags, 5 drab indigo bags. +dark yellow bags contain 1 wavy white bag, 3 posh violet bags, 4 bright magenta bags. +dull gray bags contain 3 dark silver bags, 3 mirrored green bags. +dark violet bags contain 2 dark maroon bags, 5 dull aqua bags. +muted brown bags contain 5 dim aqua bags, 3 dim teal bags, 4 faded olive bags, 1 plaid purple bag. +posh chartreuse bags contain 3 dark tan bags, 1 striped salmon bag, 2 dark lime bags, 5 vibrant beige bags. +mirrored maroon bags contain 1 dark red bag. +faded yellow bags contain 5 mirrored beige bags, 1 drab chartreuse bag, 3 vibrant lavender bags. +dotted aqua bags contain 4 vibrant lavender bags, 4 shiny fuchsia bags. +bright maroon bags contain 5 faded maroon bags, 2 dark lime bags, 4 dim beige bags. +dark salmon bags contain 5 clear tan bags. +wavy bronze bags contain 3 dark beige bags. +wavy crimson bags contain no other bags. +drab gold bags contain 2 faded violet bags, 4 faded silver bags. +dark black bags contain 3 wavy bronze bags, 2 dark aqua bags, 4 dotted beige bags. +striped lavender bags contain 2 wavy aqua bags. +vibrant red bags contain 1 plaid aqua bag. +shiny yellow bags contain 5 clear silver bags, 2 dull magenta bags, 5 clear turquoise bags. +dull chartreuse bags contain 5 light tan bags. +bright beige bags contain 2 dim tomato bags. +mirrored yellow bags contain 5 drab aqua bags, 5 mirrored silver bags, 3 dark lime bags. +striped beige bags contain 4 dim white bags. +muted orange bags contain 3 drab beige bags, 5 faded olive bags. +drab turquoise bags contain 1 light green bag, 1 drab tomato bag, 4 clear purple bags. +plaid salmon bags contain 3 posh gray bags, 1 dim beige bag, 1 plaid brown bag. +faded gray bags contain 3 plaid fuchsia bags, 5 plaid magenta bags, 5 plaid white bags, 1 dull beige bag. +posh aqua bags contain 2 mirrored turquoise bags. +mirrored crimson bags contain no other bags. +vibrant magenta bags contain 1 dull purple bag, 4 shiny red bags, 5 drab chartreuse bags, 4 bright red bags. +striped yellow bags contain 1 shiny tan bag. +vibrant orange bags contain 4 plaid silver bags, 5 dim teal bags, 1 striped maroon bag, 3 plaid red bags. +dark indigo bags contain 3 drab purple bags. +shiny gray bags contain 1 wavy yellow bag. +faded plum bags contain no other bags. +dim blue bags contain 2 dotted crimson bags, 5 muted chartreuse bags, 3 dark silver bags, 4 vibrant lime bags. +muted white bags contain 4 muted teal bags, 3 posh purple bags, 1 dull lavender bag, 5 pale crimson bags. +muted lime bags contain 1 shiny turquoise bag, 2 faded indigo bags, 2 vibrant silver bags, 1 pale turquoise bag. +posh coral bags contain 5 faded violet bags. +dotted fuchsia bags contain 1 clear tan bag, 1 striped lavender bag. +wavy brown bags contain 2 dim aqua bags. +posh brown bags contain 1 shiny cyan bag, 5 plaid orange bags, 3 light coral bags. +drab purple bags contain 5 faded orange bags. +muted tan bags contain 2 wavy teal bags, 3 dim salmon bags, 1 bright gold bag, 3 clear gray bags. +dim yellow bags contain 1 vibrant gray bag, 4 vibrant lavender bags, 1 muted magenta bag. +pale salmon bags contain 2 vibrant beige bags, 3 bright maroon bags. +faded turquoise bags contain 4 plaid purple bags, 2 light tomato bags, 3 light salmon bags. +clear teal bags contain 4 muted yellow bags, 3 dim beige bags, 5 faded tomato bags, 1 dim red bag. +vibrant olive bags contain 3 muted lime bags, 5 shiny blue bags, 3 light gold bags, 3 dark olive bags. +dim beige bags contain 1 light cyan bag, 3 faded plum bags. +dull black bags contain 2 striped black bags, 5 wavy brown bags, 1 bright red bag, 1 drab teal bag. +pale turquoise bags contain 5 vibrant violet bags, 3 dotted fuchsia bags, 2 striped blue bags, 4 posh purple bags. +wavy red bags contain 3 drab teal bags. +faded gold bags contain 5 dull lavender bags. +faded black bags contain 5 wavy turquoise bags, 5 mirrored crimson bags. +bright orange bags contain 2 striped maroon bags, 4 light cyan bags, 5 light silver bags, 5 wavy indigo bags. +drab teal bags contain 4 wavy aqua bags, 5 light bronze bags, 1 drab red bag. +dull salmon bags contain 4 dull orange bags. +bright lavender bags contain 2 plaid silver bags, 3 bright crimson bags. +drab cyan bags contain 2 bright bronze bags, 5 bright crimson bags, 2 wavy yellow bags. +dull plum bags contain 3 shiny lavender bags, 2 bright magenta bags, 2 mirrored crimson bags, 4 mirrored silver bags. +dotted teal bags contain 3 muted yellow bags, 3 dotted turquoise bags, 5 mirrored white bags. +vibrant turquoise bags contain 5 clear magenta bags, 5 dark beige bags, 2 vibrant tan bags, 3 plaid blue bags. +pale crimson bags contain 2 bright turquoise bags, 4 dark lime bags. +pale plum bags contain 1 shiny chartreuse bag, 3 vibrant gold bags, 5 plaid violet bags, 5 dim salmon bags. +mirrored lime bags contain 2 plaid green bags. +pale lavender bags contain 5 dotted gold bags, 1 striped maroon bag, 3 shiny tan bags, 5 drab white bags. +muted olive bags contain 3 drab crimson bags, 2 dotted gray bags, 5 dotted tomato bags, 3 posh bronze bags. +drab brown bags contain 3 dull orange bags, 4 posh gold bags, 2 pale crimson bags, 1 plaid white bag. +bright tan bags contain 1 dark white bag, 5 bright turquoise bags. +faded indigo bags contain 3 pale yellow bags, 2 mirrored brown bags, 1 shiny gray bag, 5 bright turquoise bags. +dark aqua bags contain 1 posh gray bag, 4 striped coral bags, 2 posh olive bags, 2 bright white bags. +light tan bags contain 2 faded purple bags, 5 muted fuchsia bags. +dark magenta bags contain 4 posh silver bags, 5 pale plum bags, 5 muted violet bags, 2 faded green bags. +clear maroon bags contain 3 muted maroon bags, 1 clear olive bag, 2 faded black bags. +posh purple bags contain 4 faded orange bags, 4 shiny salmon bags. +bright gold bags contain 1 dull crimson bag, 1 shiny lavender bag. +dull purple bags contain 3 clear silver bags, 1 drab aqua bag, 3 wavy beige bags. +muted cyan bags contain 1 plaid green bag. +vibrant yellow bags contain 3 faded plum bags, 4 vibrant lavender bags, 2 muted magenta bags. +vibrant green bags contain 5 dim chartreuse bags, 2 posh lavender bags. +plaid bronze bags contain 4 dim tomato bags, 3 shiny silver bags. +striped blue bags contain 5 vibrant gold bags. +plaid coral bags contain 4 faded purple bags, 3 drab turquoise bags, 1 light teal bag, 2 posh indigo bags. +posh turquoise bags contain 5 posh cyan bags, 5 mirrored violet bags. +faded crimson bags contain 2 plaid salmon bags, 1 striped magenta bag, 1 striped maroon bag. +striped purple bags contain 1 drab violet bag, 2 pale maroon bags, 2 drab beige bags, 4 faded maroon bags. +clear orange bags contain 5 dotted red bags, 4 mirrored red bags. +striped fuchsia bags contain 2 bright tomato bags, 4 dull magenta bags. +wavy purple bags contain 5 wavy olive bags, 3 shiny silver bags. +dotted crimson bags contain 1 striped teal bag, 5 shiny tomato bags. +dull lavender bags contain 1 dotted tomato bag, 3 wavy indigo bags, 1 faded silver bag. +dotted magenta bags contain 3 dotted coral bags. +drab silver bags contain 5 dark indigo bags, 4 bright bronze bags, 1 dim lime bag, 3 bright aqua bags. +clear cyan bags contain 1 bright maroon bag. +shiny beige bags contain 2 plaid beige bags, 2 striped magenta bags, 4 drab yellow bags, 4 muted yellow bags. +dim turquoise bags contain 2 dull tan bags. +drab coral bags contain 4 striped bronze bags, 3 dull orange bags, 5 plaid silver bags. +light lavender bags contain 1 wavy plum bag, 4 posh purple bags. +posh yellow bags contain 3 dark lime bags, 3 light cyan bags, 4 dull crimson bags. +posh violet bags contain 2 faded chartreuse bags. +shiny teal bags contain 5 mirrored salmon bags, 1 wavy plum bag, 3 posh purple bags, 2 posh cyan bags. +vibrant lime bags contain 1 dotted tomato bag, 1 drab fuchsia bag, 1 mirrored brown bag. +dark fuchsia bags contain 1 vibrant blue bag. +bright green bags contain 4 dark purple bags, 4 bright tan bags, 5 drab turquoise bags. +dull coral bags contain 2 dotted tomato bags. +posh white bags contain 3 dull bronze bags, 1 faded salmon bag, 3 pale tomato bags, 3 vibrant salmon bags. +plaid black bags contain 4 vibrant aqua bags, 2 shiny teal bags. +posh lavender bags contain 4 wavy beige bags, 1 dim silver bag, 2 faded white bags. +posh orange bags contain 4 dim orange bags, 3 faded chartreuse bags. +plaid brown bags contain 5 shiny fuchsia bags, 5 striped magenta bags, 2 wavy coral bags, 1 vibrant beige bag. +shiny plum bags contain 3 light green bags, 4 bright orange bags. +dim aqua bags contain 4 faded gold bags, 1 dotted lavender bag, 3 light gold bags, 4 shiny aqua bags. +wavy gold bags contain 4 clear violet bags, 5 dim red bags, 5 drab crimson bags, 2 dull coral bags. +vibrant tomato bags contain 3 faded olive bags. +bright silver bags contain 2 dull lavender bags, 4 faded aqua bags, 4 dim coral bags. +wavy turquoise bags contain 4 dull lavender bags, 1 drab aqua bag. +wavy aqua bags contain 3 wavy yellow bags. +light indigo bags contain 5 dim beige bags, 3 drab fuchsia bags, 1 plaid violet bag, 5 bright yellow bags. +striped red bags contain 3 bright violet bags, 5 dark indigo bags, 5 dim silver bags. +posh lime bags contain 5 striped teal bags, 3 dark brown bags, 4 bright crimson bags, 2 posh violet bags. +faded magenta bags contain 5 light gold bags, 1 posh indigo bag, 3 plaid lime bags. +vibrant lavender bags contain 5 faded maroon bags, 3 striped orange bags, 3 dull crimson bags. +clear purple bags contain 5 dark green bags, 3 light cyan bags, 3 clear white bags, 4 pale silver bags. +muted purple bags contain 5 drab fuchsia bags, 1 vibrant salmon bag, 5 bright yellow bags. +bright lime bags contain 5 vibrant violet bags, 5 wavy maroon bags. +bright black bags contain 5 dark silver bags, 2 vibrant green bags. +muted magenta bags contain no other bags. +striped tomato bags contain 4 shiny gold bags. +pale black bags contain 3 dull brown bags, 2 wavy coral bags, 2 posh purple bags, 4 faded beige bags. +dim red bags contain 1 dotted tomato bag, 2 wavy beige bags. +light black bags contain 4 dull maroon bags, 3 dotted aqua bags, 3 drab purple bags. +shiny turquoise bags contain 3 dull blue bags, 4 posh bronze bags. +pale indigo bags contain 4 dotted tomato bags. +shiny white bags contain 5 vibrant tomato bags, 4 dotted magenta bags, 3 dull aqua bags. +dark lavender bags contain 4 faded orange bags. +shiny brown bags contain 3 bright orange bags, 2 dotted crimson bags, 2 wavy aqua bags. +light chartreuse bags contain 1 muted lavender bag. +faded aqua bags contain 4 dull green bags, 4 faded violet bags, 4 clear gray bags. +light olive bags contain 4 shiny purple bags, 3 shiny plum bags. +wavy indigo bags contain 3 dim green bags, 5 shiny lavender bags, 3 posh olive bags, 1 dull crimson bag. +dull tomato bags contain 3 light coral bags, 2 light cyan bags, 3 plaid silver bags. +clear turquoise bags contain 1 wavy crimson bag, 4 dim tomato bags. +dim tomato bags contain 5 shiny lavender bags, 2 dim gold bags. +wavy black bags contain 4 wavy chartreuse bags, 4 dull coral bags. +dotted maroon bags contain 5 pale violet bags, 5 vibrant aqua bags, 5 plaid cyan bags. +clear lavender bags contain 2 dotted turquoise bags, 4 light purple bags, 1 plaid plum bag. +dotted cyan bags contain 2 dotted turquoise bags, 4 plaid gold bags, 5 drab red bags, 5 faded orange bags. +muted violet bags contain 3 light teal bags, 2 striped gold bags. +wavy silver bags contain 2 dim coral bags, 1 shiny chartreuse bag, 4 shiny turquoise bags. +drab crimson bags contain 2 drab beige bags. +dull aqua bags contain 4 striped maroon bags, 5 vibrant beige bags, 3 faded gold bags, 3 dark lime bags. +vibrant coral bags contain 4 faded gold bags, 2 dotted black bags, 5 drab tomato bags. +pale beige bags contain 1 dotted coral bag. +dim olive bags contain 5 clear gray bags, 2 muted violet bags, 3 clear gold bags, 4 shiny red bags. +dim cyan bags contain 4 plaid silver bags. +muted bronze bags contain 4 wavy yellow bags, 1 vibrant yellow bag, 5 dim tomato bags, 2 mirrored silver bags. +dim gold bags contain 2 dim green bags, 4 shiny tomato bags, 4 striped white bags, 4 mirrored crimson bags. +vibrant gray bags contain 4 dotted turquoise bags, 4 posh violet bags. +plaid orange bags contain 2 dotted turquoise bags. +posh magenta bags contain 4 dotted lime bags. +light silver bags contain 5 shiny gold bags, 3 dull tan bags. +bright plum bags contain 5 pale magenta bags, 5 dull aqua bags. +drab red bags contain 1 dim gold bag. +striped salmon bags contain 1 vibrant lavender bag, 3 wavy crimson bags, 5 posh olive bags. +dotted purple bags contain 3 dull lavender bags. +bright violet bags contain 2 dotted indigo bags, 4 shiny violet bags. +muted red bags contain 2 mirrored silver bags. +dotted green bags contain 5 muted plum bags. +clear lime bags contain no other bags. +wavy gray bags contain 1 posh cyan bag, 5 dim bronze bags, 5 posh lime bags, 4 drab silver bags. +dotted brown bags contain 4 striped tomato bags. +plaid indigo bags contain 1 plaid purple bag, 3 dark turquoise bags, 3 light purple bags, 5 dotted cyan bags. +mirrored olive bags contain 5 bright gold bags, 3 dotted gold bags, 4 drab gray bags, 4 drab tomato bags. +wavy green bags contain 3 mirrored indigo bags, 4 wavy chartreuse bags, 2 clear cyan bags, 5 bright violet bags. +light gray bags contain 4 vibrant yellow bags, 2 dull blue bags. +posh plum bags contain 3 wavy yellow bags, 5 dim yellow bags, 2 clear chartreuse bags. +posh bronze bags contain 2 clear lime bags. +bright indigo bags contain 4 muted salmon bags, 2 posh violet bags. +mirrored violet bags contain 1 faded plum bag, 3 dull orange bags. +muted silver bags contain 3 mirrored indigo bags, 4 shiny fuchsia bags. +striped coral bags contain 2 posh turquoise bags. +plaid tomato bags contain 1 wavy beige bag, 5 muted green bags. +dark gold bags contain 1 clear gold bag, 2 light maroon bags, 3 pale teal bags. +light green bags contain 1 dull aqua bag, 4 dotted magenta bags, 4 dull purple bags. +plaid lime bags contain 1 faded fuchsia bag. +muted beige bags contain 1 dotted coral bag, 1 plaid fuchsia bag, 2 posh bronze bags. +pale red bags contain 2 wavy gold bags, 1 striped lavender bag. +striped lime bags contain 1 wavy turquoise bag, 4 dim aqua bags. +muted black bags contain 3 dotted black bags. +faded brown bags contain 1 dim turquoise bag, 2 plaid brown bags. +plaid blue bags contain 2 muted salmon bags. +muted indigo bags contain 2 dull fuchsia bags, 2 dull lime bags. +dark coral bags contain 2 faded indigo bags, 3 shiny tomato bags, 2 mirrored salmon bags. +vibrant beige bags contain 4 vibrant lavender bags. +mirrored bronze bags contain 1 mirrored orange bag, 5 plaid red bags, 1 mirrored cyan bag. +shiny red bags contain 1 bright yellow bag. +light crimson bags contain 5 plaid crimson bags, 3 pale white bags, 3 drab fuchsia bags, 3 muted olive bags. +drab blue bags contain 1 mirrored black bag, 3 striped fuchsia bags, 3 drab tan bags. +striped violet bags contain 2 muted gray bags, 5 faded white bags, 5 striped black bags, 3 mirrored tomato bags. +wavy maroon bags contain 2 light cyan bags, 3 muted teal bags, 2 vibrant lavender bags. +pale brown bags contain 2 wavy black bags. +bright aqua bags contain 3 plaid tan bags. +muted plum bags contain 5 light bronze bags, 1 dotted beige bag, 3 vibrant cyan bags. +posh green bags contain 4 faded lime bags, 1 dull coral bag, 4 mirrored silver bags. +dark beige bags contain 3 wavy yellow bags, 5 dim salmon bags. +light fuchsia bags contain 4 plaid coral bags. +shiny tan bags contain 2 drab tan bags, 4 clear gray bags, 2 mirrored crimson bags, 1 vibrant beige bag. +clear crimson bags contain 3 vibrant aqua bags, 4 dotted indigo bags. +clear beige bags contain 4 posh olive bags, 4 bright lime bags, 3 dark green bags. +dim gray bags contain 1 drab beige bag, 3 clear tomato bags, 2 mirrored fuchsia bags. +light violet bags contain 3 plaid purple bags. +faded silver bags contain 5 striped bronze bags, 4 dotted lavender bags. +dotted white bags contain 5 drab green bags. +shiny purple bags contain 3 posh turquoise bags, 2 dark brown bags. +posh blue bags contain 2 vibrant chartreuse bags, 2 muted olive bags, 4 dull brown bags, 5 wavy magenta bags. +striped cyan bags contain 1 pale plum bag, 3 dim maroon bags, 5 light salmon bags, 3 dim crimson bags. +shiny tomato bags contain no other bags. +plaid aqua bags contain 4 clear maroon bags, 4 plaid white bags, 2 posh chartreuse bags. +pale magenta bags contain 5 muted teal bags, 1 vibrant lavender bag. +dim plum bags contain 4 drab coral bags. +drab beige bags contain 4 wavy crimson bags, 1 dull tan bag, 3 dotted tomato bags. +wavy coral bags contain 1 mirrored yellow bag, 1 dull tan bag, 5 drab gold bags, 2 muted bronze bags. +drab violet bags contain 4 faded maroon bags, 2 posh gold bags, 3 wavy maroon bags, 3 bright lime bags. +light aqua bags contain 5 light bronze bags, 1 light tan bag, 1 dull beige bag. +light orange bags contain 1 dark tan bag, 3 dim white bags, 3 plaid plum bags. +pale chartreuse bags contain 3 pale violet bags, 1 drab fuchsia bag, 1 shiny indigo bag, 2 dull turquoise bags. +faded chartreuse bags contain 4 vibrant lime bags, 3 drab tomato bags, 1 vibrant violet bag, 1 vibrant tomato bag. +clear chartreuse bags contain 2 dotted plum bags, 1 muted brown bag, 2 wavy chartreuse bags, 4 faded green bags. +dotted silver bags contain 3 mirrored yellow bags. +dotted violet bags contain 4 muted turquoise bags, 4 light black bags. +wavy orange bags contain 3 shiny fuchsia bags, 4 clear beige bags. +dark red bags contain 1 faded salmon bag, 3 muted purple bags. +dim bronze bags contain 2 clear turquoise bags. +light turquoise bags contain 5 dark red bags. +muted green bags contain 5 bright turquoise bags, 2 wavy coral bags, 3 faded chartreuse bags. +vibrant violet bags contain 3 wavy indigo bags, 1 dotted gray bag, 4 vibrant beige bags. +dull cyan bags contain 3 light maroon bags, 2 posh plum bags. +muted aqua bags contain 2 dotted beige bags, 2 faded yellow bags, 3 plaid gray bags, 3 bright chartreuse bags. +dark tomato bags contain 2 striped purple bags, 2 dark maroon bags, 2 dim silver bags. +vibrant blue bags contain 4 dull orange bags. +faded violet bags contain 2 vibrant lavender bags, 5 plaid plum bags, 4 bright magenta bags, 4 faded silver bags. +bright salmon bags contain 1 dull crimson bag, 2 light maroon bags. +vibrant aqua bags contain 4 dotted aqua bags, 3 vibrant gray bags, 3 dotted lavender bags. +striped plum bags contain 2 mirrored lime bags, 2 dark salmon bags. +plaid gold bags contain 4 dark lime bags, 3 drab aqua bags, 3 dim white bags, 2 mirrored brown bags.
\ No newline at end of file diff --git a/2020/07/puzzle-1.py b/2020/07/puzzle-1.py new file mode 100755 index 0000000..da054b8 --- /dev/null +++ b/2020/07/puzzle-1.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + + +bdict: dict[str, list[str]] = {} + +# Recursively check if a bag can hold a shiny gold bag +def holds_bag(innerbags: list[str]) -> bool: + if "no other" in innerbags: + return False + elif "shiny gold" in innerbags: + return True + + for subbag in innerbags: + if holds_bag(bdict[subbag]): + return True + + +def main() -> None: + global bdict + with open("input", "r") as f: + lines = f.readlines() + + for baginfo in lines: + data = baginfo.split(" bags contain") + + # { bag_name: [contained_bag_1, containted_bag_2, ...] } + bdict[data[0]] = [" ".join(b.split(" ")[-3:][:2]) for b in data[1].split(",")] + + count = 0 + for bag in bdict: + if holds_bag(bdict[bag]): + count += 1 + + print(count) + + +if __name__ == "__main__": + main() diff --git a/2020/07/puzzle-2.py b/2020/07/puzzle-2.py new file mode 100755 index 0000000..c87ea13 --- /dev/null +++ b/2020/07/puzzle-2.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + + +bdict: dict[str, list[str]] = {} + +# Recursively find the number of sub-bags in a bag +def total_bags(innerbags: list[dict[int, str]]) -> int: + if innerbags[0]["name"] == "no other": + return 0 + + return sum([bag["count"] + bag["count"] * total_bags(bdict[bag["name"]]) for bag in innerbags]) + + +def main() -> None: + with open("input", "r") as f: + lines = f.readlines() + + for baginfo in lines: + data = baginfo.split(" bags contain") + + # { bag_name: [{ count: n, name: bag_name_ }, ...] } + bdict[data[0]] = [] + for b in data[1].split(","): + bdict[data[0]].append( + { + "count": int(b.replace("no", "0").split(" ")[1]), + "name": " ".join(b.split(" ")[-3:][:2]), + } + ) + + print(total_bags(bdict["shiny gold"])) + + +if __name__ == "__main__": + main() diff --git a/2020/08/.gitignore b/2020/08/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/08/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/08/Makefile b/2020/08/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/08/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/08/input b/2020/08/input new file mode 100644 index 0000000..49eb92d --- /dev/null +++ b/2020/08/input @@ -0,0 +1,653 @@ +acc +9 +acc -2 +acc -12 +acc +33 +jmp +301 +nop +508 +jmp +216 +acc +27 +acc +35 +acc +43 +acc +31 +jmp +309 +acc +18 +acc -19 +acc +7 +jmp +44 +acc -13 +acc -17 +acc +31 +jmp +311 +nop +612 +jmp +143 +acc +22 +nop +85 +jmp +458 +acc -3 +jmp +13 +acc -19 +acc +27 +acc +12 +jmp +483 +acc +40 +acc +6 +jmp +128 +jmp +10 +acc +0 +acc -3 +acc -2 +jmp -11 +acc +43 +acc -12 +jmp +158 +acc +0 +jmp +240 +jmp +1 +acc +5 +acc +15 +jmp +187 +nop +563 +jmp +51 +acc -16 +jmp +158 +jmp +322 +acc +47 +nop -1 +jmp +299 +acc +26 +acc +25 +jmp +232 +jmp -9 +acc +15 +jmp +54 +jmp +558 +acc +7 +acc -7 +jmp +399 +nop +447 +jmp +71 +acc +26 +acc +46 +jmp +145 +acc +38 +acc +30 +acc +21 +jmp +263 +acc +10 +jmp +168 +acc +22 +nop +561 +jmp -26 +jmp +1 +acc -7 +jmp -5 +acc +28 +acc -6 +jmp +370 +jmp +94 +acc +50 +acc +42 +acc -9 +acc +30 +jmp +70 +acc +29 +jmp +166 +acc -5 +acc -18 +nop +84 +acc +2 +jmp +366 +jmp -40 +acc -4 +acc -15 +acc -1 +jmp +169 +jmp +1 +acc -4 +acc +0 +jmp -45 +nop -21 +nop +241 +acc -18 +acc +19 +jmp +26 +nop -51 +jmp +260 +acc +17 +jmp +428 +acc +6 +jmp +405 +acc +22 +acc +10 +nop +471 +jmp +352 +acc -6 +acc +48 +acc +7 +acc +3 +jmp +57 +acc -10 +acc +16 +acc +16 +acc +43 +jmp +432 +acc -5 +acc +0 +nop +339 +acc +49 +jmp +17 +acc +33 +nop +166 +acc -5 +jmp +392 +nop +246 +acc -7 +acc +21 +acc +30 +jmp +398 +acc +36 +acc +24 +acc -15 +acc -9 +jmp +114 +acc +19 +jmp +11 +acc +43 +nop +182 +jmp -129 +nop -29 +acc -6 +acc +2 +jmp +398 +jmp +78 +acc +36 +jmp +393 +acc +15 +nop -11 +acc -7 +acc -9 +jmp +76 +acc +0 +acc +27 +jmp +25 +acc +27 +nop -54 +jmp +458 +acc +3 +acc +29 +acc -4 +acc +43 +jmp +413 +acc +33 +acc +13 +jmp +382 +jmp -83 +acc +42 +acc +24 +jmp +64 +acc +23 +acc -13 +nop +110 +acc -5 +jmp +114 +jmp +113 +nop +112 +acc +26 +jmp -133 +jmp -12 +jmp +1 +jmp +330 +acc +25 +acc -1 +acc +30 +acc +42 +jmp -187 +jmp +1 +acc +20 +acc +35 +acc +36 +jmp -125 +jmp +165 +acc +28 +acc -17 +acc -12 +jmp +1 +jmp -120 +nop +1 +acc +2 +acc +26 +jmp +398 +acc +20 +acc -1 +jmp -127 +acc +36 +acc +14 +jmp +1 +jmp +331 +acc +50 +acc +1 +acc -10 +nop +159 +jmp -83 +jmp +374 +acc +17 +jmp +372 +acc +44 +nop -39 +jmp +228 +acc +17 +jmp +74 +acc +16 +acc +33 +acc -2 +jmp +152 +jmp +29 +acc +8 +acc +27 +nop +59 +jmp -32 +acc +28 +jmp -227 +nop -35 +jmp -168 +acc +13 +nop +390 +jmp -204 +acc +16 +acc +44 +jmp -230 +jmp +25 +acc +30 +jmp +383 +acc -11 +acc +38 +acc +11 +jmp +341 +acc +35 +acc +46 +acc -1 +jmp +94 +acc -4 +acc +12 +jmp +111 +jmp +133 +nop +283 +acc +13 +acc +37 +jmp +74 +nop -218 +jmp -178 +acc +46 +acc +25 +acc -5 +jmp -174 +acc +28 +acc +39 +acc +36 +acc +22 +jmp -172 +acc +19 +jmp -250 +nop +62 +acc +44 +nop +347 +acc +40 +jmp +345 +acc -3 +acc -13 +acc -11 +jmp +56 +jmp -180 +acc +17 +acc -4 +acc +46 +nop -165 +jmp +321 +acc -4 +jmp +1 +acc +9 +acc -12 +jmp -155 +acc +5 +jmp -96 +acc +0 +acc -2 +acc +38 +jmp +67 +acc -4 +nop -283 +acc +28 +jmp +324 +acc -9 +acc +43 +acc -1 +acc +9 +jmp -290 +acc +3 +acc +22 +nop +84 +acc -17 +jmp -210 +acc +7 +jmp -260 +nop -232 +nop +87 +acc +43 +acc +36 +jmp +96 +jmp +238 +acc +13 +acc -14 +acc +32 +acc +11 +jmp -146 +acc +13 +acc +37 +acc -10 +jmp +187 +acc +49 +acc +15 +jmp -234 +jmp -328 +jmp -136 +jmp +143 +jmp +1 +acc +27 +acc +22 +jmp +1 +jmp -5 +acc +30 +nop -7 +acc -6 +jmp -71 +acc -17 +acc +15 +jmp -52 +jmp -126 +acc -4 +jmp +151 +jmp +52 +nop -86 +acc +25 +jmp +187 +nop -22 +jmp -219 +acc +33 +nop -120 +acc +0 +jmp +215 +acc +46 +acc +38 +jmp +1 +jmp -262 +jmp +157 +acc -15 +acc +48 +acc +39 +acc +10 +jmp -137 +acc +47 +acc +50 +jmp -324 +nop +214 +acc +39 +jmp -178 +acc +49 +acc -10 +jmp -268 +jmp +50 +acc -14 +nop -100 +jmp +20 +acc +45 +acc -12 +acc -4 +jmp -208 +acc -19 +jmp -340 +acc +36 +nop -358 +acc +5 +jmp -348 +acc +47 +nop -18 +acc -12 +jmp -131 +acc +19 +acc +10 +acc +19 +acc +31 +jmp -164 +nop +162 +nop -260 +jmp +146 +acc +32 +acc -1 +nop -14 +jmp -192 +acc +3 +acc +31 +nop -185 +jmp -208 +jmp -69 +acc +43 +acc +43 +jmp -68 +acc -16 +acc +5 +acc -9 +jmp +126 +acc +33 +acc +2 +acc +34 +acc -9 +jmp -16 +acc +34 +acc -19 +jmp -266 +nop +135 +nop -389 +acc +33 +jmp -195 +acc +48 +jmp +1 +acc -12 +jmp +143 +nop -317 +acc -14 +nop -127 +acc +32 +jmp -372 +acc +24 +nop -41 +nop -42 +jmp -344 +acc +23 +nop +117 +nop +92 +acc +42 +jmp +143 +acc +48 +acc -6 +nop -272 +acc -13 +jmp -379 +acc -2 +acc +44 +acc +9 +jmp -369 +acc +6 +acc +25 +acc +34 +jmp -301 +nop -227 +acc +43 +jmp -141 +acc +12 +acc +41 +acc +17 +acc -11 +jmp +29 +jmp -121 +acc +6 +acc +7 +acc +7 +jmp +131 +nop +144 +nop -142 +acc -13 +acc -18 +jmp +149 +acc +14 +acc +49 +acc +25 +acc -17 +jmp -9 +acc +26 +acc -4 +jmp -230 +acc -18 +acc +36 +acc +27 +nop -142 +jmp +21 +acc +34 +nop +54 +jmp -476 +acc +10 +jmp -174 +nop -354 +acc +1 +jmp -324 +acc +40 +jmp +94 +acc -12 +jmp -136 +nop -454 +acc -14 +jmp +116 +acc +12 +acc -1 +nop -453 +jmp -241 +jmp -479 +acc -19 +jmp -87 +acc +27 +acc +48 +acc +0 +jmp -476 +acc +16 +acc +46 +jmp -534 +acc +0 +jmp -344 +acc +0 +acc +28 +jmp +10 +jmp -248 +nop -186 +jmp +1 +acc +26 +jmp -153 +acc +14 +acc -8 +nop -416 +jmp -91 +jmp -409 +jmp -326 +acc +2 +acc +8 +acc -18 +acc +33 +jmp -468 +jmp -175 +acc -7 +acc +45 +jmp -18 +jmp -375 +acc -8 +jmp +28 +acc -16 +nop -38 +acc +37 +acc +48 +jmp -343 +acc +10 +acc +26 +acc -9 +acc -16 +jmp -348 +acc +37 +jmp -453 +acc -2 +acc +27 +acc +17 +acc +28 +jmp -406 +acc +25 +acc +24 +acc +44 +acc +44 +jmp -532 +acc +10 +jmp -531 +acc +39 +acc +40 +jmp -284 +acc +19 +acc +3 +nop -533 +acc -3 +jmp -162 +nop -438 +acc -5 +jmp -114 +acc +45 +acc +1 +acc +28 +acc +9 +jmp -550 +jmp -222 +jmp -106 +acc -7 +nop -263 +nop -375 +jmp -381 +acc -4 +nop -223 +jmp -171 +jmp -465 +acc -2 +nop -562 +jmp -190 +acc +40 +jmp -4 +acc +30 +acc +21 +jmp -435 +acc +1 +acc +10 +jmp +1 +jmp -157 +acc -7 +acc +18 +acc -3 +acc +24 +jmp -113 +acc +21 +jmp -339 +acc +34 +jmp -563 +acc +27 +jmp -589 +jmp -61 +acc +35 +acc +50 +acc +8 +jmp -553 +acc +48 +acc -15 +acc +29 +acc +24 +jmp +1
\ No newline at end of file diff --git a/2020/08/puzzles.c b/2020/08/puzzles.c new file mode 100644 index 0000000..cfa9389 --- /dev/null +++ b/2020/08/puzzles.c @@ -0,0 +1,112 @@ +#include <err.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define LINECOUNT 653 + +struct Inst { + char opp; + int val; +}; + +/* Check if the given instruction has been executed already */ +static bool +repeati(int const * const lines, int const rip) +{ + for (int i = 0; i < LINECOUNT; i++) { + if (lines[i] == rip) + return true; + } + return false; +} + +static int +run_circuit(struct Inst *circuit) +{ + int i, acc, rip; + int lines[LINECOUNT] = {0}; + + i = acc = rip = 0; + + /* Execute the circuit */ + do { + lines[i++] = rip; + switch (circuit[rip].opp) { + case 'j': + rip += circuit[rip].val; + if (rip >= LINECOUNT) + return acc; + break; + case 'a': + acc += circuit[rip].val; + /* FALLTHROUGH */ + case 'n': + rip++; + break; + } + } while (!repeati(lines, rip)); + +#ifdef PART2 + return -1; +#else + return acc; +#endif +} + +int +main(void) +{ + int i = 0; + char cl[10]; + FILE *fp; + struct Inst circuit[LINECOUNT]; + + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + /* Load the entire circuit */ + while (fgets(cl, sizeof(cl), fp)) { + char *val; + /* struct Inst operation; */ + + val = strtok(cl, " "); + circuit[i++] = (struct Inst) { + .opp = cl[0], + .val = atoi(strtok(NULL, " ")) + }; + } + fclose(fp); + + int result = -1; +#ifdef PART2 + int count, prev_count; + count = prev_count = 1; + + /* Run circuit until it completes successfully */ + while (result == -1 && count < LINECOUNT) { + for (i = 0; i < LINECOUNT; i++) { + if (circuit[i].opp == 'j' || circuit[i].opp == 'n') + count--; + + /* Swap jmp and nop */ + if (!count) { + circuit[i].opp = (circuit[i].opp == 'j') ? 'n' : 'j'; + break; + } + } + + count = ++prev_count; + result = run_circuit(circuit); + + /* Return to original array */ + circuit[i].opp = (circuit[i].opp == 'j') ? 'n' : 'j'; + } +#else + result = run_circuit(circuit); +#endif + + printf("%d\n", result); + return EXIT_SUCCESS; +} diff --git a/2020/09/input b/2020/09/input new file mode 100644 index 0000000..b6fbe43 --- /dev/null +++ b/2020/09/input @@ -0,0 +1,1000 @@ +42 +27 +23 +19 +4 +26 +31 +29 +11 +49 +38 +9 +45 +1 +40 +46 +39 +28 +44 +16 +13 +5 +32 +17 +50 +12 +20 +6 +7 +10 +22 +14 +18 +60 +59 +8 +19 +9 +11 +15 +21 +23 +39 +24 +25 +16 +26 +13 +29 +17 +27 +28 +20 +35 +30 +31 +22 +32 +44 +33 +38 +47 +34 +36 +37 +41 +55 +64 +40 +42 +43 +46 +39 +45 +61 +48 +50 +52 +65 +62 +53 +67 +72 +69 +70 +74 +73 +98 +86 +76 +79 +81 +108 +84 +82 +91 +160 +153 +93 +253 +100 +102 +105 +115 +175 +166 +151 +149 +142 +218 +147 +152 +162 +155 +161 +163 +165 +173 +255 +184 +191 +193 +293 +195 +357 +252 +295 +220 +257 +404 +289 +291 +322 +294 +314 +415 +343 +316 +318 +324 +328 +512 +364 +517 +379 +384 +511 +636 +615 +574 +472 +477 +509 +644 +1021 +605 +585 +608 +610 +800 +634 +640 +1122 +642 +1255 +692 +841 +893 +981 +763 +1313 +1586 +1046 +949 +986 +1057 +1062 +1094 +1444 +1300 +2393 +1193 +1250 +1244 +1274 +1475 +1282 +1405 +1334 +1533 +1585 +1604 +1744 +2467 +1712 +2986 +2043 +2193 +2255 +2048 +3250 +2338 +2287 +2437 +3711 +2443 +2526 +2494 +2518 +2556 +3382 +2938 +2990 +3527 +4149 +5876 +4660 +4993 +4050 +4724 +4091 +4236 +4241 +4303 +4781 +4625 +4730 +4805 +4880 +4937 +5432 +7280 +9717 +5074 +5494 +9027 +5928 +9505 +7577 +8966 +8141 +8286 +8291 +13021 +12377 +10162 +9535 +8544 +13907 +14235 +14459 +9610 +9685 +19222 +17294 +10506 +18637 +18683 +14040 +33262 +22526 +21882 +15718 +17751 +16427 +16432 +16835 +35110 +28293 +18079 +19050 +28322 +34586 +30339 +40277 +19295 +26520 +20191 +24546 +26224 +26933 +29758 +33090 +47837 +34506 +34914 +32553 +64269 +34178 +52868 +62471 +35885 +37374 +37129 +38270 +38345 +96649 +39486 +43841 +57636 +70898 +44737 +46415 +68387 +66887 +74155 +71307 +85211 +66731 +67059 +67467 +68438 +110684 +82300 +73014 +80622 +74230 +76615 +75399 +106217 +77831 +152678 +126074 +116044 +91152 +111624 +113474 +141117 +133618 +133790 +138366 +134198 +173276 +142668 +157699 +135905 +158453 +206696 +212520 +147244 +157237 +365198 +152014 +239548 +168983 +191305 +224942 +202776 +254591 +276458 +272564 +247092 +267408 +267816 +402014 +301121 +292651 +278573 +506956 +283149 +293142 +304481 +309251 +494139 +565215 +320997 +343319 +441547 +371759 +785529 +449868 +692756 +457367 +537740 +592400 +514500 +761848 +546389 +711265 +561722 +1157615 +585793 +571715 +846991 +1100293 +597623 +874466 +715078 +778364 +881059 +784866 +793187 +813306 +821627 +907235 +1452774 +971867 +995107 +1157508 +1060889 +1076222 +1118104 +1108111 +1340086 +1370659 +1169338 +1183416 +1375987 +1634933 +1508265 +1419250 +1493442 +1499944 +2407179 +1665925 +1578053 +1889528 +1720541 +1728862 +1879102 +1966974 +2400975 +3213983 +2230227 +2137111 +3457155 +2448197 +3379046 +2352754 +2539997 +3306915 +2993386 +5013979 +2912692 +2919194 +3085175 +3071495 +3165869 +3243978 +3545027 +3298594 +5846912 +3449403 +3607964 +3846076 +4104085 +4940972 +4367338 +4489865 +6764070 +4800951 +4892751 +5265446 +5271948 +6362095 +5831886 +6291980 +6237364 +5984187 +6615272 +6156670 +6315473 +6409847 +6542572 +7144670 +11945621 +8593950 +9606073 +7454040 +7950161 +8471423 +9382616 +17777507 +9290816 +11103834 +10537394 +10158197 +17211067 +12654075 +11816073 +18200023 +17719106 +12140857 +12299660 +14106831 +12472143 +16148645 +12952419 +13687242 +15094831 +15404201 +15925463 +16744856 +23009537 +17240977 +26306842 +20695591 +19828210 +20394650 +21641228 +21974270 +39754393 +23956930 +36543295 +24115733 +24440517 +24771803 +37045429 +25252079 +25424562 +29216999 +33515452 +41177542 +28782073 +30499032 +42169418 +54455962 +33985833 +37069187 +37936568 +44600013 +40523801 +40222860 +42035878 +59019699 +53988802 +57631185 +54206635 +48556250 +54034152 +50196365 +50023882 +50676641 +54469078 +58940014 +57999072 +104652327 +69305874 +59281105 +64484865 +71055020 +105132603 +82536581 +80746661 +78159428 +155328968 +82258738 +88779110 +104665443 +159121405 +98580132 +130814988 +98752615 +99232891 +100220247 +123424879 +100700523 +169617468 +112468150 +213328040 +117280177 +135539885 +217798623 +123765970 +142644293 +149214448 +163283242 +158906089 +160418166 +166938538 +171037848 +255112443 +138879426 +197332747 +197813023 +197985506 +231035235 +241046147 +388836471 +340655316 +213168673 +277698343 +282085618 +236234120 +252820062 +278184178 +266410263 +262645396 +272980418 +288093874 +364271285 +297785515 +299297592 +305817964 +550739270 +503150711 +336212173 +700483458 +395145770 +570179492 +411154179 +444203908 +449402793 +465988735 +822999554 +524327994 +637251703 +489054182 +498879516 +515465458 +551164596 +585879389 +535625814 +700963734 +587391466 +597083107 +785614966 +635509765 +893209430 +1004519640 +900208361 +959669366 +806299949 +1137043985 +1229818874 +1897729070 +893606701 +1059953808 +955042917 +987933698 +1013382176 +1014344974 +1024679996 +1034505330 +1121505203 +1336473499 +1621763103 +1810294962 +1601602747 +1497291468 +1953163238 +2428063052 +1441809714 +1959562557 +1706508310 +1699906650 +2922409066 +1819682125 +1881540399 +1907951675 +1848649618 +1906988877 +1942976615 +1968425093 +2001315874 +3927987650 +2048850304 +2734411980 +2156010533 +2618796671 +2778283213 +2939101182 +3043412461 +3148318024 +4436392650 +3141716364 +7069704014 +3555157928 +3406414960 +3519588775 +3817074711 +4098987148 +5821695674 +3730190017 +3755638495 +7572713206 +6878508041 +3911401708 +6548131324 +4779599087 +5353208651 +4204860837 +4774807204 +5095111715 +7317816668 +5919999577 +7578109014 +6191730485 +10966537689 +6958791075 +6661305139 +6926003735 +6961572888 +9299972552 +7249778792 +7485828512 +10459533032 +13150521560 +10396591322 +8979668041 +9558069488 +8116262545 +8686208912 +10128015855 +13461016116 +11130864572 +11286842200 +9869918919 +11015111292 +12111730062 +16465496553 +20419807191 +20573180780 +13920363963 +15077835433 +13587308874 +14211351680 +25537368465 +28059009292 +14735607304 +15602091057 +19973051112 +17674332033 +16802471457 +17095930586 +17986181464 +18244278400 +18556127831 +19997934774 +23126841354 +20885030211 +24605526223 +21981648981 +38975935022 +28577226615 +27507672837 +27798660554 +28131715643 +28322916178 +54053770455 +35340208986 +29813442737 +30337698361 +31831537890 +41979583755 +32404562514 +36230459864 +33898402043 +41113022818 +37980960797 +39441158042 +45108490335 +79093983615 +42866679192 +44011871565 +45490556434 +46587175204 +53813186871 +56084899452 +69435938996 +55306333391 +63138869540 +69238611029 +58660614539 +70385523311 +60151141098 +62742260875 +62169236251 +65729939933 +66302964557 +68635022378 +70128861907 +73339560085 +86603579252 +77422118839 +164025698091 +86878550757 +88357235626 +100400362075 +89502427999 +233461637087 +101893508595 +109119520262 +129587080094 +113966947930 +115457474489 +118811755637 +120829850790 +121402875414 +199715942001 +122320377349 +127899176184 +128472200808 +175422484819 +134937986935 +141974582463 +143468421992 +164300669596 +165779354465 +166924546838 +187278912832 +216465630851 +214367310005 +235369823344 +191395936594 +211013028857 +246710931821 +223086468192 +232778703567 +326333923529 +236860349903 +287182229879 +242232726204 +366640488839 +306275252059 +257258364284 +522740882910 +357835731997 +276912569398 +278406408927 +332703901303 +739206513761 +355696606190 +380146664470 +354203459670 +642878836069 +402408965451 +405763246599 +414482404786 +760244697448 +599419192406 +919791405467 +459946818095 +632609175588 +479093076107 +660478711729 +499491090488 +690539633300 +534170933682 +535664773211 +679321534849 +555318978325 +609616470701 +756612425121 +812577342609 +932123093709 +734350124140 +1140391361918 +1150486451395 +1851914499176 +1096302879899 +808172212050 +820245651385 +874429222881 +939039894202 +959437908583 +1632822993994 +1089489912007 +1394828835869 +978584166595 +2611407160589 +1033662024170 +1069835706893 +1695710340243 +1687006565490 +1164935449026 +1289669102465 +1343966594841 +1490962549261 +2524624573431 +1972701918372 +1542522336190 +1628417863435 +1682601434931 +1694674874266 +1897662124057 +1747212106252 +2717907775442 +1813469117083 +2103975343228 +2661185601526 +2012246190765 +2048419873488 +2103497731063 +2859610323292 +2729372364413 +2198597473196 +2234771155919 +3338088975953 +2454604551491 +2508902043867 +3091178701093 +3868591168272 +4466850742256 +3170940199625 +3237197210456 +3225123771121 +3311019298366 +3377276309197 +3441886980518 +3560681223335 +3759458297017 +6921455293747 +4048240273002 +5490306854006 +4060666064253 +4871856514057 +4689375707410 +5536686449149 +4927969837609 +4433368629115 +4707499517063 +5325949857012 +4963506595358 +10092395493372 +7502553044771 +7878439716688 +6396063970746 +6536143069487 +6408137410081 +7820124361270 +10727676815892 +7070477595383 +8249132823254 +8268180740398 +7621347287588 +11115636927144 +8481608902117 +8108906337255 +8494034693368 +8750041771663 +9122744336525 +9140868146178 +9361338466724 +9396875224473 +11103563487809 +9671006112421 +10289456452370 +11359570566104 +12804201380827 +14414582786175 +14890098664114 +12932207040233 +12944280479568 +13478615005464 +15179383932638 +14691824882971 +20226307824334 +16115381980956 +15730253624843 +16102956189705 +16590515239372 +17231650673780 +16602941030623 +26282816386291 +18502206612902 +24030966810292 +18537743370651 +18758213691197 +19067881336894 +19960462564791 +29535148070856 +21649027018474 +24163771946931 +27983585313465 +25876487519801 +27834379143682 +26410822045697 +26422895485032 +28170439888435 +41102646928668 +30422078507814 +32705897220328 +42141075670540 +31833209814548 +35733857286682 +37192113238571 +33834591704403 +35105147643525 +37039949983553 +37295957061848 +37605624707545 +37826095028091 +38718676255988 +39028343901685 +41609489583265 +45812798965405 +65266418875599 +50040259466732 +66702261569453 +52287309565498 +56004819032117 +52833717530729 +54593335373467 +58592518396249 +66155935794496 +62255288322362 +64539107034876 +65667801518951 +84666927345277
\ No newline at end of file diff --git a/2020/09/puzzle-1.py b/2020/09/puzzle-1.py new file mode 100755 index 0000000..f68fc21 --- /dev/null +++ b/2020/09/puzzle-1.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from typing import List + + +def is_valid(nums: List[int], lp: int, up: int) -> bool: + for i in range(lp, up): + x = nums[up] - nums[i] + if x in nums[lp:up] and x != nums[i]: + return True + return False + + +def main() -> None: + with open("input", "r") as f: + nums = list(map(int, f.readlines())) + + lp = 0 + up = 25 + + while is_valid(nums, lp, up): + lp += 1 + up += 1 + + print(nums[up]) + + +if __name__ == "__main__": + main() diff --git a/2020/09/puzzle-2.py b/2020/09/puzzle-2.py new file mode 100755 index 0000000..8833f50 --- /dev/null +++ b/2020/09/puzzle-2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import numpy as np + + +def main() -> None: + goal = 138879426 + with open("input", "r") as f: + nums = np.array(list(map(int, f.readlines())), dtype=int) + + lp = 0 + up = 1 + + while (x := sum(nums[lp : up + 1])) != goal: + if x > goal: + up -= 1 + lp += 1 + elif x < goal: + up += 1 + + sorted = np.sort(nums[lp : up + 1]) + print(sorted[0] + sorted[-1]) + + +if __name__ == "__main__": + main() diff --git a/2020/10/input b/2020/10/input new file mode 100644 index 0000000..379b145 --- /dev/null +++ b/2020/10/input @@ -0,0 +1,108 @@ +147 +174 +118 +103 +67 +33 +96 +28 +43 +22 +16 +138 +75 +148 +35 +6 +10 +169 +129 +115 +21 +52 +58 +79 +46 +7 +139 +104 +91 +51 +172 +57 +49 +126 +95 +149 +125 +123 +112 +30 +78 +44 +37 +167 +157 +29 +173 +98 +36 +63 +111 +160 +18 +8 +9 +159 +179 +72 +110 +2 +53 +150 +17 +81 +97 +108 +102 +56 +135 +166 +168 +163 +1 +25 +3 +158 +101 +132 +144 +45 +140 +34 +156 +178 +105 +68 +153 +80 +82 +59 +50 +122 +69 +85 +109 +40 +124 +119 +94 +88 +13 +180 +177 +133 +66 +134 +60 +141 diff --git a/2020/10/puzzle-1.sh b/2020/10/puzzle-1.sh new file mode 100755 index 0000000..f31af02 --- /dev/null +++ b/2020/10/puzzle-1.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +sort -n input | awk ' +BEGIN { o = t = 1 } +NR > 1 { if ($0 - prev == 1) o++; else if ($0 - prev == 3) t++; } + { prev = $0 } +END { print o * t }' diff --git a/2020/10/puzzle-2.py b/2020/10/puzzle-2.py new file mode 100755 index 0000000..bdf7bbf --- /dev/null +++ b/2020/10/puzzle-2.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +from typing import List + +adaptors: list[str] + + +def combos(i: int, counts: dict[int, dict[int, int]] = {}) -> int: + if i == len(adaptors) - 1: + return 1 + if i in counts: + return counts[i] + + ans = 0 + for j in range(i + 1, len(adaptors)): + if adaptors[j] - adaptors[i] <= 3: + ans += combos(j, counts) + + counts[i] = ans + return ans + + +def main() -> None: + global adaptors + with open("input", "r") as f: + adaptors = list(map(int, f.readlines())) + + adaptors.append(0) + adaptors.sort() + adaptors.append(max(adaptors) + 3) + + print(combos(0)) + + +if __name__ == "__main__": + main() diff --git a/2020/11/.gitignore b/2020/11/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/11/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/11/Makefile b/2020/11/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/11/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/11/input b/2020/11/input new file mode 100644 index 0000000..a586f62 --- /dev/null +++ b/2020/11/input @@ -0,0 +1,98 @@ +LLLLLL.LLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL +LLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LL +LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.L.LLLLLL.LL.LLLLLL +LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLL.LLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL +LLLLL..LLLLLLLLLLLLLLLLLL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LLLL.LLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLL..LLLLLLLLL +LLL..L..LLLL.LLL.L......L...LL.L..L.L...L...LL....L.L.L.L................L....L..L...L......LLL.L. +LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL..LLLLL.LLLLLLLL.LLLL.LLLLLLL.LLLLLLLL..LLLLLLL.LLLLLLLLLLLLLLLLLL +LLLLLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LL.LLLLLLLL.LLLLLL.LLLLLLLLLL.LLLLLLLLL +.LLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLL.LLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL +LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLL..LLLLLLLL.LLLLLLLL.LLLLLLLL.L.LLLLLLL +LLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLL.LLLLL.LL.LLLLLLLLLLLLLLLLLL +LLLLLL.LLLLLL.LLLLL.LLLL.LL.LLLLL.LLLLL.LLLLLLLL..LLL.LLLLL.L.LLLLLLLLLLLLLLLLL.LLL.LLLL.LLLLLLLLL +LL.LLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LL.LLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLL.LLL.L.LL.LLLLLLLLLLL.LLLLLL +LLLLLLLLLLLLL.LLLLL..LLLLLLLLLLLLLLLLLL.L.LLLLLL.LLLL.LLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLL +.LLLLL..L.L.L...L...L..LL.L.L.LL.L...L.L.L...................LL..L...L......L..L.........L.....LL. +LLLL.LLLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLLL.LL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LLLLL.LLLLLLL.LLLLL.LLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLL.LLLLL.LLL +LLLLLLLLLLLLL.LLLLL.L.LLLLL.LLLLLLLLLLL.LLLLLLLLLL.LL.LLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL +LLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLL.LLLLLLLL.LLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL +LLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLL.LLLLLLLL.LLLL.LLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL +LLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLL.L.LLLLLL.LLLLLLLLLLLLLLLLL. +LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL
\ No newline at end of file diff --git a/2020/11/puzzles.c b/2020/11/puzzles.c new file mode 100644 index 0000000..7c579b9 --- /dev/null +++ b/2020/11/puzzles.c @@ -0,0 +1,158 @@ +#include <err.h> +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> + +#define ROWCNT 98 +#define ROWLEN 98 + +#ifdef PART2 + #define IS_SEAT(a, b) \ + if (rows[a][b] == '.') \ + continue + #define IS_OCC(a, b) \ + if (rows[a][b] == '#') \ + adjecent++ +#endif + +bool changed; +char rows[ROWCNT][ROWLEN + 1]; +char temp[ROWCNT][ROWLEN + 1]; + +/* Check and update a seat at the given index */ +static void +check_seat(int const i, int const j) +{ + if (rows[i][j] == '.') + return; + + int adjecent = 0; + +#ifdef PART2 + /* Up */ + for (int h = i - 1; h >= 0; h--) { + IS_SEAT(h, j); + IS_OCC(h, j); + break; + } + /* Down */ + for (int h = i + 1; h < ROWCNT; h++) { + IS_SEAT(h, j); + IS_OCC(h, j); + break; + } + /* Left */ + for (int h = j - 1; h >= 0; h--) { + IS_SEAT(i, h); + IS_OCC(i, h); + break; + } + /* Right */ + for (int h = j + 1; h < ROWLEN; h++) { + IS_SEAT(i, h); + IS_OCC(i, h); + break; + } + /* Up-Left */ + for (int h = i - 1, k = j - 1; h >= 0 && k >= 0; h--, k--) { + IS_SEAT(h, k); + IS_OCC(h, k); + break; + } + /* Up-Right */ + for (int h = i - 1, k = j + 1; h >= 0 && k < ROWLEN; h--, k++) { + IS_SEAT(h, k); + IS_OCC(h, k); + break; + } + /* Down-Left */ + for (int h = i + 1, k = j - 1; h < ROWCNT && k >= 0; h++, k--) { + IS_SEAT(h, k); + IS_OCC(h, k); + break; + } + /* Down-Right */ + for (int h = i + 1, k = j + 1; h < ROWCNT && k < ROWLEN; h++, k++) { + IS_SEAT(h, k); + IS_OCC(h, k); + break; + } +#else + for (int h = i - 1; h <= i + 1; h++) { + if (h < 0 || h > ROWCNT - 1) + continue; + for (int k = j - 1; k <= j + 1; k++) { + if (k < 0 || k > ROWCNT - 1 || (h == i && k == j)) + continue; + if (rows[h][k] == '#') + adjecent++; + } + } +#endif + /* Edit seats as needed */ + if (rows[i][j] == 'L' && adjecent == 0) { + temp[i][j] = '#'; + changed = true; +#ifdef PART2 + } else if (rows[i][j] == '#' && adjecent >= 5) { +#else + } else if (rows[i][j] == '#' && adjecent >= 4) { +#endif + temp[i][j] = 'L'; + changed = true; + } else + temp[i][j] = rows[i][j]; +} + +int +main(void) +{ + /* Initialize the temp array to be all floor */ + int i, j; + for (i = 0; i < ROWCNT; i++) { + for (j = 0; j < ROWLEN; j++) + temp[i][j] = '.'; + } + + FILE *fp; + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + /* Read in seats */ + i = j = 0; + char c; + while ((c = fgetc(fp)) != EOF) { + if (c == '\n') { + i = 0; + j++; + } else + rows[j][i++] = c; + } + fclose(fp); + + /* Update the seats until they don't change anymore */ + do { + changed = false; + for (i = 0; i < ROWCNT; i++) { + for (j = 0; j < ROWLEN; j++) + check_seat(i, j); + } + + for (i = 0; i < ROWCNT; i++) { + for (j = 0; j < ROWLEN; j++) + rows[i][j] = temp[i][j]; + } + } while (changed); + + /* Calculate filled seats */ + int count = 0; + for (i = 0; i < ROWCNT; i++) { + for (j = 0; j < ROWLEN; j++) { + if (rows[i][j] == '#') + count++; + } + } + + printf("%d\n", count); + return EXIT_SUCCESS; +} diff --git a/2020/12/.gitignore b/2020/12/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/12/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/12/Makefile b/2020/12/Makefile new file mode 100644 index 0000000..cf466dc --- /dev/null +++ b/2020/12/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzle-1.c + ${CC} ${CFLAGS} -o puzzle-2 puzzle-2.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/12/input b/2020/12/input new file mode 100644 index 0000000..5e5e7be --- /dev/null +++ b/2020/12/input @@ -0,0 +1,778 @@ +R90 +N2 +N2 +F94 +R90 +E3 +F2 +L90 +L90 +F66 +S5 +L90 +W3 +R90 +N3 +W2 +N2 +W1 +R90 +E3 +F100 +S4 +F66 +R180 +F96 +R90 +N2 +R90 +E2 +S3 +E1 +F65 +W4 +F6 +L180 +W2 +L90 +F95 +L90 +F97 +E2 +F36 +E2 +R90 +E4 +F98 +N4 +F70 +S1 +R270 +E1 +F13 +R90 +W1 +L90 +F82 +S2 +R90 +N2 +F80 +N1 +R90 +F26 +W4 +F23 +S5 +F72 +N5 +W2 +N5 +F47 +L270 +F18 +W1 +L90 +F91 +R90 +W5 +N2 +F60 +E5 +S3 +R90 +R180 +S3 +L90 +W4 +F80 +S2 +L90 +F31 +W1 +L90 +F45 +S3 +F64 +N1 +W4 +N2 +R180 +W3 +R90 +S1 +F7 +W1 +R180 +W1 +S4 +E4 +W4 +F87 +R90 +N5 +F65 +W4 +F15 +E5 +N5 +L90 +F36 +E1 +F70 +E1 +L180 +F42 +L90 +F9 +L90 +E4 +F2 +F35 +N4 +E4 +N2 +L90 +N4 +R90 +F100 +S3 +F13 +E1 +S4 +F66 +L90 +F75 +E5 +R180 +E2 +L90 +W4 +F89 +S5 +R90 +E4 +F5 +R270 +E3 +S5 +R90 +F65 +S5 +R180 +S3 +W4 +F68 +W1 +F62 +W1 +F99 +F96 +R90 +E1 +R90 +L180 +F96 +W4 +N2 +W2 +R90 +F32 +N1 +E1 +L90 +E1 +S3 +F6 +S4 +E1 +N2 +W5 +S5 +E4 +F3 +F58 +N1 +F96 +E5 +F31 +R90 +F74 +R180 +N2 +W1 +F65 +L90 +F45 +F73 +R90 +S1 +R270 +N5 +L90 +W1 +N3 +L90 +F36 +R90 +N4 +L180 +W4 +N5 +R180 +N1 +R90 +N1 +R270 +F80 +R90 +S5 +E3 +F49 +W5 +F27 +E1 +N2 +W4 +S3 +L90 +F100 +N1 +F28 +E2 +F88 +S1 +R90 +F14 +S4 +L180 +F93 +E1 +L90 +F64 +L90 +L90 +F84 +E4 +F69 +W1 +R90 +E5 +N2 +W1 +N3 +F10 +S2 +F64 +F10 +R180 +W3 +N1 +F82 +S2 +W1 +R90 +W1 +L90 +W2 +N3 +F95 +E4 +N3 +N2 +E3 +E1 +N1 +W5 +R90 +W3 +S3 +E3 +L90 +W3 +N5 +F61 +S3 +F50 +F71 +E1 +E1 +F63 +L90 +W5 +S1 +R90 +F29 +L90 +S1 +R90 +S1 +L90 +W4 +N4 +R270 +S1 +F87 +R90 +F82 +W1 +L90 +S4 +L90 +W2 +N4 +R90 +F61 +R90 +N5 +F38 +W3 +L90 +F56 +N1 +R90 +W1 +S2 +F97 +S5 +R90 +E1 +F97 +R270 +N2 +L180 +F14 +E1 +R90 +F70 +L180 +S4 +E3 +L90 +N3 +F87 +E3 +N3 +R90 +F59 +F18 +W5 +F71 +E3 +S5 +W3 +R180 +F71 +S3 +W5 +F47 +N5 +L90 +F79 +N3 +F40 +W5 +S2 +F59 +W3 +F2 +W1 +F63 +R90 +S4 +L90 +S1 +E5 +F33 +L180 +F83 +E5 +S3 +W1 +F66 +R270 +N4 +F29 +W5 +F83 +W1 +R90 +N5 +W3 +F58 +S4 +R90 +F36 +S1 +F67 +W1 +S4 +F56 +E2 +F88 +N4 +L90 +F71 +W3 +F88 +R180 +F50 +R90 +E4 +R90 +S1 +W2 +L90 +N1 +R90 +E5 +N1 +F39 +L180 +E5 +R90 +W4 +L180 +W3 +R90 +W3 +L90 +S5 +W5 +S2 +L90 +N3 +W5 +R180 +F74 +E1 +N1 +N4 +R90 +N2 +W4 +F34 +L90 +E4 +L90 +S4 +L90 +W3 +F83 +N1 +L90 +F58 +W5 +F38 +L180 +N1 +L90 +S4 +F45 +E4 +S3 +L90 +E1 +S2 +F30 +E2 +L90 +F84 +W4 +F53 +R90 +S5 +F31 +L180 +N1 +L90 +E2 +L180 +W3 +F98 +R270 +S2 +E5 +F84 +S4 +L90 +F26 +E2 +F66 +L270 +E1 +L180 +F11 +E5 +L90 +W1 +F11 +E3 +F70 +E5 +N3 +F78 +W5 +L270 +W5 +N1 +L90 +S4 +F8 +L90 +F95 +L90 +F99 +S3 +F61 +N2 +F84 +S5 +F3 +E5 +R90 +F33 +W5 +S1 +L90 +F52 +E4 +L90 +E1 +N1 +L270 +S3 +W4 +R180 +F89 +R270 +F10 +R90 +N1 +R180 +W5 +N2 +F78 +S5 +F25 +S4 +F25 +N3 +F29 +W1 +F24 +S4 +L90 +S5 +F17 +L90 +S4 +E2 +N3 +F38 +S4 +L90 +F1 +L90 +E2 +F92 +L90 +E4 +S1 +E1 +F28 +N1 +F46 +R90 +N1 +W4 +N3 +E3 +F90 +N5 +L180 +S1 +E3 +F96 +L90 +E1 +R90 +N5 +E1 +F74 +L180 +N2 +L90 +N1 +E4 +R90 +E1 +S2 +F91 +R90 +N5 +E4 +F9 +N2 +E1 +F13 +E2 +S4 +W1 +R90 +S1 +R90 +F18 +L90 +F12 +S2 +F65 +N2 +E3 +F65 +E1 +L180 +E2 +S4 +W4 +F89 +N4 +E5 +L180 +N4 +W1 +F22 +L90 +W2 +S2 +F6 +E4 +F74 +N2 +E2 +S1 +R90 +F87 +W5 +R90 +W4 +R90 +E4 +L90 +N3 +F68 +L180 +N1 +W1 +F81 +R90 +F95 +R90 +R180 +E5 +F51 +F23 +F74 +N3 +F16 +F64 +L90 +W4 +R90 +R90 +W4 +F97 +R180 +N3 +F79 +E3 +L90 +N2 +F14 +S4 +F41 +W2 +L90 +F54 +N3 +E4 +R90 +W2 +R90 +S4 +L90 +L90 +S4 +R90 +E4 +S3 +L90 +F5 +R90 +L90 +W2 +R90 +W3 +N4 +E5 +F14 +E5 +S4 +F96 +S4 +L90 +W2 +F96 +L90 +E3 +L90 +F4 +R90 +F61 +E2 +F56 +E1 +F100 +E5 +R90 +F54 +R90 +E4 +F2 +R180 +S3 +F8 +L90 +W1 +R90 +F19 +W5 +L90 +S1 +L90 +W5 +S2 +F30 +R90 +W5 +F31 +S5 +E1 +N2 +F100 +N1 +F3 +W3 +F46 +R90 +E2 +F62 +L180 +F90 +L180 +S3 +L90 +S5 +F40 +N4 +F95
\ No newline at end of file diff --git a/2020/12/puzzle-1.c b/2020/12/puzzle-1.c new file mode 100644 index 0000000..1a4c7ab --- /dev/null +++ b/2020/12/puzzle-1.c @@ -0,0 +1,73 @@ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int +main(void) +{ + FILE *fp; + char cl[5]; + int north, east; + int direction = 0; + + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + north = east = 0; + while (fgets(cl, sizeof(cl), fp) != NULL) { + switch (cl[0]) { + case 'N': + north += atoi(&cl[1]); + break; + case 'E': + east += atoi(&cl[1]); + break; + case 'S': + north -= atoi(&cl[1]); + break; + case 'W': + east -= atoi(&cl[1]); + break; + case 'L': + direction -= atoi(&cl[1]); + goto wrap; + case 'R': + direction += atoi(&cl[1]); + +wrap: + /* 0 <= direction < 360 */ + if (direction >= 360) + direction -= 360; + else if (direction < 0) + direction += 360; + break; + case 'F': + switch (direction) { + case 0: + east += atoi(&cl[1]); + break; + case 90: + north -= atoi(&cl[1]); + break; + case 180: + east -= atoi(&cl[1]); + break; + case 270: + north += atoi(&cl[1]); + break; + } + break; + } + } + fclose(fp); + + /* Absolute value */ + if (north < 0) + north = -north; + if (east < 0) + east = -east; + + printf("%d\n", north + east); + return EXIT_SUCCESS; +} diff --git a/2020/12/puzzle-2.c b/2020/12/puzzle-2.c new file mode 100644 index 0000000..8ac34b4 --- /dev/null +++ b/2020/12/puzzle-2.c @@ -0,0 +1,79 @@ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +struct coords { + int north; + int east; +}; + +int +main(void) +{ + FILE *fp; + char cl[6]; + struct coords waypoint = {1, 10}; + struct coords ship = {0, 0}; + + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + while (fgets(cl, sizeof(cl), fp) != NULL) { + switch (cl[0]) { + case 'N': + waypoint.north += atoi(&cl[1]); + break; + case 'E': + waypoint.east += atoi(&cl[1]); + break; + case 'S': + waypoint.north -= atoi(&cl[1]); + break; + case 'W': + waypoint.east -= atoi(&cl[1]); + break; + case 'F':; + unsigned int const val = atoi(&cl[1]); + ship.north += val * waypoint.north; + ship.east += val * waypoint.east; + break; + /* Left and right */ + default:; + int direction = atoi(&cl[1]); + + /* (x, y) -> (-x, -y) */ + if (direction == 180) { + waypoint.north = -waypoint.north; + waypoint.east = -waypoint.east; + break; + } + + /* 0 <= direction < 360 */ + if (cl[0] == 'R') + direction = -direction + 360; + + int const temp = waypoint.east; + if (direction == 90) { + /* (x, y) -> (-y, x) */ + waypoint.east = -waypoint.north; + waypoint.north = temp; + } else { + /* (x, y) -> (y, -x) */ + waypoint.east = waypoint.north; + waypoint.north = -temp; + } + break; + } + } + fclose(fp); + + /* Absolute value */ + if (ship.north < 0) + ship.north = -ship.north; + if (ship.east < 0) + ship.east = -ship.east; + + printf("%d\n", ship.north + ship.east); + return EXIT_SUCCESS; +} diff --git a/2020/13/input b/2020/13/input new file mode 100644 index 0000000..59d4d66 --- /dev/null +++ b/2020/13/input @@ -0,0 +1,2 @@ +1006401 +17,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,449,x,x,x,x,x,x,x,23,x,x,x,x,13,x,x,x,x,x,19,x,x,x,x,x,x,x,x,x,x,x,607,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,29
\ No newline at end of file diff --git a/2020/13/puzzle-1.py b/2020/13/puzzle-1.py new file mode 100755 index 0000000..7b21f96 --- /dev/null +++ b/2020/13/puzzle-1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + + +def main() -> None: + with open("input", "r") as f: + time = int(f.readline()) + ids = list(map(int, f.readline().replace(",x", "").split(","))) + + ids.sort() + + min = -1 + x = 0 + for bus in ids: + res = (time + ids[0]) % bus + if min < res < ids[0]: + min = res + x = bus + + for i in range(time, time + ids[0]): + if i % x == 0: + print((i - time) * x) + break + + +if __name__ == "__main__": + main() diff --git a/2020/13/puzzle-2.py b/2020/13/puzzle-2.py new file mode 100755 index 0000000..3965488 --- /dev/null +++ b/2020/13/puzzle-2.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +from functools import reduce + + +def chinese_remainder(n: tuple[int, ...], a: tuple[int, ...]) -> int: + sum = 0 + prod = reduce(lambda a, b: a * b, n) + for n_i, a_i in zip(n, a): + p = prod // n_i + sum += a_i * mul_inv(p, n_i) * p + return sum % prod + + +def mul_inv(a: int, b: int) -> int: + b0 = b + x0, x1 = 0, 1 + if b == 1: + return 1 + while a > 1: + q = a // b + a, b = b, a % b + x0, x1 = x1 - q * x0, x0 + if x1 < 0: + x1 += b0 + return x1 + + +def main() -> None: + with open("input", "r") as f: + ids = tuple(map(lambda x: int(x) if x.isdigit() else x, f.readlines()[1].split(","))) + + buses = tuple(filter(lambda x: x != "x", ids)) + modres = tuple(x if (x := bus - ids.index(bus)) != bus else 0 for bus in buses) + + print(chinese_remainder(buses, modres)) + + +if __name__ == "__main__": + main() diff --git a/2020/14/input b/2020/14/input new file mode 100644 index 0000000..11570c1 --- /dev/null +++ b/2020/14/input @@ -0,0 +1,578 @@ +mask = 00X10101X110010011XX0X011X100000X010 +mem[13197] = 47579321 +mem[37394] = 374943 +mem[48509] = 418284 +mem[29793] = 191792725 +mask = 00100X001010010111XX010X10X01100001X +mem[378] = 9637 +mem[41083] = 1858241 +mem[36394] = 762 +mem[40101] = 15295 +mem[50670] = 9179863 +mem[30384] = 164245 +mem[11676] = 393669095 +mask = 0XX000X1111001010X10XX1101XX00X00100 +mem[17956] = 854 +mem[57595] = 179871 +mem[50596] = 207644327 +mask = X100XX0111X0X1X01101X0X0110010101011 +mem[26867] = 1012 +mem[3061] = 514891024 +mem[35973] = 512 +mask = 01X000111110010X1110X00110000X00000X +mem[3707] = 123619 +mem[37107] = 7325808 +mem[31906] = 102168 +mask = XX00XX0101100X011100000XX00100000X00 +mem[38336] = 2917310 +mem[7166] = 313228 +mem[41771] = 2741721 +mem[52154] = 89454 +mask = 11001111X110X0XX10XX11101111000X0111 +mem[35611] = 58725 +mem[40227] = 8442431 +mem[10029] = 7334 +mem[13345] = 87327004 +mask = 0XX0X0001010011011010XX0X110XX01X001 +mem[4868] = 493430 +mem[40452] = 18191 +mem[4567] = 330532 +mem[13580] = 1662243 +mask = 001X00011000X1X0X1X0110X110111001011 +mem[2096] = 25174 +mem[15283] = 994663544 +mem[16002] = 1359 +mem[4240] = 704816 +mask = 01000011101001001010110X10011X11XX01 +mem[16210] = 279177 +mem[8996] = 6470256 +mem[31049] = 1371071 +mem[20425] = 9683526 +mem[24986] = 142094045 +mask = 0X001X01X1X0110X10XX0X01X00101111010 +mem[61471] = 23661 +mem[57520] = 246980 +mem[57446] = 4169790 +mask = 001000X11110010111X000X00X0011X01001 +mem[25460] = 1461 +mem[528] = 48572826 +mem[61442] = 1487 +mem[60708] = 1804 +mem[51588] = 36111 +mask = 0X000001111001010X1011100100001X0X0X +mem[45713] = 3807909 +mem[26867] = 6236 +mem[39186] = 3023142 +mem[46212] = 5671589 +mem[28686] = 10375260 +mask = 00X0000XXX10X1011100X100001X0X100010 +mem[7272] = 1073 +mem[35482] = 1877478 +mask = 01X00XX11110X11X110X1000010XXX101110 +mem[28892] = 2154970 +mem[33403] = 34104 +mem[56124] = 11230 +mem[11265] = 484054168 +mem[36422] = 1080979 +mask = 00000001X11001X1110001X01000101XXXX0 +mem[8445] = 2387 +mem[55775] = 8215 +mask = 110001101110110X10010X00XX1X01010100 +mem[49202] = 4152007 +mem[49938] = 4676666 +mem[58184] = 43886544 +mem[35840] = 8484248 +mem[25642] = 1980350 +mem[37918] = 1692542 +mem[44918] = 43860354 +mask = 0X000X011110010X1100X10X100X1X111100 +mem[24669] = 15051033 +mem[43432] = 1054 +mem[64706] = 21834 +mem[27336] = 773822 +mem[24406] = 420 +mask = 00XX01111X1001001X0001101001111101XX +mem[48221] = 256859 +mem[1361] = 145480785 +mem[8221] = 32962081 +mem[11649] = 327597066 +mem[6355] = 3866 +mem[33696] = 951794 +mask = X10XX0010110011010111100X010X000000X +mem[51014] = 577 +mem[38304] = 7416 +mem[34256] = 3748 +mem[12926] = 306 +mem[39297] = 1823498 +mask = 0000X00XXX10011XX000000X10X010100001 +mem[18788] = 7298 +mem[39644] = 7675 +mem[33093] = 416832 +mem[5195] = 6722351 +mem[28000] = 53707945 +mem[5336] = 77314873 +mem[992] = 134079888 +mask = 0000X101110X010011X0000000X011X1X101 +mem[8536] = 401336 +mem[1632] = 1267 +mem[6456] = 581 +mem[31682] = 20542 +mem[27729] = 726 +mem[49447] = 37811 +mask = 0X0X00111XX001XX111X1011010X100X0111 +mem[38677] = 9808 +mem[54045] = 28545 +mem[30384] = 49811 +mem[62515] = 19422 +mem[14508] = 49363 +mask = X100X1X1011X1111011X01101000X11XX101 +mem[59468] = 387 +mem[37138] = 121701873 +mem[18728] = 2624430 +mem[28293] = 5039090 +mem[32321] = 839768 +mem[28535] = 647 +mask = XX100X0010100XX1110X11000110X100X00X +mem[2147] = 1562 +mem[25832] = 275992750 +mask = 110XX0X10110X11X10X1110X10100X000000 +mem[22152] = 470276298 +mem[60732] = 716 +mem[52727] = 1427169 +mem[16196] = 9596060 +mem[3910] = 28432777 +mask = 01X0001111100X101110110X011XXX01X011 +mem[8221] = 60956 +mem[1223] = 293 +mem[24130] = 777493 +mem[62002] = 3900 +mem[20316] = 26105612 +mem[58295] = 528344031 +mem[12465] = 1159 +mask = 11000X011110010010011100100XX111100X +mem[59580] = 3601634 +mem[31173] = 325319 +mem[28284] = 2285676 +mem[57595] = 8662764 +mem[32672] = 4111107 +mask = 01000001X1100101XX0X01101X1X00011X0X +mem[33093] = 4612 +mem[61749] = 5692 +mem[28188] = 26420039 +mem[59026] = 1325 +mem[37032] = 149 +mask = 01000X11111001X11110011X111X01100X01 +mem[23793] = 131971 +mem[10420] = 848652 +mem[10469] = 33394600 +mem[23001] = 1875 +mask = 01001111011X1X1XXX1X001XX11100011X10 +mem[38294] = 371641 +mem[17261] = 72227824 +mem[41143] = 213405737 +mem[54246] = 1445548 +mem[41901] = 1849824 +mask = 0X00110X01101100XX101011001110XX1101 +mem[42925] = 176752065 +mem[17255] = 12010392 +mem[37437] = 64942 +mem[57253] = 827582 +mask = 11X10X101111XX0010X10101100100010110 +mem[14344] = 6638562 +mem[40266] = 89477554 +mem[9511] = 1133 +mem[53072] = 748643130 +mem[4567] = 372 +mem[26565] = 4739 +mask = 00010XX1X11X010X11X000100111001X1110 +mem[4247] = 17837 +mem[18674] = 2031700 +mem[47487] = 89684677 +mask = 110X1X11011X101110111101XX01001100X0 +mem[22046] = 3445 +mem[55657] = 29187 +mem[38510] = 159862 +mask = 0100000X11X00100110X01101X0011001100 +mem[12772] = 3394234 +mem[30255] = 47301946 +mem[55181] = 11825301 +mem[2096] = 239 +mem[6355] = 66264 +mem[62103] = 62751352 +mask = X100010XXX10X1001110001001X10X100X0X +mem[18880] = 12756 +mem[52727] = 58449492 +mem[52620] = 106260805 +mask = 01000X011110010XX110X11001100X000XXX +mem[5734] = 3770 +mem[46419] = 12806425 +mem[26866] = 6566928 +mask = X1001XX101101X1X10111X0X1111001101X0 +mem[54847] = 8045 +mem[61036] = 1672 +mem[32929] = 87423486 +mem[48539] = 13896 +mem[14353] = 7009065 +mem[16446] = 32987614 +mask = 00100000X111110X1110X101100000100X00 +mem[23863] = 4070 +mem[52234] = 498973 +mem[20235] = 1706949 +mask = 00X000011110X100110X11100X0X10X01010 +mem[44286] = 26378 +mem[30741] = 14368000 +mem[7396] = 88194752 +mask = 0X001X01X11011X0101X1010XX01X01000X0 +mem[6834] = 2670580 +mem[15903] = 6945101 +mem[10104] = 2517 +mem[65020] = 61602027 +mem[55142] = 1143278 +mem[38596] = 1333 +mem[17509] = 153504934 +mask = 00XX0X01111XX10111X00X10X0111011110X +mem[568] = 1625 +mem[30255] = 248279 +mem[11912] = 538 +mem[12028] = 520033 +mask = 0010XX011X00X10011X001XX1100X1000001 +mem[15654] = 120 +mem[4292] = 57554 +mem[2096] = 346664 +mem[1248] = 10995 +mem[48539] = 656539 +mem[19181] = 147211 +mask = 1010010X110001001100X1X00X0011010X01 +mem[11344] = 4845730 +mem[60639] = 25030928 +mem[1005] = 12960528 +mem[47688] = 107547855 +mem[17509] = 728745 +mask = X00000011X10X10X11000101101000000100 +mem[46621] = 1608 +mem[5562] = 15064109 +mem[28385] = 1651 +mem[5734] = 288099689 +mem[49319] = 97558812 +mem[37739] = 1161 +mem[52727] = 1992490 +mask = 0001010XX110010X110000X01X10X011XX1X +mem[37366] = 735085354 +mem[1739] = 409 +mem[12604] = 754989 +mask = 00000X011110010011000X001X0100XX0000 +mem[29851] = 8508 +mem[44133] = 1998890 +mem[24804] = 6068 +mem[59260] = 1198469 +mem[59580] = 10413954 +mask = 00110111X01X010010X00000X10X00110110 +mem[55579] = 418284890 +mem[7573] = 1800 +mem[26096] = 1469134 +mem[44133] = 25531796 +mem[39628] = 7076590 +mask = 0000000111X0010111X001011XX0000X1X00 +mem[24778] = 24875864 +mem[10420] = 3072761 +mem[2096] = 2762 +mem[30148] = 6696 +mem[17770] = 13204967 +mask = 0011010101X00X0X1100X000110011100101 +mem[57742] = 21044093 +mem[33266] = 56667 +mem[61442] = 1636 +mem[51870] = 1018197644 +mem[40469] = 77760 +mask = X0X001XX11000X0011X00100010011X00X01 +mem[11504] = 438885 +mem[53777] = 6130 +mem[17770] = 808014 +mask = 000X001111100101XX100010X010X1100100 +mem[35611] = 1215 +mem[10397] = 301 +mem[10866] = 8375216 +mem[2499] = 10472 +mem[63504] = 270966 +mem[7719] = 2064 +mem[41088] = 343764913 +mask = 010X1X00X1X0X1101X0X00111101001X0101 +mem[20597] = 773 +mem[14657] = 294987038 +mask = 00XX0001X110010111100000X01010100111 +mem[43170] = 365 +mem[55657] = 4882105 +mem[44170] = 628956 +mem[10429] = 947957 +mem[272] = 36059 +mask = 0X000011X0X0010X1X1011110100101XXXX1 +mem[3910] = 2312 +mem[47735] = 89421 +mem[2197] = 32972549 +mem[49938] = 7005 +mask = 00000100X100X100111X0101011X11010101 +mem[54400] = 830 +mem[43977] = 2412350 +mem[18229] = 19157634 +mem[19181] = 879884567 +mask = 000101X11X100100X100011X000100110001 +mem[37237] = 104037633 +mem[29167] = 1094 +mem[6308] = 6007 +mem[21610] = 80462437 +mem[2261] = 345450311 +mask = 0X0000X1111001011110X01X1XX01010X0XX +mem[10892] = 85035 +mem[38510] = 42597708 +mem[30752] = 2960 +mem[30416] = 123661909 +mem[49045] = 913 +mem[4292] = 75 +mem[17509] = 1382 +mask = 1X00X00111X001X0100101001X110X0001X0 +mem[56241] = 8276 +mem[40782] = 243373 +mem[42397] = 43237586 +mem[13015] = 399 +mem[23129] = 735838 +mem[1385] = 4448 +mask = 0000X011000XX100X110111101X110X010X1 +mem[13015] = 247 +mem[42378] = 546670 +mem[8214] = 63809 +mem[22410] = 155149 +mem[55264] = 454543598 +mem[28778] = 69088880 +mem[48061] = 12489909 +mask = 0XX0X000XX1001X01101001000000100X1X1 +mem[7551] = 11717790 +mem[6107] = 50467 +mem[30752] = 4249755 +mem[17228] = 33884 +mem[59957] = 32163540 +mask = 1X0X0X10111X01001X0101011X0X0X0101X0 +mem[45349] = 1879078 +mem[31733] = 88189 +mem[12577] = 546676501 +mem[53419] = 16199 +mem[59921] = 2546 +mask = 0010001X110001X1X110100101X111000000 +mem[19998] = 179736 +mem[22061] = 30001652 +mem[41371] = 16212851 +mem[64355] = 622251640 +mem[23129] = 98852 +mem[56429] = 266 +mask = 00000X0X11X00XX1100001X0100010X0X100 +mem[37241] = 450 +mem[64833] = 219911344 +mem[16713] = 626602448 +mask = X1X01011X11010111011XX000001X01XX100 +mem[47336] = 15388 +mem[56124] = 582872 +mem[28686] = 27406190 +mem[34623] = 13146 +mem[30384] = 229541309 +mask = X00X011X11100100110X00110001XXX00000 +mem[18660] = 3353 +mem[30741] = 10036798 +mem[47487] = 4090 +mask = 00X0000X11100X011X0001101001X10X10X0 +mem[52567] = 730515 +mem[16156] = 10615261 +mem[29580] = 957414770 +mem[26765] = 19 +mem[24655] = 510031974 +mem[24669] = 30 +mem[46781] = 5769 +mask = 0X0010011110111010X000X0X11X101001X0 +mem[63285] = 8050 +mem[46893] = 981797 +mem[46022] = 984778 +mem[31931] = 67780 +mem[23543] = 3153 +mask = 1100X001X11001X01001X100111X01X0X100 +mem[53172] = 13616323 +mem[31500] = 117639 +mem[59037] = 106552607 +mem[54562] = 3408946 +mem[57159] = 411910 +mem[2824] = 61677145 +mem[47313] = 520051559 +mask = X100010111100100XX0XX110100001010101 +mem[37739] = 3912032 +mem[12772] = 884026 +mem[2217] = 4238 +mem[57159] = 28391 +mem[17146] = 3998 +mask = 00000001111001X11X000110101X1X11X100 +mem[11649] = 516652 +mem[21190] = 526 +mem[6364] = 274816 +mem[25567] = 190071 +mask = XXX00000X111010111001001111000X00000 +mem[25786] = 934 +mem[22026] = 215203 +mask = 0010000110X0110X11X001001101110X0011 +mem[59392] = 400 +mem[59580] = 927 +mem[15208] = 18515970 +mem[59444] = 245687 +mem[36248] = 893 +mem[59134] = 20240 +mask = 0X0XX1X11110X1011010000110000010000X +mem[11344] = 223586488 +mem[41434] = 519191086 +mem[15028] = 1492592 +mem[25631] = 247281 +mask = 11X0XX1011101000X0011X00X101X1111000 +mem[21825] = 1675 +mem[2371] = 663473 +mem[37724] = 4339 +mem[54246] = 855 +mem[9392] = 56579 +mem[35552] = 14454 +mask = 0100010111100100111X110X00X01000X1X0 +mem[44516] = 482691 +mem[26528] = 1559 +mem[53886] = 89643332 +mem[3478] = 12699372 +mask = 0011010111X00100XXX0XX1X10XX10100001 +mem[27239] = 413074512 +mem[15589] = 3001 +mem[10011] = 1136 +mem[59026] = 852921 +mem[5283] = 213015528 +mask = 00X0000XX11XX10111X0000001X000101000 +mem[17298] = 4088539 +mem[54369] = 505389469 +mem[8221] = 132829 +mem[55115] = 5055 +mem[56330] = 1932140 +mask = 01X00001111001010110111001X00010X0XX +mem[37467] = 127273625 +mem[38432] = 3166735 +mem[52727] = 998 +mem[42925] = 1733202 +mask = 11010011011011X01X01010XX10110110000 +mem[26085] = 233531 +mem[57079] = 1526 +mem[53172] = 385838419 +mem[29614] = 254712697 +mem[25466] = 735 +mem[27081] = 7719 +mask = 01000000111X0XXX1101X11X001101X01100 +mem[55941] = 72432190 +mem[16199] = 10097889 +mem[45349] = 10650 +mem[62515] = 8214 +mem[59468] = 965897 +mem[16653] = 386447843 +mem[49447] = 413274 +mask = 01000X011110X1XX1XX10X001111000X1000 +mem[59209] = 14316 +mem[50790] = 705222705 +mem[45621] = 232211796 +mask = 010X111101111XX1101000X1011000111011 +mem[48891] = 3231894 +mem[37241] = 49993 +mem[47016] = 3806 +mem[10469] = 12758 +mem[43871] = 17980 +mask = 0XX00XX11110010011X0010X1X011100X000 +mem[28733] = 801341049 +mem[12772] = 20002640 +mem[30741] = 2248 +mask = 0101X01110100X0111XX11110011000XXX01 +mem[17803] = 65414 +mem[45439] = 13886371 +mem[16184] = 130293 +mem[29313] = 1782 +mask = 01000111111001101X0110000001XX1X1111 +mem[34404] = 202755 +mem[43413] = 1045 +mem[48841] = 381434549 +mem[37238] = 230052 +mem[10175] = 421554 +mem[11939] = 15850 +mask = X0XX0011X110010X011000010111110X1XX0 +mem[54847] = 160031 +mem[53915] = 5111 +mem[6036] = 17132 +mem[36183] = 1360055 +mem[47658] = 127563 +mask = 00100X1111X0010101101X11X11111001X10 +mem[25937] = 8673 +mem[12926] = 834 +mem[43356] = 732346 +mem[5734] = 393 +mem[3822] = 30383 +mask = 110001101110XX00100100XX0X11X1XX010X +mem[821] = 185158312 +mem[64509] = 264189683 +mem[15199] = 1037709 +mem[635] = 437556 +mem[31141] = 14726605 +mem[40468] = 47196 +mask = 00000001XX1001001X0000X01001X0001100 +mem[46740] = 8071 +mem[43144] = 14187193 +mem[51555] = 382 +mem[30741] = 4087 +mem[45411] = 1430 +mem[14377] = 7364 +mask = 11X00110111001001001100X10X1XX00X100 +mem[62803] = 979004797 +mem[4838] = 343 +mem[23241] = 4426 +mask = 001X0101X1100100X1X0X110110XX01001X0 +mem[10799] = 5745 +mem[14789] = 34632 +mem[27068] = 8863 +mask = 001001011XX0010011000111010X10XX0100 +mem[31173] = 109895 +mem[25936] = 4493 +mask = 00000011111X0101X1X01100X00000100000 +mem[32612] = 14472 +mem[22702] = 713 +mem[22779] = 126887839 +mem[43168] = 251908 +mem[11504] = 47004 +mem[7399] = 2215129 +mem[63129] = 4367 +mask = 010001010X10010X111XX1X0111100101X0X +mem[3663] = 187207677 +mem[52928] = 200 +mem[38852] = 8397 +mem[31461] = 223838656 +mem[64706] = 4205924 +mem[26237] = 218385741 +mem[57402] = 258615472 +mask = 11X0X0X1011001XX1001111X011100XX0000 +mem[55334] = 323423 +mem[5833] = 33097 +mem[26924] = 272 +mem[42957] = 47976862 +mem[18798] = 61419 +mem[19947] = 1287 +mask = 1100X101011X10111X11X000111100111XX0 +mem[64472] = 224734 +mem[18079] = 526 +mem[60870] = 3322170 +mem[4013] = 578 +mem[2606] = 83684765 +mem[17048] = 2503 +mask = 0010000XX0000100110000011X0001X0X00X +mem[37789] = 94286 +mem[2499] = 13318890 +mem[29793] = 78507 +mem[45621] = 3626886 +mem[34770] = 2407 +mem[54400] = 38740 +mask = 0010X10111000100110001X0X1000100X101 +mem[11265] = 1297549 +mem[16410] = 948310 +mem[33093] = 893977 +mem[17298] = 53047 +mem[45439] = 14869 +mem[21212] = 870451788 diff --git a/2020/14/puzzle-1.py b/2020/14/puzzle-1.py new file mode 100755 index 0000000..f102316 --- /dev/null +++ b/2020/14/puzzle-1.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + + +def bitmask(mask: str, num: int) -> int: + binary = bin(num)[2:] + binary = "0" * (36 - len(binary)) + binary + res = "" + + for i in range(len(binary)): + if binary[i] == "1" and mask[i] == "0": + res += "0" + elif binary[i] == "0" and mask[i] == "1": + res += "1" + else: + res += binary[i] + + return int(res, 2) + + +def main() -> None: + with open("input", "r") as f: + lines = f.read().splitlines() + + mem: dict[str, int] = {} + mask = "" + for line in lines: + line = line.split(" ") + if line[0] == "mask": + mask = line[2] + else: + mem[line[0][4:-1]] = bitmask(mask, int(line[2])) + + print(sum(mem[val] for val in mem)) + + +if __name__ == "__main__": + main() diff --git a/2020/14/puzzle-2.py b/2020/14/puzzle-2.py new file mode 100755 index 0000000..45fb6ad --- /dev/null +++ b/2020/14/puzzle-2.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + + +def bitmask(mask: str, num: int) -> tuple[int, ...]: + binary = bin(num)[2:] + binary = binary.zfill(36) + res = "" + + for i in range(len(binary)): + if mask[i] == "0": + res += binary[i] + else: + res += mask[i] + + n = res.count("X") + combos = tuple(bin(i)[2:].zfill(n) for i in range(2 << n - 1)) + + acc: list[str] = [] + for combo in combos: + temp = res + for i in range(n): + temp = temp.replace("X", combo[i], 1) + acc.append(temp) + + return tuple(int(x, 2) for x in acc) + + +def main() -> None: + with open("input", "r") as f: + lines = f.read().splitlines() + + mem: dict[str, int] = {} + mask = "" + for line in lines: + line = line.split(" ") + if line[0] == "mask": + mask = line[2] + else: + address = line[0][4:-1] + addresses = bitmask(mask, int(address)) + for a in addresses: + mem[a] = int(line[2]) + + print(sum(mem[val] for val in mem)) + + +if __name__ == "__main__": + main() diff --git a/2020/15/.gitignore b/2020/15/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/15/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/15/Makefile b/2020/15/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/15/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/15/puzzles.c b/2020/15/puzzles.c new file mode 100644 index 0000000..64d89bb --- /dev/null +++ b/2020/15/puzzles.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdlib.h> + +#ifndef PART2 + #define BUFFER 2020 +#else + #define BUFFER 30000000 +#endif + +int +main(void) +{ + /* Given starting numbers */ + static unsigned int nums[BUFFER] = {0}; + nums[6] = 1; + nums[19] = 2; + nums[0] = 3; + nums[5] = 4; + nums[7] = 5; + nums[13] = 6; + + unsigned int temp, lnum = 1; + for (int i = 8; i <= BUFFER; i++) { + temp = lnum; + lnum = nums[lnum] ? i - 1 - nums[lnum] : 0; + nums[temp] = i - 1; + } + + printf("%u\n", lnum); + return EXIT_SUCCESS; +} diff --git a/2020/16/input b/2020/16/input new file mode 100644 index 0000000..2895e57 --- /dev/null +++ b/2020/16/input @@ -0,0 +1,269 @@ +departure location: 30-260 or 284-950 +departure station: 29-856 or 863-974 +departure platform: 32-600 or 611-967 +departure track: 44-452 or 473-965 +departure date: 36-115 or 129-950 +departure time: 50-766 or 776-972 +arrival location: 40-90 or 104-961 +arrival station: 40-864 or 887-971 +arrival platform: 32-920 or 932-964 +arrival track: 45-416 or 427-959 +class: 47-536 or 557-964 +duration: 33-229 or 246-969 +price: 25-147 or 172-969 +route: 32-328 or 349-970 +row: 50-692 or 709-964 +seat: 49-292 or 307-964 +train: 28-726 or 748-954 +type: 37-430 or 438-950 +wagon: 46-628 or 638-973 +zone: 39-786 or 807-969 + +your ticket: +89,193,59,179,191,173,61,73,181,67,71,109,53,79,83,113,107,139,131,137 + +nearby tickets: +499,362,657,143,723,763,935,454,473,586,372,489,214,753,765,65,307,56,853,934 +228,664,709,361,856,645,363,171,901,199,62,513,667,808,350,890,715,687,257,721 +531,490,628,88,947,252,832,917,686,571,362,874,837,588,849,140,655,407,90,611 +777,194,111,386,90,598,153,363,373,566,191,945,559,819,289,487,480,590,691,756 +186,366,196,844,655,659,845,109,355,330,71,176,397,380,822,776,369,447,658,949 +783,763,570,184,260,448,856,717,913,646,774,657,841,917,910,193,941,408,110,577 +378,832,670,59,155,911,209,74,57,947,144,514,411,89,690,856,854,286,597,132 +319,684,204,909,342,206,204,943,620,52,516,115,430,319,84,618,593,211,596,581 +66,146,910,225,107,112,918,679,255,757,125,946,863,892,78,525,373,913,87,838 +674,653,588,220,448,941,112,924,474,358,513,649,766,500,847,197,639,836,373,573 +76,115,776,726,598,361,480,772,356,129,506,380,202,810,932,756,408,81,786,889 +311,620,848,357,483,754,181,300,284,60,259,674,596,289,397,113,894,82,291,754 +84,600,751,223,595,478,198,2,402,428,355,517,947,933,624,59,598,711,752,513 +286,664,786,775,510,363,666,229,914,938,196,509,410,528,681,943,477,850,640,595 +365,17,624,375,640,483,208,258,189,222,889,655,852,326,109,428,758,616,889,288 +566,195,201,949,205,517,672,762,180,886,679,63,596,664,678,596,894,384,321,212 +576,316,480,579,925,328,498,194,191,132,106,863,210,416,351,663,643,218,366,942 +776,60,256,400,368,664,469,53,949,689,569,253,319,717,387,591,845,66,499,566 +620,831,379,712,614,176,682,666,83,197,438,916,535,504,218,377,627,155,429,855 +853,525,865,487,190,940,810,251,786,618,895,580,908,86,578,136,781,562,498,759 +671,625,256,592,177,500,523,50,443,692,650,128,441,832,626,491,252,405,661,756 +597,722,922,721,319,388,653,484,83,142,781,451,106,499,515,672,113,374,911,311 +211,716,176,715,627,286,327,531,566,587,916,431,57,371,894,677,778,193,710,447 +559,508,196,178,844,78,114,662,142,558,514,378,375,694,718,314,384,89,816,562 +290,578,105,478,229,260,752,496,187,937,137,898,69,399,980,638,441,84,589,574 +413,592,841,498,793,214,947,582,827,940,446,572,259,623,213,355,853,360,60,195 +481,764,308,384,131,247,595,756,221,361,175,256,407,255,155,752,781,524,403,640 +74,765,914,319,715,86,316,612,197,640,827,760,926,106,520,818,229,824,623,404 +576,504,694,379,75,528,638,257,482,852,837,563,575,389,686,217,852,684,314,184 +481,679,312,796,358,71,376,830,209,946,69,591,939,357,59,284,522,626,218,825 +355,812,691,377,833,938,139,233,643,764,663,692,722,576,495,843,450,536,359,174 +367,749,373,379,69,753,711,81,445,265,405,624,759,814,311,623,228,290,682,195 +475,841,833,415,13,809,478,70,191,228,934,760,765,508,398,655,907,850,487,54 +198,841,184,84,492,945,429,72,753,572,510,408,827,289,177,559,890,837,987,291 +427,198,192,666,319,369,565,861,512,216,81,899,388,761,683,933,529,515,673,674 +355,188,827,614,178,600,641,181,915,728,934,526,904,136,74,649,187,77,381,498 +751,317,780,190,897,781,65,852,933,69,657,811,517,564,842,877,382,84,56,576 +946,839,941,322,409,318,751,850,215,750,394,578,95,284,902,396,409,51,309,938 +54,400,54,307,290,665,125,507,220,600,214,405,864,217,763,284,382,820,129,910 +722,68,841,521,597,286,722,481,451,145,448,389,61,844,650,487,250,781,149,70 +175,323,322,831,857,137,616,686,408,175,709,903,214,917,414,108,367,827,684,593 +321,820,388,220,368,137,403,523,914,839,64,724,482,307,284,448,585,208,764,988 +86,926,414,213,825,682,473,67,318,144,51,311,814,709,520,687,623,396,949,387 +522,369,139,593,122,210,716,906,406,488,681,753,852,189,71,203,51,145,639,412 +322,368,18,663,903,574,203,363,391,643,205,474,182,517,855,486,890,315,725,82 +60,582,819,529,180,140,570,402,191,594,863,146,614,631,51,593,828,583,184,78 +856,622,291,412,503,532,563,217,404,352,349,406,675,277,292,765,748,493,691,626 +647,849,636,64,479,715,623,132,322,408,524,385,212,328,289,104,82,689,908,650 +197,444,249,763,892,86,775,441,172,664,379,596,910,584,574,376,665,899,174,847 +375,906,894,75,895,82,250,367,350,581,912,927,370,888,938,413,109,909,570,481 +104,831,565,413,849,533,861,394,361,511,292,573,567,218,832,135,717,851,134,223 +847,59,369,147,509,80,184,527,199,430,614,687,621,823,132,787,569,109,665,112 +109,983,680,682,191,65,139,643,687,228,828,317,211,784,851,757,672,64,616,173 +403,640,763,704,504,381,201,933,144,597,825,79,496,246,783,113,84,650,720,81 +356,82,615,375,222,361,182,255,112,845,612,298,891,887,382,839,380,691,405,660 +251,535,590,228,181,710,663,485,856,929,389,892,573,247,856,313,679,397,50,850 +895,673,675,513,838,181,135,696,599,327,583,720,486,104,691,777,115,536,724,920 +519,3,55,711,820,572,614,401,751,664,856,779,726,687,672,415,680,536,481,684 +692,781,22,72,586,906,845,356,852,590,777,372,593,579,369,663,619,317,134,138 +623,484,723,936,810,940,824,676,362,172,494,864,360,133,402,911,307,634,828,428 +899,308,410,558,557,452,69,84,65,5,187,849,493,223,441,349,499,677,67,915 +222,758,668,351,782,373,825,839,369,615,904,186,815,379,897,380,863,911,60,981 +576,710,508,63,506,888,638,476,626,616,863,494,434,898,715,759,946,208,932,84 +495,255,259,810,586,387,804,69,564,73,140,628,890,205,213,363,709,683,401,78 +79,582,688,536,114,106,622,289,395,417,786,384,175,55,850,855,327,189,135,254 +379,895,255,498,766,523,291,782,944,839,615,687,892,824,479,77,619,359,702,680 +250,144,611,936,220,851,509,379,260,821,532,859,79,673,906,624,211,780,349,448 +75,643,392,826,139,579,479,618,372,563,823,913,106,286,639,594,455,895,388,776 +370,785,939,918,661,841,582,655,678,109,850,673,423,864,290,677,762,834,383,686 +19,906,528,475,779,174,519,389,715,816,247,500,350,250,54,897,57,942,369,443 +114,684,251,944,56,944,228,217,666,778,650,605,488,284,643,516,754,561,659,938 +292,429,906,605,935,88,140,197,721,438,257,590,324,900,325,785,290,522,491,619 +249,52,649,558,605,914,494,286,373,132,892,766,709,355,655,321,218,473,906,562 +612,908,180,854,475,825,61,516,363,945,896,176,563,763,361,221,847,205,631,112 +936,57,379,279,534,211,889,254,198,381,645,764,318,377,619,850,78,750,181,83 +413,130,497,366,65,307,255,686,181,368,997,560,781,205,69,863,401,809,829,683 +137,227,53,486,826,676,221,896,219,358,981,370,638,528,649,404,482,942,809,676 +918,172,942,948,821,911,291,906,393,438,757,702,215,383,178,219,350,894,757,403 +526,913,180,376,653,617,837,935,896,373,343,184,257,660,784,406,901,904,377,689 +189,388,628,55,723,82,51,369,808,365,137,668,664,596,325,672,360,316,797,939 +88,905,90,284,619,394,326,415,836,891,618,207,754,226,766,572,444,567,177,991 +685,531,67,314,673,136,325,283,659,374,403,60,914,492,478,648,190,320,592,692 +137,146,504,678,691,247,673,438,999,315,639,536,917,416,212,187,896,198,785,452 +855,205,111,600,562,785,489,226,209,941,518,384,700,579,315,657,74,654,591,558 +444,360,672,367,819,108,757,136,621,838,323,785,478,809,492,376,161,508,901,586 +205,500,513,902,408,909,573,663,891,290,326,389,477,376,810,392,596,382,846,989 +141,366,489,481,716,350,589,63,655,558,451,143,289,594,866,933,711,63,213,380 +320,144,949,726,314,576,639,80,287,143,616,713,945,623,228,927,374,385,856,499 +215,135,351,409,69,619,658,639,567,716,227,888,768,66,115,320,77,718,748,369 +614,894,572,515,842,371,253,570,479,574,292,394,463,659,840,227,763,757,777,83 +401,887,116,854,751,683,137,898,104,649,596,779,935,65,570,220,147,850,781,379 +353,808,187,909,895,710,192,903,784,779,755,788,896,292,719,428,843,681,407,313 +83,722,826,829,392,616,655,484,520,720,53,243,145,360,63,594,512,443,850,200 +588,889,187,889,581,215,290,319,821,440,601,220,482,307,217,690,758,512,942,372 +722,183,134,843,807,783,509,657,411,859,561,401,763,719,756,380,756,375,443,207 +289,853,562,190,181,652,988,942,315,225,813,355,404,107,429,442,311,377,259,855 +527,780,526,323,449,218,721,714,84,200,806,717,619,587,821,399,570,518,778,893 +836,309,893,780,943,779,657,256,528,296,512,476,131,641,828,223,807,683,562,313 +855,192,440,557,427,710,776,755,653,920,191,763,631,664,897,580,845,916,659,66 +179,559,920,399,906,720,822,942,852,408,617,690,599,937,949,356,195,982,251,318 +942,990,386,328,473,669,52,324,531,889,854,322,594,762,536,135,672,501,612,229 +627,500,725,255,136,370,403,58,77,838,674,620,858,307,438,189,392,674,568,446 +529,415,438,661,287,511,200,250,179,388,596,582,176,529,514,978,945,106,312,564 +587,392,947,762,110,387,495,115,452,572,416,676,189,751,208,985,478,828,442,638 +439,935,614,357,919,131,385,247,674,113,835,766,908,373,134,257,996,487,145,836 +855,619,843,711,577,427,392,661,485,257,293,504,315,450,190,389,581,197,823,711 +617,816,838,636,257,58,935,668,501,386,226,838,919,660,755,643,438,216,526,753 +685,288,86,781,908,140,310,144,258,52,132,560,803,622,591,134,218,248,566,518 +782,290,896,384,324,452,671,562,508,653,475,996,683,624,494,597,145,682,67,910 +567,532,719,399,50,616,922,914,310,612,353,653,400,384,562,684,492,568,135,689 +170,749,486,901,108,825,887,210,519,226,762,188,590,903,452,617,615,834,363,517 +308,497,496,400,530,512,939,647,514,359,435,625,186,580,66,206,718,491,657,50 +558,698,326,195,809,89,135,378,518,846,692,204,716,573,176,369,583,752,227,651 +399,982,611,404,619,317,86,486,524,673,51,489,751,318,766,486,826,249,381,815 +597,856,16,375,61,137,906,888,439,669,782,893,902,398,785,900,671,319,710,136 +311,653,224,823,442,220,902,603,367,54,945,195,897,67,60,360,814,450,246,665 +358,579,849,813,315,308,825,681,827,114,857,352,481,440,212,944,836,312,501,439 +55,129,66,942,133,137,208,50,478,205,200,916,851,487,889,824,989,691,490,364 +308,381,688,440,135,516,816,504,287,625,750,355,663,714,176,391,229,989,904,284 +213,780,407,912,573,535,585,825,897,842,588,469,893,321,567,831,90,138,613,863 +853,119,581,373,84,761,217,640,752,383,226,650,357,322,438,503,292,559,291,492 +684,874,935,786,89,852,940,397,643,51,722,647,79,50,817,86,585,822,611,575 +777,890,911,915,114,452,635,204,79,289,310,449,628,247,358,948,894,307,350,893 +724,685,936,485,887,82,835,870,481,615,616,751,131,505,111,82,912,438,50,405 +520,826,224,592,411,284,834,668,902,657,661,897,758,369,933,809,704,501,222,777 +624,628,105,260,663,502,447,436,310,851,836,208,911,591,718,755,844,647,854,497 +762,175,201,4,644,111,427,490,713,409,531,143,577,75,287,663,172,411,911,57 +285,225,187,359,57,911,315,56,892,398,216,533,784,916,10,690,912,133,939,328 +754,649,519,319,315,807,640,749,668,404,594,514,175,587,637,582,188,90,219,427 +906,146,274,173,229,562,480,518,897,821,53,913,319,63,189,571,485,613,509,353 +502,646,58,352,505,660,575,133,671,811,586,350,850,802,474,360,911,136,564,753 +106,62,354,247,935,626,978,371,834,214,586,76,659,532,938,444,388,443,668,574 +132,473,368,718,80,754,751,947,903,772,284,256,650,258,251,682,197,619,758,501 +77,892,401,675,270,935,183,658,578,497,373,209,807,187,209,85,205,251,367,57 +750,209,834,811,665,898,361,64,114,685,258,943,644,532,129,614,924,76,377,405 +195,428,488,67,935,19,375,392,484,450,892,416,260,650,256,194,397,483,113,557 +474,852,196,427,375,977,639,643,536,785,66,452,326,623,828,309,909,373,138,113 +219,225,818,84,639,380,856,676,372,82,76,577,517,758,942,182,604,194,400,357 +908,622,568,81,183,901,868,354,818,835,894,430,482,824,856,839,190,77,88,840 +641,572,228,286,936,889,818,777,778,846,643,113,150,138,754,934,582,581,627,685 +898,891,841,0,62,908,110,888,74,831,286,653,407,138,653,932,514,853,357,598 +622,413,899,828,185,194,173,571,481,670,315,515,562,207,836,708,766,683,488,372 +248,457,934,372,564,414,662,665,949,642,202,144,189,842,214,592,374,888,211,247 +668,139,115,132,522,683,205,849,784,481,713,776,689,63,563,658,361,982,196,897 +289,407,60,434,323,561,196,319,517,846,686,855,173,864,611,814,717,618,313,687 +474,892,536,259,888,86,81,328,687,402,375,891,291,666,805,909,386,193,511,898 +131,210,638,840,392,765,565,841,394,781,813,562,316,145,526,528,826,803,87,197 +841,557,935,116,837,478,174,839,623,752,71,484,709,685,495,360,327,143,440,908 +452,86,411,358,847,632,853,716,410,491,934,86,196,598,600,486,402,212,493,714 +766,663,131,474,888,85,569,710,251,225,846,194,692,925,398,783,226,291,189,488 +657,560,388,477,509,87,139,911,258,671,947,753,865,913,324,638,366,526,584,429 +658,181,83,611,259,561,752,121,758,561,612,478,518,763,896,596,68,328,173,446 +625,810,62,508,458,355,847,896,220,838,933,536,376,112,427,190,511,403,479,675 +367,495,523,441,694,656,286,309,203,839,481,848,646,830,383,221,848,185,615,208 +311,526,497,750,473,916,393,396,564,191,479,723,627,182,444,484,173,754,661,8 +759,848,112,516,668,189,217,617,598,117,831,251,906,905,560,86,573,938,63,908 +188,889,534,86,999,187,441,186,762,61,827,106,222,756,814,113,716,54,200,808 +809,259,908,290,905,316,761,593,846,408,509,780,516,447,311,201,773,217,948,932 +210,253,621,481,900,557,318,379,909,511,985,904,681,716,115,70,214,385,825,427 +533,130,571,599,621,141,612,786,838,402,662,186,297,820,759,381,208,592,576,318 +320,253,349,831,394,557,105,752,522,191,181,891,200,13,409,762,833,317,683,55 +401,416,920,309,583,665,570,369,199,54,455,185,513,80,527,912,442,783,615,85 +365,190,504,219,595,618,593,350,782,809,66,919,427,474,406,137,81,14,189,442 +135,187,428,506,662,209,850,905,184,855,935,584,606,944,819,371,825,720,598,912 +622,620,408,224,530,792,894,855,372,667,653,820,514,180,479,685,190,196,107,560 +205,848,375,252,628,479,670,147,413,156,759,949,489,719,681,493,70,508,807,835 +776,676,62,512,658,477,215,748,911,186,500,557,213,862,905,373,677,250,410,250 +58,88,684,855,626,498,574,631,503,749,75,59,641,207,440,404,139,887,751,363 +113,186,66,204,104,726,115,137,617,832,90,755,664,517,452,635,594,749,892,363 +356,863,658,575,896,903,373,645,192,907,277,816,844,532,519,520,402,390,623,507 +83,514,383,674,628,832,584,723,639,307,144,569,191,199,990,718,76,415,193,756 +308,267,503,448,842,228,55,371,63,724,590,894,566,621,477,448,566,752,530,675 +569,327,379,64,84,51,273,863,721,501,592,688,406,814,498,292,505,487,901,398 +830,855,66,534,710,441,623,816,324,368,318,450,232,407,619,639,50,530,413,428 +477,579,480,721,16,713,673,53,687,256,624,444,534,725,653,227,76,750,411,104 +720,405,915,676,80,623,757,141,901,847,493,485,123,379,444,349,832,711,77,73 +528,50,913,528,50,61,354,489,838,600,193,387,382,621,191,822,119,82,211,836 +516,565,76,906,586,638,755,716,588,822,502,15,492,896,391,503,685,382,188,940 +318,583,260,677,873,822,364,255,624,624,147,721,63,218,215,567,136,493,87,511 +58,446,210,582,133,814,719,476,412,863,492,901,580,845,87,179,629,177,915,322 +112,712,386,667,624,369,650,317,177,230,532,56,360,482,479,818,893,835,258,495 +51,492,763,777,287,508,827,138,620,635,915,311,808,510,82,360,564,251,446,138 +198,678,855,410,568,899,712,442,173,438,18,86,777,83,752,144,207,721,587,590 +79,352,414,777,786,384,671,346,600,591,829,316,374,939,229,199,216,219,109,210 +508,154,508,677,510,212,529,903,758,410,199,131,88,476,481,508,825,393,784,287 +55,652,686,521,620,388,785,907,535,683,631,363,186,487,289,406,481,572,360,574 +133,507,413,366,838,939,131,589,678,440,520,912,142,533,909,17,588,753,833,657 +111,356,638,172,491,684,110,846,384,433,679,647,289,846,916,946,352,196,786,479 +567,224,907,310,488,763,195,139,595,512,687,680,493,401,130,749,273,353,498,679 +814,988,813,443,662,948,136,503,517,392,815,317,723,416,400,318,627,780,836,890 +328,196,856,288,623,257,525,285,679,512,564,170,723,534,916,179,67,651,557,834 +450,484,381,441,774,570,664,815,147,319,173,316,137,532,327,657,749,510,200,199 +902,650,327,258,647,667,250,77,579,598,723,473,510,364,923,369,493,357,318,359 +314,824,689,488,809,892,530,384,809,399,497,413,935,133,641,360,996,643,615,215 +365,756,249,585,913,613,821,353,646,851,411,54,710,153,289,199,617,200,383,528 +824,257,831,938,481,841,576,179,321,938,919,81,479,766,705,257,513,112,353,200 +71,748,208,75,250,319,498,179,997,394,409,764,377,678,534,320,113,512,669,115 +260,587,57,671,366,248,175,727,814,596,309,664,757,781,940,62,187,809,642,816 +406,205,569,108,817,414,366,474,86,311,901,682,589,256,283,814,393,596,856,321 +920,613,190,616,616,614,897,384,213,222,158,359,80,837,140,709,854,356,838,820 +496,508,512,509,675,180,89,182,838,208,392,771,177,934,88,513,61,943,903,666 +311,509,478,439,890,692,682,361,914,802,720,600,675,576,664,224,522,252,898,650 +384,587,250,396,715,840,595,679,900,135,141,438,844,122,310,566,850,291,205,676 +414,810,370,856,785,628,172,781,88,450,675,339,308,210,832,660,595,77,475,438 +648,77,650,473,817,977,819,524,846,751,323,823,104,67,112,451,394,627,725,578 +620,327,676,194,664,51,140,368,782,528,111,280,145,73,582,486,821,530,372,764 +370,364,79,252,718,204,370,835,825,904,698,312,137,586,387,360,713,229,725,318 +192,776,258,495,644,836,759,139,147,702,658,779,615,816,478,812,657,712,362,839 +386,530,409,863,110,290,938,75,406,457,190,513,368,133,203,753,514,825,644,687 +615,862,808,721,579,671,807,228,848,307,760,74,451,509,484,403,216,710,892,667 +494,763,935,569,778,396,362,723,113,495,897,486,735,495,288,715,937,590,575,687 +478,108,831,687,817,753,687,528,321,201,574,572,444,897,489,568,876,512,508,288 +829,312,350,843,478,252,584,361,625,307,929,570,514,72,219,825,686,570,655,667 +172,910,658,834,657,182,941,182,246,907,373,147,271,183,77,785,429,320,847,726 +855,523,364,690,564,979,145,892,354,525,326,510,723,856,560,445,620,813,525,618 +748,916,783,872,646,676,596,691,316,373,512,915,512,724,831,723,842,324,908,899 +88,766,253,446,940,533,398,506,751,912,18,130,134,477,855,59,516,395,384,76 +795,638,507,766,947,400,474,505,864,612,653,212,529,378,255,911,358,83,51,491 +765,827,584,196,941,390,402,713,901,82,659,623,345,177,309,191,198,223,863,937 +517,635,510,64,415,765,901,365,723,574,623,850,191,917,943,643,413,523,757,830 +218,854,225,812,523,170,593,357,761,291,621,914,584,60,64,198,65,501,848,939 +83,683,222,750,135,847,864,325,80,668,717,630,757,427,137,430,176,777,809,670 +285,570,846,471,759,572,627,721,753,68,414,920,521,677,517,713,901,475,569,67 +135,319,70,328,495,618,78,479,414,782,107,64,489,378,227,444,861,314,441,179 +766,557,983,577,443,573,225,74,259,680,659,932,916,452,560,763,374,214,446,644 +54,509,310,204,580,484,889,371,935,619,520,188,622,653,491,229,66,926,828,688 +560,311,146,911,907,864,696,386,328,776,393,387,947,364,212,688,677,446,361,64 +79,259,476,926,67,375,59,397,750,909,652,947,568,786,208,107,200,830,527,173 +88,836,587,134,901,176,896,287,68,574,903,562,82,877,75,651,561,813,569,209 +480,566,575,639,198,80,935,142,446,948,784,360,716,835,318,171,536,112,843,835 +519,711,796,581,590,382,317,514,389,488,410,663,840,578,450,906,947,841,507,663 +87,569,890,497,368,361,58,413,145,592,144,221,292,445,72,941,791,60,218,814 +389,810,597,156,190,186,507,725,638,349,86,405,644,947,254,201,391,573,758,826 +500,829,643,858,193,191,485,584,370,940,841,820,832,327,565,389,816,677,819,485 +81,499,388,812,201,848,823,288,715,650,868,307,322,53,780,360,650,491,711,896 +816,443,408,197,316,936,487,792,350,492,287,717,350,201,444,111,579,73,409,289 +509,369,890,671,529,444,428,783,170,139,889,649,905,511,508,410,380,399,203,310 +808,711,711,500,512,227,85,810,940,604,786,74,667,684,400,174,480,224,522,88 +105,897,172,780,432,722,287,529,824,524,52,250,136,219,223,249,384,938,559,856 +827,618,152,625,143,933,529,254,400,257,780,144,182,599,576,376,113,199,353,624 +515,253,651,450,659,382,814,254,522,535,906,180,350,358,725,441,135,591,921,54 +290,354,895,627,399,945,355,311,385,496,756,986,893,80,52,308,414,313,572,599 +211,363,501,189,635,891,131,623,493,109,854,572,190,246,206,562,808,365,889,250 +63,792,659,400,946,835,724,641,566,180,824,892,199,528,175,563,687,571,314,557
\ No newline at end of file diff --git a/2020/16/puzzle-1.py b/2020/16/puzzle-1.py new file mode 100755 index 0000000..f4343c8 --- /dev/null +++ b/2020/16/puzzle-1.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + i = 0 + valid: list[int] = [] + while data[i] != "\n": + ranges = data[i].split(": ")[1].split(" or ") + for _range in ranges: + bounds = tuple(map(int, _range.split("-"))) + for j in range(bounds[0], bounds[1] + 1): + valid.append(j) + i += 1 + + # Skip to nearby tickets + i += 5 + acc = 0 + + for j in range(i, len(data)): + fields = tuple(map(int, data[j].split(","))) + acc += sum(field for field in fields if field not in valid) + + print(acc) + + +if __name__ == "__main__": + main() diff --git a/2020/16/puzzle-2.py b/2020/16/puzzle-2.py new file mode 100755 index 0000000..1060049 --- /dev/null +++ b/2020/16/puzzle-2.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +from functools import reduce +from operator import mul + + +def not_reduced(label_dict: dict[int, str]) -> bool: + for i in label_dict: + if len(label_dict[i]) != 1: + return True + return False + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + i = 0 + valid: list[int] = [] + labels: list[str] = [] + while data[i] != "\n": + labels.append(data[i].split(":")[0]) + ranges = data[i].split(": ")[1].split(" or ") + for _range in ranges: + bounds = tuple(map(int, _range.split("-"))) + for j in range(bounds[0], bounds[1] + 1): + valid.append(j) + i += 1 + + # Skip to nearby tickets + i += 5 + + vtickets: list[tuple[int, ...]] = [] + for j in range(i, len(data)): + fields = tuple(map(int, data[j].split(","))) + check = True + for field in fields: + if field not in valid: + check = False + break + if check == True: + vtickets.append(tuple(map(int, data[j].split(",")))) + + label_dict: dict[int, list[str]] = {} + for i in range(len(labels)): + label_dict[i] = [] + + # Triple for loop, gross! + for label in labels: + valid: list[list[int]] = [] + ranges = data[labels.index(label)].split(": ")[1].split(" or ") + for _range in ranges: + bounds = tuple(map(int, _range.split("-"))) + for i in range(bounds[0], bounds[1] + 1): + valid.append(i) + + # For each column + for i in range(len(labels)): + allvalid = True + for ticket in vtickets: + if ticket[i] not in valid: + allvalid = False + break + + if allvalid == True: + label_dict[i].append(label) + + # Reduce the label dictionary + while not_reduced(label_dict): + for i in label_dict: + if len((l := label_dict[i])) == 1: + for j in label_dict: + if l[0] in label_dict[j] and i != j: + label_dict[j].remove(l[0]) + + my_ticket = tuple(map(int, data[data.index("your ticket:\n") + 1].split(","))) + print(reduce(mul, [x for x in my_ticket if "departure" in label_dict[my_ticket.index(x)][0]],)) + + +if __name__ == "__main__": + main() diff --git a/2020/17/.gitignore b/2020/17/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/17/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/17/Makefile b/2020/17/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/17/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/17/input b/2020/17/input new file mode 100644 index 0000000..3b42c23 --- /dev/null +++ b/2020/17/input @@ -0,0 +1,8 @@ +...#..#. +.....##. +##..##.# +#.#.##.. +#..#.### +...##.#. +#..##..# +.#.#..#.
\ No newline at end of file diff --git a/2020/17/puzzles.c b/2020/17/puzzles.c new file mode 100644 index 0000000..4e98982 --- /dev/null +++ b/2020/17/puzzles.c @@ -0,0 +1,104 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* PART2 is defined for part 2, but not for part 1 */ +#ifdef PART2 + #define MAXTIME 50 +#else + #define MAXTIME 1 +#endif +#define MAXDEPTH 50 +#define MAXHEIGHT 50 +#define MAXWIDTH 50 + +char space[MAXTIME][MAXDEPTH][MAXHEIGHT][MAXWIDTH]; +char temp[MAXTIME][MAXDEPTH][MAXHEIGHT][MAXWIDTH]; + +/* Check the cubes around the given coordinates and update the temp array accordingly */ +static void +update_cube(unsigned int const t, unsigned int const i, unsigned int const j, unsigned int const k) +{ + unsigned int active = 0; + + for (int tme = t - 1; tme <= (int) t + 1; tme++) { + if (tme < 0 || tme > MAXTIME - 1) + continue; + for (int dep = i - 1; dep <= (int) i + 1; dep++) { + if (dep < 0 || dep > MAXDEPTH - 1) + continue; + for (int hgt = j - 1; hgt <= (int) j + 1; hgt++) { + if (hgt < 0 || hgt > MAXHEIGHT - 1) + continue; + for (int wid = k - 1; wid <= (int) k + 1; wid++) { + if (wid < 0 || wid > MAXWIDTH - 1 + || (tme == (int) t && dep == (int) i && hgt == (int) j + && wid == (int) k)) + continue; + + if (space[tme][dep][hgt][wid] == '#') + active++; + } + } + } + } + + if (space[t][i][j][k] == '#' && (active == 2 || active == 3)) + temp[t][i][j][k] = '#'; + else if (space[t][i][j][k] == '.' && active == 3) + temp[t][i][j][k] = '#'; + else + temp[t][i][j][k] = '.'; +} + +int +main(void) +{ + /* Initialze space */ + memset(space, '.', MAXTIME * MAXDEPTH * MAXHEIGHT * MAXWIDTH); + + /* Read input */ + FILE *fpt = fopen("input", "r"); + char c; + unsigned int t, i, j, k; + + j = k = 0; + while ((c = fgetc(fpt)) != EOF) { + if (c == '\n') { + j++; + k = 0; + } + else { + space[MAXTIME / 2][MAXDEPTH / 2][j + MAXHEIGHT / 2][k + MAXWIDTH / 2] = c; + k++; + } + } + + /* Do the boot cycles */ + for (int cycle = 0; cycle < 6; cycle++) { + for (t = 0; t < MAXTIME; t++) + for (i = 0; i < MAXDEPTH; i++) + for (j = 0; j < MAXHEIGHT; j++) + for (k = 0; k < MAXWIDTH; k++) + update_cube(t, i, j, k); + + /* Copy temp to space */ + for (t = 0; t < MAXTIME; t++) + for (i = 0; i < MAXDEPTH; i++) + for (j = 0; j < MAXHEIGHT; j++) + for (k = 0; k < MAXWIDTH; k++) + space[t][i][j][k] = temp[t][i][j][k]; + } + + /* Count the active cubes */ + unsigned int count = 0; + for (t = 0; t < MAXTIME; t++) + for (i = 0; i < MAXDEPTH; i++) + for (j = 0; j < MAXHEIGHT; j++) + for (k = 0; k < MAXWIDTH; k++) + if (space[t][i][j][k] == '#') + count++; + + printf("%u\n", count); + return EXIT_SUCCESS; +} diff --git a/2020/18/.gitignore b/2020/18/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2020/18/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2020/18/Makefile b/2020/18/Makefile new file mode 100644 index 0000000..c32dafa --- /dev/null +++ b/2020/18/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -o puzzle-1 puzzles.c + ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2020/18/input b/2020/18/input new file mode 100644 index 0000000..c39b341 --- /dev/null +++ b/2020/18/input @@ -0,0 +1,379 @@ +6 * 7 * 8 * 9 * ((8 * 3 * 9) * 7 + 2 + 4 * 8 + 2) + 5 +3 * 2 * (5 + (8 + 2 * 2 * 8 + 8) * 8) +5 + 7 * 8 * 2 +(8 + 5 * 9 + (8 * 9 + 7 + 8)) * 4 * 3 * (8 * 9) * 3 +(7 + 2 + 2 + 5 * 6 * 3) * 8 + 5 * 9 +(9 + (2 * 9 + 6 + 5 + 2 + 7) + 4) + 5 + (9 + (7 + 8 * 6 + 3 * 8) * (5 + 3 * 2 * 9) + 7 * (4 * 5 + 6 + 9)) + 9 * 7 * 4 +5 * (8 + 2 + 9 * 6) +(4 * 8 + 8 + 5 * (5 * 3 + 7 * 8 + 8 + 2) + 8) * 4 * 2 * 7 + 3 + 8 +6 + 9 * (6 + 7 + (3 + 9)) +(6 * 7) + 2 +9 + (4 * (4 * 2 + 6 + 9) + 2 + 4 * 5 + 9) +2 * (8 + 6 * 2 * 6 + 2 * (6 + 5 + 9 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6 * 3 * 5) + 5 * 3 + 8) * 7 + 7 * 2 +9 + 2 * (7 * (8 * 7 * 4)) + 7 + 4 +(2 * 4 * (4 * 9 * 7 * 7 + 3) + 5) * 4 + 8 * 5 + 4 * 5 +(7 * 3 + 7 + 7 * 3 + (4 * 4 * 9 + 4 * 7)) * 6 * (4 + 5 * 3) * 4 + 2 +8 + (2 + 6 * 9 * (7 * 4 * 9) + (2 * 4 + 3)) + (5 + 9 * 2 * 9 + 7) + 2 * 5 +6 + 9 * 6 + 6 + (8 + 7) * 4 +8 + 8 * 7 + 6 * 2 + 8 +6 * 2 + 8 +5 + (7 * 9 + 6) * (8 + (3 + 9 + 8)) + (5 + 4 + 5 + 5 * 5) + (8 * 6) +(9 * 9 * 8 + 7 * 2) + 7 +6 + 7 + 8 + (6 * (5 * 8 * 4 + 5 + 7) + 4 + 9 * (3 * 2)) + (7 + 6 + 6) +(5 * 5 * 9 * 6 + (2 + 9 * 5 * 6) + 9) + 7 * 6
\ No newline at end of file diff --git a/2020/18/puzzles.c b/2020/18/puzzles.c new file mode 100644 index 0000000..5afbe00 --- /dev/null +++ b/2020/18/puzzles.c @@ -0,0 +1,126 @@ +#define _GNU_SOURCE +#include <sys/types.h> + +#include <ctype.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +static unsigned long long parse_number(void); +static unsigned long long parse_digit(void); +static unsigned long long parse_result(void); + +#ifdef PART2 +static unsigned long long parse_sum(void); +static unsigned long long parse_product(void); +#endif + +char *g_current; + +/* Convert the current number from a string to an int */ +unsigned long long +parse_number(void) +{ + unsigned long long number = 0; + while (isdigit(*g_current)) + number = number * 10 + *g_current++ - '0'; + + return number; +} + +/* Parse the current digit pointed to by `g_current` */ +unsigned long long +parse_digit(void) +{ + if (isdigit(*g_current)) + return parse_number(); + + /* If not a digit, it's a parenthesis */ + g_current++; + unsigned long long result = parse_result(); + g_current++; + return result; +} + +#ifdef PART2 +/* Parse and compute a sum */ +unsigned long long +parse_sum(void) +{ + unsigned long long result = parse_digit(); + + while (*g_current == '+') { + g_current++; + result += parse_digit(); + } + + return result; +} + +/* Parse and compute a product */ +unsigned long long +parse_product(void) +{ + unsigned long long result = parse_sum(); + + while (*g_current == '*') { + g_current++; + result *= parse_sum(); + } + + return result; +} +#endif + +/* Parse and compute a sum */ +unsigned long long +parse_result(void) +{ +#ifdef PART2 + return parse_product(); +#else + unsigned long long result = parse_digit(); + + while (*g_current == '+' || *g_current == '*') { + if (*g_current++ == '+') + result += parse_digit(); + else + result *= parse_digit(); + } + + return result; +#endif +} + +/* Remove the spaces from user input */ +static void +remove_spaces(char *str) +{ + char const *c = str; + do + while (*c == ' ') + c++; + while ((*str++ = *c++)); +} + +int +main(void) +{ + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + + unsigned long long acc = 0; + while ((read = getline(&line, &len, fp)) != -1) { + remove_spaces(line); + g_current = line; + acc += parse_result(); + } + + printf("%llu\n", acc); + return EXIT_SUCCESS; +} diff --git a/2020/19/input b/2020/19/input new file mode 100644 index 0000000..d45070d --- /dev/null +++ b/2020/19/input @@ -0,0 +1,562 @@ +72: "b" +45: 46 52 | 9 72 +85: 9 52 | 9 72 +82: 52 87 | 72 77 +133: 52 30 | 72 56 +118: 7 52 | 70 72 +18: 52 113 | 72 52 +119: 72 46 | 52 18 +25: 19 72 | 103 52 +32: 90 52 | 78 72 +50: 113 113 +71: 72 106 | 52 128 +3: 103 72 | 18 52 +41: 86 72 | 19 52 +96: 86 72 | 108 52 +33: 44 52 | 104 72 +127: 52 36 | 72 50 +51: 72 79 | 52 38 +43: 72 50 | 52 106 +14: 32 72 | 129 52 +6: 2 72 | 33 52 +108: 52 72 | 72 52 +129: 6 52 | 82 72 +34: 127 72 | 3 52 +74: 128 52 | 9 72 +80: 52 103 | 72 19 +2: 134 72 | 13 52 +54: 128 72 | 114 52 +19: 72 72 | 113 52 +0: 8 11 +30: 132 72 | 39 52 +60: 72 64 | 52 5 +4: 18 52 | 114 72 +57: 72 71 | 52 54 +111: 52 27 | 72 102 +76: 122 52 | 75 72 +134: 86 52 | 9 72 +49: 17 52 | 81 72 +124: 103 72 | 86 52 +123: 72 28 | 52 121 +117: 18 52 | 86 72 +26: 51 72 | 58 52 +62: 85 52 | 44 72 +55: 126 52 | 92 72 +115: 72 13 | 52 67 +109: 128 72 | 106 52 +52: "a" +93: 60 52 | 133 72 +64: 67 72 | 84 52 +102: 52 128 | 72 48 +84: 86 52 | 46 72 +77: 41 72 | 21 52 +27: 52 9 | 72 108 +95: 89 72 | 105 52 +36: 52 72 +110: 72 50 | 52 9 +9: 72 72 +120: 72 19 | 52 18 +67: 52 48 +112: 65 72 | 119 52 +75: 62 52 | 123 72 +23: 15 72 | 119 52 +42: 131 52 | 61 72 +94: 52 91 | 72 18 +66: 52 128 | 72 103 +10: 113 108 +37: 52 18 | 72 50 +98: 72 69 | 52 94 +126: 115 52 | 29 72 +79: 59 52 | 94 72 +104: 19 72 | 36 52 +125: 96 72 | 4 52 +122: 52 73 | 72 112 +130: 52 20 | 72 45 +90: 72 40 | 52 88 +132: 103 52 +121: 91 52 | 46 72 +7: 52 114 | 72 128 +5: 52 66 | 72 41 +97: 52 18 | 72 91 +89: 72 109 | 52 116 +53: 52 108 | 72 128 +114: 52 113 | 72 72 +16: 1 52 | 110 72 +113: 72 | 52 +31: 52 14 | 72 12 +69: 52 103 | 72 48 +128: 72 52 +40: 72 3 | 52 83 +101: 63 52 | 127 72 +1: 72 91 | 52 114 +58: 52 111 | 72 99 +13: 19 72 | 9 52 +35: 22 72 | 125 52 +65: 72 114 | 52 91 +12: 52 24 | 72 93 +46: 72 72 | 52 52 +20: 9 72 +73: 72 37 | 52 43 +15: 52 50 | 72 108 +103: 52 52 +106: 72 52 | 72 72 +21: 36 72 +28: 72 50 | 52 46 +78: 72 16 | 52 23 +70: 36 72 | 19 52 +87: 72 107 | 52 47 +116: 19 52 | 106 72 +29: 72 68 | 52 65 +8: 42 +68: 9 52 | 128 72 +99: 110 72 | 25 52 +17: 52 118 | 72 130 +11: 42 31 +48: 52 52 | 72 52 +83: 48 113 +105: 52 100 | 72 80 +61: 55 52 | 26 72 +100: 48 52 | 108 72 +56: 52 53 | 72 74 +63: 52 106 | 72 9 +44: 72 114 | 52 128 +47: 52 50 | 72 36 +107: 52 36 | 72 91 +39: 114 72 | 86 52 +86: 52 72 | 52 52 +24: 52 95 | 72 35 +81: 98 72 | 34 52 +131: 49 52 | 76 72 +92: 52 101 | 72 57 +59: 52 114 | 72 50 +38: 52 74 | 72 124 +88: 97 72 | 10 52 +22: 117 72 | 120 52 +91: 72 72 | 52 72 + +bbabbaabaabaaaababbbbabaabbaabab +baaabaaabaaababbabababaabababaaa +aaabbbabaabbbbbbbbabaaba +aaababbbaaabaabbabbbbabbaaaabbbb +ababaabbaabbbaabbbabbababbabbbbbbaaabbbbaaaabbbabbbaaabbaaaabbaa +bbbbaabaababaaabbbaaaaabbbbabbabaaabaabaabbaaaba +bbaababbbbbbaabbbbbaaaabbbbbabaaaabbbabaabbbaaaa +aaaaaaaaaababaaaabaaababaabbbbaababaaaaaaaaabaaabbaabbbaaabaabababbbbaaabbbbbabb +bbbbabbbbbbbbbbababbabbabbbabbbaaabbbbbaabbbbbaa +bbabaaababbbaabababbabbbabaabbbbbaaabbaaaaabbbaaaaabaabbaabbabba +babbbabaaabbaaaabaaaaabbbabaaaaa +ababaabbaaabbabbbbbbbaaaaabaabaabaaaababbaaaaaaa +baaaababaaaaaaababaaabba +bbaabbbaaabababbbaaaaabbbbbbbaaaaabbaabaabaaabaabbbaabaaaaaababbababbbbb +bbababbbaaabbabababbbabaaabbaababbbaaabaaabbbabbabababab +babbabbabbbaabbbbaabaaabbabababbbbbbbbaa +abbaaaaaabbabbaabbabbabababbaabaabbbaaaa +ababaabbabbbbbabbabbbaaaabbbaabbabbbbabb +aaabbbbaabbbababaabaaaaa +babbbaaaabaaabaaabbabbabbabaabab +aaabbaabaabbabaaaaaaaabb +ababbbabaabbaabbabaababababbbbaa +babbabaaabbbababbbababaaaaaabbaaababaaab +bbaababbbabaaababbaaabab +aabababbbbaabbbbabaabaababababaaabababab +baaaaabbbbbaabbbbbababbbbbbabbab +baaaabaaabaabaaabbabaaaababaaaab +aabbbabababaaabababbaaaa +ababbbaaabababbaaabaaababbaaaabaabbbbbab +ababbbaaaabaaaababababba +aaabbbabaabbaababbbbabbbbbabbabaababbabb +aabbabaaaabbaababbabbabbaaabaabababaaabaaaaaabab +abaaabbbabbaaababaaababa +bbaaabbbbababbababaababb +aaabbabababaaabaabbabaab +bbabbaaaabbbaabbaaabbbbbbbbabaabbbbbabbbbabbaabaabbaababaaabaabb +babbabbabbbbababaaaaabaababbbabbaabaabbbabaaaabb +bbabbaababababbabaaababb +babaaabaaabababbaabababbabbababaabbaaabbbababaaaababbbbbaaaabbbbabbbbaaa +aaabaabaaabbbaabbbabbbbbbbababba +aabaababbbaaaababbabaaaa +aaaabaaabbabababbabbbaab +baaabaabbaaaababbbaabaaaaabbabaaabaaabaabbbbbabbbabaabababaabbaaabbaaababbabbbbb +aabaabbbababbbababaababaabbbaaaa +aabaabbaaaabaabaabaaaaaabababbaababaaabbabbbbabbbaaaaaaabababbabbbbbabaa +baaabbbaaaaaabbbbbaaaaabbabbaabaaaaabbba +baaabaaaabbbbaaaaabbaababbabbababaaaabbbbabbaaabaabbbaabbaaaabbb +baaabbbabaabbabaabbabaaabaaabbbaabbaaabbabaaabab +abbaaabbaaabbabbabaaabba +aaaaaaabbabbbabababbbaaaababaabbabbaaabaabbaabab +aabababaaabbaabbbbaabbbababbaaaa +aabbbabaaabaabbbbbbabaabababbbbb +bbbababbbabbbbbbbabaaabaaaabbabaaabbbbabbabababaaabaaaaa +abaabbaabbbabaabbabaaabbaaabbaaaaabbaaabbaaabbbbbabbaabb +abbbbbabaabaabababababbaaabababbaabbbababbaabaaa +aaabbaabaabaaaabbbbabbbbbabaababaaaaabab +aabbbaabbbbbababaabbbbbbaababbbb +bbababbbaabaaaabbaaaaabbbaababaabbaabaab +aabaababaabbbbbbbabbbbab +aaaaabaababbbabbabbbaabbbbabbaaa +baaaabababbbabbbbaaababbbbbababaaaaaaabb +baaaabaabaaabbaaabbbbbbaabaabbaabbbbbbabbbbbbbbbbabaabababbbbabbaababbbb +bababbabaaabaaaaaaababbbbbabbbaabaaabbbb +bbbbbbbabbabaaabaaaaaaabaabaaabaaaaaaaaababbaaabbaabbaaababaaabbabaaaaaa +abbaaababbbabaabbaaabbab +aabaabbbabaaaababaaabbbabaaaabbbbabbbababbbbabaaaaaababbaaabaabbbbbaabababbaabbb +abaaabaabbabaabbaabbaabaababaaaa +babbabaabaaaaababaaaabba +bbabbbbaaabbbabaaaaabbbb +abbabababbabbbbbaaabaaabaaaaabbaabbabbababbaabbaaabbbabbabbaabbbaabbabaaabaabbab +baabaaabbbbbaabbbaaababa +bbaaabbabbbbabbabbaabbaabaaaaabbabaabbba +babbbabaaabbbaaababababb +abaabbbbbbbbbababaaabbbabbababaaabaaaabababaaaab +bbbbbabbbabbbbbababbabaaabbbaabbbbabbbbbabbabababababaabaaabaaabbaaabaaaaaabbaaa +bababababbbbbbaaaabbbbaabbaaabaababbbbaaabbabbab +ababbaabababaababbbbbabbbbabbababaaabbbabaaaabbbaaaaaaba +abaabababbbbabbbbabbaaab +bbaaaaaaabbababaabbbababbabbbabbbaabaaaabbabbaba +abbbaabbabbabaabbbbbbbaabaaaaabbbbaaaabbbbbbabba +aabbbbbbaaabbaabaababbbababbabaaaaabbaaa +abaabbaaaabababbabbabbabbbaaaaab +babbbababbbbbbbababaaaaa +baabbbbbaabbbaabbabbababbbbbbbbb +bbaaabbbbbbabaabaaaaabaa +bbababaaabbabbabbabbbaaabbabbbab +bbbbabbababbababaababbaa +bbababaabbabaabaabbaabab +aabbbaabbbbaababbabababa +ababaaababbbbaaaabbbbaaaaaababbb +baaaababbbaabaaabbabbbabaababbabbaaaaaaabbaaaaaa +abbbababbaababbbbbaabbbbababbbaabaaababaabaababbbabbbbab +bbabaaabbaabbaaabbbaaabaaaaabbabbaaaabaaabbbbabbbaabbbbbabbabaababaaaaab +bbbbabbabbbbbbaaaaaabbbbabaabababbabbbbbbabaabbaaabbbbbbbbbbaaaa +baababaaaaabbbaaabaabbba +bbbbababbbabbaabbbabaaababbaaaababababaa +aaaaaaaaaaaaaababaaababbabbbabaa +aaabbabababbbaaabaabbbbbababbbbaaabbbabb +aabaaaabbbbbaaaaababbaabaaabbbbabbaaaaaabbababbbaababaaabaabbaabbabaaaaa +aaaabaaabbaabbaaaabbabba +bbbbaaabbaababaaababbabb +abbbbababbbbabbbbbbbababbaabbbbbaaabaabaabababbabaaabaaa +baabbabaabbbaababbabbaba +bbbbaabbbabbabaaaabaaaaababbaababaaabaabbbaaabaaaaababab +abbbbbbababbabbbbaababababbabbabababbbbb +aaabbbabbbbaaaaaabbbabaababababb +aabbaaabaaabaaabbbaaabaaaabbaaaaaaabababbbaabaab +babaababbaabaaaababaaaaa +aaabbbaaaabaabbbaaabbbbb +abaabaabbaabbabaaaabbbbaaabbbbabaabbbabb +baaababbabaaababaaababbababbbbba +aabbaaaabbabaabbbabaaabaaaaaaaabbbbaaaaa +bbbabbbbaabbbbaabbbaaaabbbbaaabb +abaaabababbabababbaabbbabaaabaaaaaaaaaabaabbbaaaaabbbbbbabbabbaaabaaaaaa +bbbbbbbabbabbaabbabbbaaabaabbaaa +bababbabbaabaabbaaabbbbabaabbbbaaabaaabb +bbbbbababaaaaabbabbbbbbabaaaabab +babbabaabbbbaaabaaabbbbaababaabbaabbaabb +ababaabbbbbaaababaabbaaaabbabbbbaaabbaaa +ababbaabbbbbbaaaaaabbbbb +babbabaababbabbabaabbbab +bbaabbaabbbbaabbabbbbbbaabbbaabaaaababbbbaaabbbbbaabbaaa +aabaabbbbabbbbbbabbabbaaabaabababbbbbabbbbaabaaa +abbbbbbaaabbbbaaabbabbbb +aaaaaaaaababbbabaaabbaabababbbba +baaabbaabaaaabaaabaabaaabbaabbbbaaaaaaababaababb +ababbbaababbbbabbabaaaaabababbba +aaaaabaaaaabbbababaaabbbabbbabba +bbbabbbaaaaaaaaaaaabbbbb +abbbbbbabbabbabbabababaa +baaaaabaaaaabaaabbaabbba +baaaabbbaababbbaaaaaaabb +bbbabaabbabbabbbabaabbbbaabbaababaaabaaababaabbb +bbbabbaabbbaabbbbbbabbbabbababababbabbbb +baabaabbbbbaabbaaaababab +bbabbaabbababbabbbabaabbbabbbbbaaaabbabaabbbbbbbababbaba +babbabbaabbaaabbbbabbbbabaaaaaaabbbaaaaa +abaabbaabbbabbbaabbabaaaaababaaaaaaaabbb +aababbabbbabbaabbabaaabbabbabaabbbbaaababbabbaaabbaaaababbbaaabbbaabaabaabababaa +abbabababbaaabbbbaababbaabaabbbbbbbbbbaa +bbbabbbabbabbbbabaaabaaababaaababbbaababbbbabababbabbbabaaabaaaaaabaabbb +baaaaaababbabaabbbabaabaabbbbbabaaababab +baabaabababbbbbabbbbaabaaaaabbbb +baabbabaababbbabbabbbbab +bbbbaabbbbbaaaabbbbbaaaa +bbbbaababaabaaababbbbbaa +bbbbbabbaaabaababbbaaaababaaabba +ababbbabbbbaaaababaaaabbbbaabbbaaaaaababababbbbababbbbbaababbbabaaaaaaababaabbababbbaaaa +aabaababbbbbababbaabbbab +baaaaababbbababbababaaab +baabaabbaaabbaaaabaabbbabbabbbbababbbbab +abbbbbbababbbabaaabababbbbaabbbabbbbababaabaaabb +bbabbabbabbabababaaaabba +abbabbbabbbbbababaaabaaa +bbbbbaabbabbbbaaabaaaaaabbbabbabaabbbabbabbabaaaabaababbbbbaaabb +baaabbbaaabaabaababaabab +baabaababaaaaabaabaabbaababbbbbabaaabbababbaabab +bbabbbbabaaaabaaaabababbabbabaab +babbaababaaaaaabbbaabaab +abaabbabaaabbbabaaaaabbbbbabababbbbaabbabbbabbbbabaaaaab +ababbbabaababababaabaaaa +abaaabaaababbbabbaababaabaabbaab +aaabbbbabbbaabbabbabaabbbaabbbaa +aaabbbaaaabaabaaabbbbbbb +abbbbabbababaabbbbaababbaabaabbbabbbbabbababbbab +baabaabbbbaaaababbabaabbbbabbaaaabbbaaaaaaababaaaabaabbbbbaaaaabbbbaaaaaaaaabbababbabbba +abbaababbbaaaaabbaabbaaa +babbbbabbbaababaaaaaaaaaabbbbaabbbababbbabbaaaaabababbaabaabbaaaaabaabbbaaaaaaaaababbbbbabbaabaa +abbbabababbabaaaababaaaaababbbbaabaabbbababbaabb +abbaaabaaabbabaaababbaab +bbaabbbabaabbbbbabbabbbaaabbaaaabbaaabbbabbaabbababbbbababbaabab +abaaabbbbbabaababbabaaaa +bbababbbbbbababbaaaaaaabbabaaabb +bbbaabbbaabbbbaaabbabbaabaabaabbbababaaa +babbbaaaaabaabbbabbbbbaa +abaabbaabaabbbbbabbbaabbaaabbaaa +abbbaabaababbbabaaaaaaaabbbabbbabbbaabab +aaaabbaabbabbaabbbaababaabbabbbbabaaabbaabbbbbbbaababbbbbbaabbabaabbbaaabbaabbba +abababbabbabbabbbbabbbab +bbbababbaaaabaaabaabbbba +bbbbaababbbbbbabbbbbabbaababaabaaababaab +bbaaaaaaaabbbaaabaaabaab +babbbbbbbbbbbaaabbaaabbaaabbabbaaaabbaaa +abaabbabaaabaababbbaaabb +abaababaaaaaaabbbababaabaaaababaabbabaabababbbba +aaabbabaabaababaababbbba +bbaaaaaababaaababababaaa +abbabaaabaabaaabbabbaaba +abbabababbabaabbabbabababbbaaaaa +aabaaabaababbbaaababaaab +bbabbbbaabaaabbbabbaaaab +bbbbababbbbaaababbbaaaba +bbbbbbababbbbbbaaaaaabab +bbababbbabaaabaabaabbaaaabbbabbabbbbbbaaabbabbbb +baababbbaaabbbaaaabaabbbaabaaabb +abaabbabbaaaabababbaabbb +bbbabaababbbbbbabaabaaabbabbbbbbbbbaabaabbabbbaaabbababb +babbabbbbbbbbabbbaaaababbbbbbbbababababa +baabababaabbaabbaabbabba +baabaababaaaaabbbabaabbbababbbaaabbaaaba +bbbbabbbbaabbbababbbaabaabaabaaaaaaaabaaabbaaaaa +bbabababbaabbabaabbabbaabaababaabaaaabba +abbbbbbaaaaabbaabbbbbaabaabbabbbaabababaaaababbbbabbbbbabaaabbab +bbbbaaabaaaabaaaaabbbaab +aabbaabbaaaaaaaaabbbbababaabababbabbabbbbbbbababaaabaabb +bbabababbabbabbbbaaaabaaaabbaababbbaaaaaabbbaaaa +bbabbabbaaabababbabbbbababaabbabbbbabbbababbaaab +abaaaaaabbbaabaaaabbbbabbababaab +aabababbbabbabbabbaabaaa +ababbbaaaaabbabaaaabbabbaaaaaabb +baaaababbbaaaababbbbbabbbbbaaabaabbabaaabbbbbabaaaaaaaababbbababaabbbbbbaabbbbaa +baabbbbbbbbbaabaabbababb +bababbababaabbbbababaaab +baababbbbabbaabbabbabbaabababbabaaaabbbaabaabaaa +aabaabababaaaabaabababbbbaaabaaaabaaabab +abbaaaaababbabbabaaaabbbbaaaabba +babbbaaabaaaaabbbabbbbab +ababbbabbaabbabaabbbabba +abaabbabaaaabaabbaaabbbbbbbabbaaaaabaabb +bbbaabbaaabbbaabbaabaabaababbaab +ababbbaabbbbbbbabaababaaabbabbabaababaaabbbaaababaabbaab +bbbbbbbabbaaaaaaaaabbbababbbbbbb +aabaaababbabbabaaaaabaaabbabbaabaabbbbbbababaaaa +baabaaabaaabbbabbababbabababbaba +abbbabbbababbabbbbbbaaaababbabbbaaaaaaaaabbaabbabbaaaaabbbabaaaabababbbaaabbabbb +baabaaabbabbababbbbaabbaaaabbaabbbbbabbbabbbaaabbbbabaaa +abaaabbbabaabaaaabbbbbabaaabbbbabababbbbbabbbbabaabaaaaa +aaaaaaaaabaaaababbbaaabababababa +bbbbaabbbababaaaaaaaaaab +aaabaaaabaaaababbabbbbbbaaaabbababbbabaa +babaaababbbbbbbaabbbbabb +baaabbaaaabbbbaabbbababa +baababbbaababbbabbbaabbbbbbbabaaaabbaaab +baaaabaabaabaabbbababbababbbaabbaaabbaabbaaaabba +baabaababbbaabbbabbabababaaaaaaa +bbbababbaabbababaaaaabbb +bbbabaaaaaaaaaaabbbaabbbbabaabbaabaaabbbabbaabbbbabbbbab +aaaaaaabbaababaaaaabaaaababbbaab +abababbaababbbabaabbbbaaaaaabaaaabbaaaba +baababbaaabaabbbbbbaabbabbbbaabbaabbabaabbabbbabaabbabba +abaaabbbbabbbaaabbbbaabaabaabababbaaabbbaabbbbabbababbbabaabbaaabaaabaaa +aabaaabaababbaabbbbbbbabbaaaaabbaaaabbba +aabbabaaabbbbabababbbbbbbaaabbbabaabbaaababbbbabbbbabaaa +abaabbbbbbbbabbbabbaaaaabbaaaaaaabbabbbbabababaa +ababaabbbbbbabaaabbaabba +bbbbababaababaaaaaaabbaabaabaaaa +abbbababbbbbaaababaaaabb +aabbbbbbaababbbaababbbabbaabbabaabaababaaaabaaab +aabaababaaabbbaabbaababababbbaaaabababaa +abaabaabbabbbababbaaaabaabaaabaabaabaabbabbababbaaabaaababaaabba +baaaaabbbbbaaaabbbbbbabb +abbbababbbbbbbbaabbaaaaababbbabbabababbaabaababb +aabbaababbabbaabbbbbaabaaaabbabbababbaba +ababbbaababbbbbabbbabaaa +abaaabbbabababbaabaaabbb +abababbabbabbababbbaabbaababbbaaaabbaaab +abbbbabbbaabaabbbaaaabbbbaaabbbbbbbabbbaababbababbbabbab +bbbbbaabbbaababbabbbaaaababbbabaaaababaaabaabbaa +ababbbaababababaaabaabbbabaaabbbbaabababbabbbbbaababbaaa +baababaabbbabbbbaaabaabb +babaabbbbbaabbbbbbabbabaabbbaaaaabbaabbabbbbaabaabbabbbbbbabbbaa +baabbabaaabbbababbaaaaba +abbbbbabbaaabbbabbaabbaaaabbbbaaaabbabbabaabbbba +aaaaaaabbaaabbbaaaaabbab +baabbbbbbaaabbbbaabbabaaaababbabbbaababaaabbbbbaabaaaaaabaabaabababbbaaa +aabbaaaaabbabaaaabbbbbaa +bbbabaabbbaaaaaaaabbbabaababaaab +babbabaaaaabbbababaaaaaa +baabbabaabaaabbbaabaaaaa +aabbaababbababbbbababaabaabbbbba +abbbbabaaabaaababbbbbaaaaaabaaab +bbbabaabbbbbabbaaababaaa +bbbbbabaabbaaabaaaabbbaaabbbbbbabaabbbaaabbbbbbbbaabbaaa +bbbbaaaabaabaabbbbabbabbbbbbbabaaaaabaaabbabbbbbbaabbbabaaabaabb +bbbbbaaabbbbabaabbabbbbbbaabaaabbabbbbbaabbbabbaabbbbbaa +aaabbbabbabbabbbbabaaaaaabbbbbaaaaababaaaaaaabbaabbabababababaaabbbababaabbaaaabbaaabaaababbaabb +abbaaaaaabbababaaababababaaaaabbaaabbaaa +aaaabaaaaabbabaaaaaabbaa +bbbbbbbabaababbbbbbbaaaabbbbbaab +ababaaaababbabbabbbababaabbaaabbabbbbbbbaabbababbbabbaba +bbbbbbbaaaaaababbaabbaaaaaababbbabaaabab +baabbbaaaaabbbbabbababbaaaaababaabbababaaaabbbbbbbbaaaababbbbbaababaaabb +bbbabbbaaabbbaabaaababbaaaabbaaa +baabaababbbbbaaabbbbabaaaabbabbaaaabaabb +abbbaabbabbabbabbbbaabbbbbabbbab +babbabaaabbabbbabaababaabbabaaba +baababbbbaaaabaaabbbaabbbbbaaaaa +bbaababbaaabbbbabbbabaaa +babababaaabbababbbbbabbbbbbababbabbbabbaaabbabbbabbaaaabbabbbabbaabbaaba +bbbbaaaabaaaaaaabbaaabaabaaaababaabaababbbbabababbabbbbaabbaaaabbbbaaababbbabbababaababb +babaaabbaabaaabbbabbbaabaaaabbbaaaaaabababababbabbababba +aaaabaaabbabaaabaabbbaaabbbbabaa +abbababaabaabbaabbbababbbbabbbbbaabbaaaaaaaabbabaaababbbbbabbbaa +aababbbababbabaabbbbabbaaabaaababbbbabababaaabaaaababaaaaabbaaab +ababbbaaaababbbaabbbbabaabaaabaabbbaabbaabbbbbaabbbaaaaabaabbabb +bbbabbaabaabababaabbababaababaaa +aaaaaaabbbbbbbabbabaabaa +abaabaaaaabbaaaabbbbaabaaabaabaabbbaabaa +aabbabaabaaabbaaaaaabbbb +abbabbaabaabababaabbbaabbbbbaababbbbabbbabbbaaab +abbaaabbabaaaabaaaaaabaaaababbbbbaabaaabaaabaabbbbabbabbbbbaaabababbabbabbbbbaaa +abaaabbbbabaaaaaabbaaababaaaaabaababbaababaabaaaabaaaaabbbaaaaab +aababababbbbbbbaabaabbabbbbbbaaaabbbaaaa +aabbaabaaabbaaaaaabaababaabbbbab +aabaaababbaaaaaabbababababaaaaabbababaab +baababaababbabbbabbaabaababbaabbaabaabbabbbbbaab +abaaabaaaaabbbaaabbababababbbabaaababaaa +aabaaababbbbbabbbaabbabb +aaabbabbaaabbbaabbbbbbababbababb +aabaaaabaabbbbaaaaaabaaabbaabbbaabbbbbbb +bbbbabaaaabbababbbabaaabbabaabba +baabaabaaabababababbabbbbbababaaaaababab +aabbbaaaaabbbbaaababbaaaababbbbaababaaaabbbabaab +abbaaabbbaabbbbabababbbabaabbbbaaabbabaabbaaaaba +aaaaaaabbbabaabbaabbbabaabbababaabbbbbbaabbbbaaaabababaaaaaabbbbaabbabba +abbbbabaabaabaabbbabbbbaabbbbabaabababbbbbaabbabbaabaaaa +abaabababbbbbabbbabaaaab +bababbabbbbabaaabbaaaabb +abbabaaabbbababbbbbaabbaaabbbbaababbaaba +bbbbaabaaabbbbbbabaabaaaaabaababbabbabbbabaaabab +babbabbbbbbabbaabbbabaabbbbbbbbb +babaabaaababbbbaabaabbbaababaaabbbabbbaaaaaaaaaabaababbbbaabbaaa +bbbbaabaabbabbaaabaabaaababababa +abbaababbbbabbabaabbbbbaababaaabaaabbbaaabaababbbbbaabaa +aabbaaaabbbbababaaaabbab +aabaababbabbbabaaabababaabaaabbaabaaaabb +bbabbabbbbaabbbbabaabaaaaaaaaaababaaabba +aaababbaabababaabababaaababaabaaabaaaabb +baaabbbabbaaaaabbaabbbab +bababaabbabbbababaaaababbabbaabbbbbaababbabbabbb +bbababaaabbbaabbaaabbbabaaabbbaabbbaaaaa +aabbbbaaabbbbbabaabaaababbaabbaaaabbbbbaabaaababbbbaabab +aaaaaaabaaaababbabababbaaababaabaabaaaaaabbaaaaaabaabbbaaaaabaaa +abaabbbbbbbabbaaaababbab +bbaaaaaaababaabbbaabaaabaababaaa +aabbbababaabababbabbbaab +abaabbbbbbaaaaaabbbbbbbabbbbabbbbabbaabb +aabbbbaabbababaabababbba +bababbabaaaabaaabaababaaaaaaaabb +bbbbaababbbabbaabbaabbaaabbbaabbbbabbaabaaaaaabb +bbbbabbabbbbaabaaaabaaaabaaaaabbaaabbbbaabaabbbaaabaaaaaabbaabbb +abbabaaabbaababbaabaaabbbbabbaabbbaabbbb +bbaaabbabbbbbababababaababaaaaaababaaaaaaabbbbab +aababbbaabbbbabaabbabaab +bbbaabbbaaaaabaabbaaaaab +bbabbabbbbaaabbbbbaaaaaababaabbaababbabbabaabbbabbaaaabb +aaabbabaaabaabbbbbaababbbaaaaaababbabaab +abbabbabbbaabbaabbaaabaa +abaabbabaaaabaaaaaaaabab +abbbbaabaabbabbbaabaaabbbaaaaaaa +abbabbaaaababbbabbabbababbaababaabbabaabbbbaaabb +aabaaaaabbbababbbaaababbabbbbababababaaabbabbbba +aaabbabababbbababbbaabbbbaabbbbaaababaaa +aabababbaaabaaaabbababaaaaaababb +abbaaaaaabababbaabaabaababbaaababaababbbaaaababbbabbaaabaabbabbaabbaabba +bbaaaabaaaabbaabbbaaaabaababbbbb +ababbbabbaababbbabaabaababbbababbbaabbaaabaababbabaaaaab +aabaaabaababaabaababaaaa +baabbbbbbaaaaabbbaabbbaa +abbabbabbabbabbbabbbbabaabbbabbb +ababbaabaabbababbbbababbbbbbabaabbabbbabbabbbbaa +bbbabaabbababbabbbabbbaa +aabaabbbaaabbababaabaaababababbbaabababbabaabbbabaaabaabbababbba +abaabaabababaababaabbabb +bbaabbbaaaabbbabaaababaa +bbbbabbbaabbaaaaabaaabba +baaaabbbbbbbaaabbaaaaabbabaabbabaabaabbbbaabbbabaababbaa +bbabaabbbaababbabbaabbaaaaabbbababaabbbaaaaabbab +babaaababbbabbbbabaabaaababaabbb +baaabbaabaaaabaaaaabaabaaaaabaaaaaabababababaaab +bbbbbabbbbaaaaaabaababbababbaaaaabbaabbb +abaaabbbabbbaabbbaaabaab +bbbabbaaaaabaabaaabababaaaabbbabbbbbabbbaababaab +bbbbabbbbaabbabbaabbbbbbabaaababbbbaaabaaaaabaabaabbaaab +baaaabbaaaaababbbbaaaaabbbbbbbaababbbabb +bbaabbbaababbaabbabbabababbbaababaabaaaa +bbbabbbbbaaaabbbabbbbbbaabaabbabbababaab +baababbbaabaabaabbaababaabaaabbbbbbababbbaaaabba +babbabababbbbbabababbbba +aabbbaaabbaaabbaabaaabab +bbbbbbbaabaaabaabbbbbabaabaababbabbabaab +bbaabbbbaaabbaababaaabbabababbbaaaabababbababaaaaabaaaab +babbbabaaabbabaaaabbbaabbabaabab +bbaaaabaaaaaaabbababbaaaababbbbbabaabaaababbabbbabbaaaaaaaaaababaaabbabbbbbbabaa +ababaabbaabbaaaabaaaaabbababbbba +baaaababbbbbaabbbaaabaaa +aababababbbaabbabbaabbbb +baababbaaaabbabbababbaba +babbabaabbbbbbbaaabbbabb +bbbbbbabbbbbbbabbbbbbabbabaaaabb +bbbaabbbbbbbbababababbbb +aabbaaaabbabbabbbbbaabaa +bbababababbbbaabaaabaababbbbaaabaaaabbab +ababbaabaabbbaababbbaababbabbabbaaabbababaabbaabababaaaaaabaaaaa +aabaababbabbbaaaabababbaaaaabbab +abbaaabbaabbaababbbabbbaababaaaa +aabaabaabbbbbabbaabbaabaaabaabaabaabaabbaaaabaaababbaabb +aabaaaabbbbbaaaabaaabbbbbbbbaaabababaaabababbaabbbaabaabaababbaabaaaabab +bbbabbabaaabaaaabababbaabaaabbbabbaabbba +bbaaaabababbbbaabaaabbaababbabbaaabbbababaaaabaaabbbbbbb +bbaabbaaaaaaabaaaaabbbbabbbbbabbbaabaabaaabbbabb +bbaabbbaabbaaaaaaaabaabababababbaabaaaaa +babbababbaabaababaababbabbbbbbabbbbbaabbbaabbbbbbabaabab +ababaabbaabbbaabaaaabbba +aaaabaaaabbabbbabbbbababbbaabbab +aaabaaaaaaabbabaaaaaabbb +bbbbabbaababbaabbbabbabbabaaaabbabaaabba +ababbaabbbabbbbbaaaabbba +abbbbabaaabbbaabbbbaaaabababaaaa +aaabaabaaabbbbbbaaabaababbabbabbbbbabbab +aaabaababaaaaaabbababbabbabaabbaabababbabaabaabaaaababbabbaabbaa +baaabbbabbabbaababbbaaab +aabbabababaabbabaaaaaaba +aabbbabaabbaaaaaaababbaa +bbbbbbabbaaaabaaabbabbabbaaaababbbababaa +aababababaaaaabbaaaaabaabbabbabbabbbabba +bbbbaaababbbbabaabbbaaaa +babababbbabababaabaabbabbbbbbbbbaaaabbaaaababababbabaaab +abaaabbbaabbbaabbbbaaaba +aabbaabbbabaaabaabbabaaabbbbbaba +bbbbaaabaaabaabaababbaabbbababbbabaaabbbabbaabaababaabababbbbabbbababbba +abaaabbbaabbaabbabbabbbabbbaaaaabaaabaabbbbbaabbaaabbbbaabababab +bbabbbbaaabbbabaababbbaaababaabb +aabababbbaabbabaaaaaabab +abaababaabbababaaabbaabbbbbaabbaaaaababa +aaabbbabaababbbabbbaaaabbabbbbaabaaabaaa
\ No newline at end of file diff --git a/2020/19/puzzle-1.py b/2020/19/puzzle-1.py new file mode 100755 index 0000000..8ca7eb2 --- /dev/null +++ b/2020/19/puzzle-1.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +from collections import OrderedDict + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + i = 0 + rules: list[tuple[str]] = [] + while data[i] != "\n": + rules.append(tuple(x for x in tuple(data[i].split(": ")))) + i += 1 + + tests: list[str] = [] + for line in data: + tests.append(line.strip()) + + patterns: dict[str, list[str]] = {} + + # Get "a" and "b" out of the way to do less comparisons in the next loop. Also make use of + # this loop to strip newlines off of all the rules. + for rule in rules: + rules[rules.index(rule)] = (rule[0], rule[1].strip()) + if len(rule[1]) == 4: + patterns[rule[0]] = [rule[1][1]] + + while len(patterns) != len(rules): + for rule in rules: + if rule[0] in patterns: + continue + + res = rule[1].split(" | ") + req_rules = list(OrderedDict.fromkeys(" ".join(res).split(" "))) + all_in = True + for req in req_rules: + if req not in patterns: + all_in = False + break + if all_in == True: + all_combos: list[str] = [] + for re in res: + re = re.split(" ") + if len(re) == 1: + all_combos.extend(patterns[re[0]]) + else: + for x in patterns[re[0]]: + for y in patterns[re[1]]: + all_combos.append(f"{x}{y}") + all_combos = list(OrderedDict.fromkeys(all_combos)) + + patterns[rule[0]] = all_combos + + print(len([test for test in tests if test in patterns["0"]])) + + +if __name__ == "__main__": + main() diff --git a/2020/19/puzzle-2.py b/2020/19/puzzle-2.py new file mode 100755 index 0000000..b0efe15 --- /dev/null +++ b/2020/19/puzzle-2.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +from collections import OrderedDict +from re import search + + +def check(test: str, patterns: dict[str, list[str]]) -> bool: + chunks = string_divide(test, 8) + search_str = "" + + for chunk in chunks: + if chunk in patterns["42"]: + search_str += "0" + elif chunk in patterns["31"]: + search_str += "1" + else: + return False + + # 42 = 0, 31 = 1 + res = search(r"^(0)+(1)+$", search_str) + return not (not res or search_str.count("0") <= search_str.count("1")) + + +def string_divide(string: str, div: int) -> list[str]: + l: list[str] = [] + for i in range(0, len(string), div): + l.append(string[i : i + div]) + return l + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + i = 0 + rules: list[tuple[str]] = [] + while data[i] != "\n": + rules.append(tuple(x for x in tuple(data[i].split(": ")))) + i += 1 + + tests: list[str] = [] + for line in data: + tests.append(line.strip()) + + patterns: dict[str, list[str]] = {} + + # Get "a" and "b" out of the way to do less comparisons in the next loop. Also make use of + # this loop to strip newlines off of all the rules. + for rule in rules: + rules[rules.index(rule)] = (rule[0], rule[1].strip()) + if len(rule[1]) == 4: + patterns[rule[0]] = [rule[1][1]] + + while len(patterns) != len(rules): + for rule in rules: + if rule[0] in patterns: + continue + + res = rule[1].split(" | ") + req_rules = list(OrderedDict.fromkeys(" ".join(res).split(" "))) + all_in = True + for req in req_rules: + if req not in patterns: + all_in = False + break + if all_in == True: + all_combos: list[str] = [] + for re in res: + re = re.split(" ") + if len(re) == 1: + all_combos.extend(patterns[re[0]]) + else: + for x in patterns[re[0]]: + for y in patterns[re[1]]: + all_combos.append(f"{x}{y}") + all_combos = list(OrderedDict.fromkeys(all_combos)) + + patterns[rule[0]] = all_combos + + print(len([test for test in tests if check(test, patterns)])) + + +if __name__ == "__main__": + main() |