diff options
author | Julien Dessaux | 2023-11-30 17:09:56 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-11-30 17:09:56 +0100 |
commit | 64286f54a74d6f45a25b5aa2e31742db90f20c75 (patch) | |
tree | 7a739e268655def33332cded39f00055ecf265e2 | |
parent | 2022-22 part 1 in haskell (diff) | |
download | advent-of-code-64286f54a74d6f45a25b5aa2e31742db90f20c75.tar.gz advent-of-code-64286f54a74d6f45a25b5aa2e31742db90f20c75.tar.bz2 advent-of-code-64286f54a74d6f45a25b5aa2e31742db90f20c75.zip |
2022-22 part 2 in haskell
-rw-r--r-- | 2022/22-Monkey-Map/folding.excalidraw.svg | 21 | ||||
-rw-r--r-- | 2022/22-Monkey-Map/second.hs | 143 |
2 files changed, 164 insertions, 0 deletions
diff --git a/2022/22-Monkey-Map/folding.excalidraw.svg b/2022/22-Monkey-Map/folding.excalidraw.svg new file mode 100644 index 0000000..2aa087e --- /dev/null +++ b/2022/22-Monkey-Map/folding.excalidraw.svg @@ -0,0 +1,21 @@ +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 504.9434888958724 543.0610501033734" width="504.9434888958724" height="543.0610501033734" filter="invert(93%) hue-rotate(180deg)"> + <!-- svg-source:excalidraw --> + <!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nO1dW1faWlx1MDAxN33vr+jgvFx1MDAxNs++X85cdTAwMWKgKIrgtYpfz3BcdTAwMDRcYphcdTAwMTJcdTAwMTIkQYGO/vdvXHUwMDA3LZdIQkJccoR61GFlJ/uauedcXGtlJf3x6fPnjDvq6Zl/Pmf0YUMzjWZfe8588cqf9L5j2JY6hCafXHUwMDFke9BvTM58cN2e88/ff89q7DXs7kst3dS7uuU66rz/qc+fP/+Y/J7rR+v37ZcuJsWzbjD0XHUwMDE3Vmxr0i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ID+trqhr/YBcdTAwMWZcdTAwMDCEkI/j9spA8kOAMUYxRdG1t3rTcoZcdTAwMTcjUqyx0eFQg19cdTAwMWLmuJNu+MV5XHUwMDE0flx1MDAwM/Dz3Dxlbyf/7pZ0wFx1MDAwZsHAW21cYjGBXGKNcaetXGZEc4yqJ7hwhonFndtyrmumXHUwMDFifW/udoQ5XHUwMDFlyaNcdTAwMGZcdTAwMTHsJTl8mKBcdTAwMGJcdTAwMGJ++akgROB5XHUwMDFieFx1MDAxNfog75/fVfFAa+/nSt+/Zq9uu/XT3UJfmN+xXHUwMDAxw48hTpX6flx1MDAxNLeDXHUwMDA3glx1MDAwZnovXHUwMDBlXHUwMDE3XHUwMDEykOjKW79cdTAwMWFccr5/zaPH8nNcdTAwMTbv48uaQa/X+u9S0vnYffLog0yxXHUwMDAxZztp+H16TZrMaL3epauazPx6YWTmydCf80tDXHUwMDA03peXfDlcdTAwMDGvXHUwMDA3XHUwMDEwffJqzJ+ffv5cdTAwMWabOqdcdTAwMDIifQ==<!-- payload-end --> + <defs> + <style class="style-fonts"> + @font-face { + font-family: "Virgil"; + src: url("https://excalidraw.com/Virgil.woff2"); + } + @font-face { + font-family: "Cascadia"; + src: url("https://excalidraw.com/Cascadia.woff2"); + } + @font-face { + font-family: "Assistant"; + src: url("https://excalidraw.com/Assistant-Regular.woff2"); + } + </style> + + </defs> + <rect x="0" y="0" width="504.9434888958724" height="543.0610501033734" fill="#ffffff"></rect><g stroke-linecap="round"><g transform="translate(368.24182385634117 171.8031184710026) rotate(0 -30 30)"><path d="M0 0 C0 10, 10 50, 0 60 C-10 70, -50 60, -60 60 M0 0 C0 10, 10 50, 0 60 C-10 70, -50 60, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(368.24182385634117 171.8031184710026) rotate(0 -30 30)"><path d="M12.99 27.04 C8.13 16.93, 3.28 6.82, 0 0 M12.99 27.04 C7.86 16.36, 2.73 5.68, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(368.24182385634117 171.8031184710026) rotate(0 -30 30)"><path d="M-7.43 29.06 C-4.65 18.2, -1.88 7.34, 0 0 M-7.43 29.06 C-4.5 17.59, -1.56 6.11, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(368.24182385634117 171.8031184710026) rotate(0 -30 30)"><path d="M-30.77 53.23 C-41.7 55.76, -52.62 58.29, -60 60 M-30.77 53.23 C-42.32 55.9, -53.86 58.58, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(368.24182385634117 171.8031184710026) rotate(0 -30 30)"><path d="M-33.26 73.6 C-43.26 68.52, -53.25 63.43, -60 60 M-33.26 73.6 C-43.82 68.23, -54.38 62.86, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(268.24182385634117 371.80311847100256) rotate(0 -30 30)"><path d="M0 0 C0 10, 10 50, 0 60 C-10 70, -50 60, -60 60 M0 0 C0 10, 10 50, 0 60 C-10 70, -50 60, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 371.80311847100256) rotate(0 -30 30)"><path d="M12.99 27.04 C10.24 21.32, 7.49 15.6, 0 0 M12.99 27.04 C7.96 16.58, 2.94 6.12, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 371.80311847100256) rotate(0 -30 30)"><path d="M-7.43 29.06 C-5.86 22.91, -4.29 16.76, 0 0 M-7.43 29.06 C-4.56 17.82, -1.68 6.58, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 371.80311847100256) rotate(0 -30 30)"><path d="M-30.77 53.23 C-36.96 54.66, -43.14 56.1, -60 60 M-30.77 53.23 C-42.08 55.85, -53.39 58.47, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 371.80311847100256) rotate(0 -30 30)"><path d="M-33.26 73.6 C-38.92 70.72, -44.58 67.84, -60 60 M-33.26 73.6 C-43.6 68.34, -53.95 63.08, -60 60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(148.24182385634117 271.80311847100256) rotate(0 30 -30)"><path d="M0 0 C0 -10, -10 -50, 0 -60 C10 -70, 50 -60, 60 -60 M0 0 C0 -10, -10 -50, 0 -60 C10 -70, 50 -60, 60 -60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(148.24182385634117 271.80311847100256) rotate(0 30 -30)"><path d="M-12.99 -27.04 C-9.61 -20.01, -6.24 -12.99, 0 0 M-12.99 -27.04 C-8.05 -16.75, -3.1 -6.46, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(148.24182385634117 271.80311847100256) rotate(0 30 -30)"><path d="M7.43 -29.06 C5.5 -21.51, 3.57 -13.96, 0 0 M7.43 -29.06 C4.6 -18, 1.78 -6.94, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(148.24182385634117 271.80311847100256) rotate(0 30 -30)"><path d="M30.77 -53.23 C38.37 -54.99, 45.96 -56.75, 60 -60 M30.77 -53.23 C41.9 -55.81, 53.02 -58.38, 60 -60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(148.24182385634117 271.80311847100256) rotate(0 30 -30)"><path d="M33.26 -73.6 C40.21 -70.07, 47.16 -66.53, 60 -60 M33.26 -73.6 C43.44 -68.43, 53.61 -63.25, 60 -60" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(208.24182385634117 111.80311847100259) rotate(0 -80 110)"><path d="M0 0 C-23.33 3.33, -113.33 -13.33, -140 20 C-166.67 53.33, -166.67 166.67, -160 200 C-153.33 233.33, -110 216.67, -100 220 M0 0 C-23.33 3.33, -113.33 -13.33, -140 20 C-166.67 53.33, -166.67 166.67, -160 200 C-153.33 233.33, -110 216.67, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(208.24182385634117 111.80311847100259) rotate(0 -80 110)"><path d="M-28.03 10.7 C-17.32 6.62, -6.62 2.53, 0 0 M-28.03 10.7 C-19.13 7.3, -10.23 3.91, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(208.24182385634117 111.80311847100259) rotate(0 -80 110)"><path d="M-28.35 -9.82 C-17.52 -6.07, -6.7 -2.32, 0 0 M-28.35 -9.82 C-19.35 -6.7, -10.34 -3.58, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(208.24182385634117 111.80311847100259) rotate(0 -80 110)"><path d="M-127.85 231.15 C-117.22 226.89, -106.58 222.63, -100 220 M-127.85 231.15 C-119.01 227.61, -110.16 224.07, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(208.24182385634117 111.80311847100259) rotate(0 -80 110)"><path d="M-128.5 210.64 C-117.62 214.21, -106.73 217.79, -100 220 M-128.5 210.64 C-119.45 213.61, -110.4 216.58, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(408.24182385634117 111.80311847100259) rotate(0 -20 110)"><path d="M0 0 C10 3.33, 53.33 -13.33, 60 20 C66.67 53.33, 66.67 166.67, 40 200 C13.33 233.33, -76.67 216.67, -100 220 M0 0 C10 3.33, 53.33 -13.33, 60 20 C66.67 53.33, 66.67 166.67, 40 200 C13.33 233.33, -76.67 216.67, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(408.24182385634117 111.80311847100259) rotate(0 -20 110)"><path d="M28.53 -9.27 C19.73 -6.41, 10.93 -3.55, 0 0 M28.53 -9.27 C22.33 -7.25, 16.13 -5.24, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(408.24182385634117 111.80311847100259) rotate(0 -20 110)"><path d="M27.81 11.24 C19.24 7.77, 10.66 4.31, 0 0 M27.81 11.24 C21.77 8.8, 15.73 6.36, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(408.24182385634117 111.80311847100259) rotate(0 -20 110)"><path d="M-71.66 210.15 C-80.4 213.19, -89.14 216.22, -100 220 M-71.66 210.15 C-77.82 212.29, -83.98 214.43, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(408.24182385634117 111.80311847100259) rotate(0 -20 110)"><path d="M-71.96 230.66 C-80.61 227.38, -89.26 224.09, -100 220 M-71.96 230.66 C-78.05 228.35, -84.14 226.03, -100 220" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(268.24182385634117 71.80311847100259) rotate(0 -120 150)"><path d="M0 0 C-6.67 -10, 0 -60, -40 -60 C-80 -60, -206.67 -63.33, -240 0 C-273.33 63.33, -253.33 260, -240 320 C-226.67 380, -173.33 353.33, -160 360 M0 0 C-6.67 -10, 0 -60, -40 -60 C-80 -60, -206.67 -63.33, -240 0 C-273.33 63.33, -253.33 260, -240 320 C-226.67 380, -173.33 353.33, -160 360" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 71.80311847100259) rotate(0 -120 150)"><path d="M-18.06 -23.95 C-13.03 -17.28, -8 -10.61, 0 0 M-18.06 -23.95 C-12.89 -17.1, -7.72 -10.24, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 71.80311847100259) rotate(0 -120 150)"><path d="M1.56 -29.96 C1.12 -21.62, 0.69 -13.27, 0 0 M1.56 -29.96 C1.11 -21.38, 0.67 -12.81, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 71.80311847100259) rotate(0 -120 150)"><path d="M-188.31 369.93 C-180.43 367.17, -172.54 364.4, -160 360 M-188.31 369.93 C-180.21 367.09, -172.1 364.25, -160 360" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(268.24182385634117 71.80311847100259) rotate(0 -120 150)"><path d="M-188.07 349.41 C-180.25 352.36, -172.44 355.31, -160 360 M-188.07 349.41 C-180.04 352.44, -172 355.47, -160 360" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round"><g transform="translate(348.24182385634117 75.50682217470629) rotate(0 -30 196.2962962962963)"><path d="M0 0 C3.33 -10.62, -3.33 -63.09, 20 -63.7 C43.33 -64.32, 126.67 -80.37, 140 -3.7 C153.33 72.96, 150 319.63, 100 396.3 C50 472.96, -110 455.68, -160 456.3 C-210 456.91, -193.33 409.38, -200 400 M0 0 C3.33 -10.62, -3.33 -63.09, 20 -63.7 C43.33 -64.32, 126.67 -80.37, 140 -3.7 C153.33 72.96, 150 319.63, 100 396.3 C50 472.96, -110 455.68, -160 456.3 C-210 456.91, -193.33 409.38, -200 400" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(348.24182385634117 75.50682217470629) rotate(0 -30 196.2962962962963)"><path d="M-6.93 -29.19 C-4.3 -18.11, -1.67 -7.03, 0 0 M-6.93 -29.19 C-4.66 -19.63, -2.39 -10.07, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(348.24182385634117 75.50682217470629) rotate(0 -30 196.2962962962963)"><path d="M13.45 -26.81 C8.35 -16.64, 3.24 -6.46, 0 0 M13.45 -26.81 C9.05 -18.03, 4.64 -9.25, 0 0" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(348.24182385634117 75.50682217470629) rotate(0 -30 196.2962962962963)"><path d="M-186.2 426.64 C-191.44 416.53, -196.68 406.42, -200 400 M-186.2 426.64 C-190.72 417.91, -195.24 409.19, -200 400" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g><g transform="translate(348.24182385634117 75.50682217470629) rotate(0 -30 196.2962962962963)"><path d="M-206.55 429.28 C-204.06 418.16, -201.58 407.05, -200 400 M-206.55 429.28 C-204.4 419.69, -202.26 410.1, -200 400" stroke="#1e1e1e" stroke-width="4" fill="none"></path></g></g><mask></mask><g stroke-linecap="round" transform="translate(208.24182385634117 71.80311847100259) rotate(0 50 50)"><path d="M0 0 C38.88 0, 77.75 0, 100 0 M0 0 C25.03 0, 50.06 0, 100 0 M100 0 C100 28.05, 100 56.09, 100 100 M100 0 C100 33.63, 100 67.27, 100 100 M100 100 C67.61 100, 35.22 100, 0 100 M100 100 C68.42 100, 36.84 100, 0 100 M0 100 C0 69.78, 0 39.55, 0 0 M0 100 C0 76.14, 0 52.27, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(245.74182385634117 98.80311847100259) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">A</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">1,0</text></g><g stroke-linecap="round" transform="translate(308.24182385634117 71.80311847100259) rotate(0 50 50)"><path d="M0 0 C31.3 0, 62.61 0, 100 0 M0 0 C27.89 0, 55.79 0, 100 0 M100 0 C100 25.5, 100 51, 100 100 M100 0 C100 24.66, 100 49.33, 100 100 M100 100 C73.22 100, 46.44 100, 0 100 M100 100 C71.03 100, 42.07 100, 0 100 M0 100 C0 76.97, 0 53.94, 0 0 M0 100 C0 79.57, 0 59.14, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(345.74182385634117 98.80311847100259) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">B</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">2,0</text></g><g stroke-linecap="round" transform="translate(208.24182385634117 171.8031184710026) rotate(0 50 50)"><path d="M0 0 C22.99 0, 45.99 0, 100 0 M0 0 C26.26 0, 52.52 0, 100 0 M100 0 C100 35.47, 100 70.94, 100 100 M100 0 C100 33.52, 100 67.03, 100 100 M100 100 C74.6 100, 49.2 100, 0 100 M100 100 C64.94 100, 29.88 100, 0 100 M0 100 C0 76.31, 0 52.63, 0 0 M0 100 C0 63.28, 0 26.56, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(245.74182385634117 198.8031184710026) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">C</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">1,1</text></g><g stroke-linecap="round" transform="translate(208.24182385634117 271.80311847100256) rotate(0 50 50)"><path d="M0 0 C22.83 0, 45.66 0, 100 0 M0 0 C28.45 0, 56.89 0, 100 0 M100 0 C100 28.45, 100 56.9, 100 100 M100 0 C100 38.62, 100 77.24, 100 100 M100 100 C70.58 100, 41.16 100, 0 100 M100 100 C75.67 100, 51.34 100, 0 100 M0 100 C0 76.9, 0 53.8, 0 0 M0 100 C0 60.82, 0 21.64, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(245.74182385634117 298.80311847100256) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">E</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">1,2</text></g><g stroke-linecap="round" transform="translate(108.24182385634117 271.80311847100256) rotate(0 50 50)"><path d="M0 0 C24.88 0, 49.75 0, 100 0 M0 0 C37.12 0, 74.25 0, 100 0 M100 0 C100 28.55, 100 57.1, 100 100 M100 0 C100 29.31, 100 58.62, 100 100 M100 100 C67.94 100, 35.88 100, 0 100 M100 100 C71.27 100, 42.54 100, 0 100 M0 100 C0 67.33, 0 34.66, 0 0 M0 100 C0 71.69, 0 43.38, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(145.74182385634117 298.80311847100256) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">D</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">0,2</text></g><g stroke-linecap="round" transform="translate(108.24182385634117 371.80311847100256) rotate(0 50 50)"><path d="M0 0 C22.45 0, 44.9 0, 100 0 M0 0 C30.24 0, 60.48 0, 100 0 M100 0 C100 37.57, 100 75.14, 100 100 M100 0 C100 36.77, 100 73.54, 100 100 M100 100 C67.32 100, 34.64 100, 0 100 M100 100 C61.4 100, 22.79 100, 0 100 M0 100 C0 71.64, 0 43.28, 0 0 M0 100 C0 70.44, 0 40.88, 0 0" stroke="#1e1e1e" stroke-width="2" fill="none"></path></g><g transform="translate(145.74182385634117 398.80311847100256) rotate(0 12.5 23)"><text x="12.5" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">F</text><text x="12.5" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">0,3</text></g><g stroke-linecap="round" transform="translate(208.24182385634117 71.80311847100259) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#b2f2bb"></path><path d="M0 0 C6.43 0, 12.87 0, 20 0 M0 0 C6.39 0, 12.79 0, 20 0 M20 0 C20 5.81, 20 11.63, 20 20 M20 0 C20 6.99, 20 13.99, 20 20 M20 20 C15.84 20, 11.68 20, 0 20 M20 20 C13.27 20, 6.54 20, 0 20 M0 20 C0 15.05, 0 10.1, 0 0 M0 20 C0 13.14, 0 6.28, 0 0" stroke="#2f9e44" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(108.24182385634117 351.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#b2f2bb"></path><path d="M0 0 C5.61 0, 11.22 0, 20 0 M0 0 C6.73 0, 13.45 0, 20 0 M20 0 C20 6.48, 20 12.96, 20 20 M20 0 C20 6.32, 20 12.63, 20 20 M20 20 C13.96 20, 7.91 20, 0 20 M20 20 C15.23 20, 10.45 20, 0 20 M0 20 C0 12.18, 0 4.36, 0 0 M0 20 C0 13.85, 0 7.7, 0 0" stroke="#2f9e44" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(108.24182385634117 371.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#b2f2bb"></path><path d="M0 0 C5.1 0, 10.2 0, 20 0 M0 0 C4.93 0, 9.87 0, 20 0 M20 0 C20 5.36, 20 10.71, 20 20 M20 0 C20 5.79, 20 11.59, 20 20 M20 20 C15.39 20, 10.79 20, 0 20 M20 20 C15.91 20, 11.83 20, 0 20 M0 20 C0 14.91, 0 9.82, 0 0 M0 20 C0 15.02, 0 10.04, 0 0" stroke="#2f9e44" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(288.24182385634117 351.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#a5d8ff"></path><path d="M0 0 C7.09 0, 14.19 0, 20 0 M0 0 C6.7 0, 13.41 0, 20 0 M20 0 C20 5.08, 20 10.16, 20 20 M20 0 C20 7.01, 20 14.02, 20 20 M20 20 C15.26 20, 10.53 20, 0 20 M20 20 C12.66 20, 5.31 20, 0 20 M0 20 C0 12.28, 0 4.55, 0 0 M0 20 C0 13.7, 0 7.41, 0 0" stroke="#1971c2" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(188.24182385634117 451.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#a5d8ff"></path><path d="M0 0 C5.69 0, 11.38 0, 20 0 M0 0 C7.72 0, 15.45 0, 20 0 M20 0 C20 5.88, 20 11.77, 20 20 M20 0 C20 4.87, 20 9.73, 20 20 M20 20 C15.38 20, 10.76 20, 0 20 M20 20 C12.16 20, 4.33 20, 0 20 M0 20 C0 14.34, 0 8.68, 0 0 M0 20 C0 13.03, 0 6.06, 0 0" stroke="#1971c2" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(388.24182385634117 71.80311847100259) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#a5d8ff"></path><path d="M0 0 C5.71 0, 11.42 0, 20 0 M0 0 C5.86 0, 11.72 0, 20 0 M20 0 C20 6.41, 20 12.82, 20 20 M20 0 C20 5.75, 20 11.49, 20 20 M20 20 C13.47 20, 6.93 20, 0 20 M20 20 C14.34 20, 8.68 20, 0 20 M0 20 C0 15.37, 0 10.74, 0 0 M0 20 C0 16, 0 12, 0 0" stroke="#1971c2" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(388.24182385634117 151.8031184710026) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#ffc9c9"></path><path d="M0 0 C7.51 0, 15.03 0, 20 0 M0 0 C7.35 0, 14.71 0, 20 0 M20 0 C20 6.54, 20 13.07, 20 20 M20 0 C20 7.72, 20 15.44, 20 20 M20 20 C14.33 20, 8.66 20, 0 20 M20 20 C14.09 20, 8.18 20, 0 20 M0 20 C0 15.05, 0 10.09, 0 0 M0 20 C0 13.32, 0 6.63, 0 0" stroke="#e03131" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(288.24182385634117 251.8031184710026) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#ffc9c9"></path><path d="M0 0 C5.81 0, 11.63 0, 20 0 M0 0 C6.99 0, 13.99 0, 20 0 M20 0 C20 4.16, 20 8.32, 20 20 M20 0 C20 6.73, 20 13.46, 20 20 M20 20 C15.05 20, 10.1 20, 0 20 M20 20 C13.14 20, 6.28 20, 0 20 M0 20 C0 13.62, 0 7.25, 0 0 M0 20 C0 13.18, 0 6.37, 0 0" stroke="#e03131" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(288.24182385634117 271.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#ffc9c9"></path><path d="M0 0 C6.48 0, 12.96 0, 20 0 M0 0 C6.32 0, 12.63 0, 20 0 M20 0 C20 6.04, 20 12.09, 20 20 M20 0 C20 4.77, 20 9.55, 20 20 M20 20 C12.18 20, 4.36 20, 0 20 M20 20 C13.85 20, 7.7 20, 0 20 M0 20 C0 13.14, 0 6.28, 0 0 M0 20 C0 13.12, 0 6.25, 0 0" stroke="#e03131" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(208.24182385634117 151.8031184710026) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#d0bfff"></path><path d="M0 0 C5.36 0, 10.71 0, 20 0 M0 0 C5.79 0, 11.59 0, 20 0 M20 0 C20 4.61, 20 9.21, 20 20 M20 0 C20 4.09, 20 8.17, 20 20 M20 20 C14.91 20, 9.82 20, 0 20 M20 20 C15.02 20, 10.04 20, 0 20 M0 20 C0 12.6, 0 5.19, 0 0 M0 20 C0 13.79, 0 7.58, 0 0" stroke="#6741d9" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(288.24182385634117 71.80311847100259) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#fab005"></path><path d="M0 0 C5.08 0, 10.16 0, 20 0 M0 0 C7.01 0, 14.02 0, 20 0 M20 0 C20 4.74, 20 9.47, 20 20 M20 0 C20 7.34, 20 14.69, 20 20 M20 20 C12.28 20, 4.55 20, 0 20 M20 20 C13.7 20, 7.41 20, 0 20 M0 20 C0 13.14, 0 6.28, 0 0 M0 20 C0 14.79, 0 9.57, 0 0" stroke="#e8590c" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(308.24182385634117 71.80311847100259) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#fab005"></path><path d="M0 0 C5.88 0, 11.77 0, 20 0 M0 0 C4.87 0, 9.73 0, 20 0 M20 0 C20 4.62, 20 9.24, 20 20 M20 0 C20 7.84, 20 15.67, 20 20 M20 20 C14.34 20, 8.68 20, 0 20 M20 20 C13.03 20, 6.06 20, 0 20 M0 20 C0 13.26, 0 6.52, 0 0 M0 20 C0 12.46, 0 4.91, 0 0" stroke="#e8590c" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(108.24182385634117 451.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#fab005"></path><path d="M0 0 C6.41 0, 12.82 0, 20 0 M0 0 C5.75 0, 11.49 0, 20 0 M20 0 C20 6.53, 20 13.07, 20 20 M20 0 C20 5.66, 20 11.32, 20 20 M20 20 C15.37 20, 10.74 20, 0 20 M20 20 C16 20, 12 20, 0 20 M0 20 C0 13.97, 0 7.94, 0 0 M0 20 C0 15.73, 0 11.46, 0 0" stroke="#e8590c" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(108.24182385634117 271.80311847100256) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#d0bfff"></path><path d="M0 0 C6.54 0, 13.07 0, 20 0 M0 0 C7.72 0, 15.44 0, 20 0 M20 0 C20 5.67, 20 11.34, 20 20 M20 0 C20 5.91, 20 11.82, 20 20 M20 20 C15.05 20, 10.09 20, 0 20 M20 20 C13.32 20, 6.63 20, 0 20 M0 20 C0 13.99, 0 7.98, 0 0 M0 20 C0 15.9, 0 11.8, 0 0" stroke="#6741d9" stroke-width="2" fill="none"></path></g><g stroke-linecap="round" transform="translate(208.24182385634117 171.8031184710026) rotate(0 10 10)"><path d="M0 0 L20 0 L20 20 L0 20" stroke="none" stroke-width="0" fill="#d0bfff"></path><path d="M0 0 C4.16 0, 8.32 0, 20 0 M0 0 C6.73 0, 13.46 0, 20 0 M20 0 C20 4.95, 20 9.9, 20 20 M20 0 C20 6.86, 20 13.72, 20 20 M20 20 C13.62 20, 7.25 20, 0 20 M20 20 C13.18 20, 6.37 20, 0 20 M0 20 C0 14.95, 0 9.91, 0 0 M0 20 C0 14.47, 0 8.95, 0 0" stroke="#6741d9" stroke-width="2" fill="none"></path></g></svg>
\ No newline at end of file diff --git a/2022/22-Monkey-Map/second.hs b/2022/22-Monkey-Map/second.hs new file mode 100644 index 0000000..82752cd --- /dev/null +++ b/2022/22-Monkey-Map/second.hs @@ -0,0 +1,143 @@ +-- requires cabal install --lib megaparsec parser-combinators vector +module Main (main) where +import Control.Monad (void, when) +import Data.Functor +import Data.List qualified as L +import Data.Maybe +import Data.Vector qualified as V +import Data.Void (Void) +import Text.Megaparsec +import Text.Megaparsec.Char +import System.Exit (die) + +exampleExpectedOutput = 5031 + +type Line = V.Vector Char +type Map = V.Vector Line +data Instruction = Move Int | L | R deriving Show +data Input = Input Map [Instruction] deriving Show + +type Parser = Parsec Void String + +parseMapLine :: Parser Line +parseMapLine = do + line <- some (char '.' <|> char ' ' <|> char '#') <* char '\n' + return $ V.generate (length line) (line !!) + +parseMap :: Parser Map +parseMap = do + lines <- some parseMapLine <* char '\n' + return $ V.generate (length lines) (lines !!) + +parseInstruction :: Parser Instruction +parseInstruction = (Move . read <$> some digitChar) + <|> (char 'L' $> L) + <|> (char 'R' $> R) + +parseInput' :: Parser Input +parseInput' = do + m <- parseMap + i <- some parseInstruction + void $ optional (char '\n') <* eof + return $ Input m i + +parseInput :: String -> IO Input +parseInput filename = do + input <- readFile filename + case runParser parseInput' filename input of + Left bundle -> die $ errorBundlePretty bundle + Right input' -> return input' + +data Heading = N | S | E | W deriving (Eq, Show) +data Cursor = Cursor Int Int Heading + +isOut :: Map -> Int -> Int -> Bool +isOut m x y = isNothing line || isNothing tile || tile == Just ' ' + where + line = m V.!? y + tile = fromJust line V.!? x + +stepOutside :: Map -> Int -> Int -> Int -> Heading -> Int -> Cursor +stepOutside m s x y h i | (t, h) == (a, N) = proceed fw (fn + rx) E + | (t, h) == (a, W) = proceed dw (ds - ry) E + | (t, h) == (b, N) = proceed (fw + rx) fs N + | (t, h) == (b, E) = proceed ee (es - ry) W + | (t, h) == (b, S) = proceed ce (cn + rx) W + | (t, h) == (c, W) = proceed (dw + ry) dn S + | (t, h) == (c, E) = proceed (bw + ry) bs N + | (t, h) == (d, N) = proceed cw (cn + rx) E + | (t, h) == (d, W) = proceed aw (as - ry) E + | (t, h) == (e, E) = proceed be (bs - ry) W + | (t, h) == (e, S) = proceed fe (fn + rx) W + | (t, h) == (f, W) = proceed (aw + ry) an S + | (t, h) == (f, S) = proceed (bw + rx) bn S + | (t, h) == (f, E) = proceed (ew + ry) es N + where + (tx, rx) = x `divMod` s + (ty, ry) = y `divMod` s + t = (tx, ty) + proceed :: Int -> Int -> Heading -> Cursor + proceed x' y' h' = case m V.! y' V.! x' of + '.' -> step m s (Cursor x' y' h') (Move $ i - 1) + '#' -> Cursor x y h + a = (ax, ay) + b = (bx, by) + c = (cx, cy) + d = (dx, dy) + e = (ex, ey) + f = (fx, fy) + (ax, ay) = (1, 0) + (bx, by) = (2, 0) + (cx, cy) = (1, 1) + (dx, dy) = (0, 2) + (ex, ey) = (1, 2) + (fx, fy) = (0, 3) + (an, as, aw, ae) = (ay * s, (ay+1)*s-1, ax *s, (ax+1)*s-1) + (bn, bs, bw, be) = (by * s, (by+1)*s-1, bx *s, (bx+1)*s-1) + (cn, cs, cw, ce) = (cy * s, (cy+1)*s-1, cx *s, (cx+1)*s-1) + (dn, ds, dw, de) = (dy * s, (dy+1)*s-1, dx *s, (dx+1)*s-1) + (en, es, ew, ee) = (ey * s, (ey+1)*s-1, ex *s, (ex+1)*s-1) + (fn, fs, fw, fe) = (fy * s, (fy+1)*s-1, fx *s, (fx+1)*s-1) + +step :: Map -> Int -> Cursor -> Instruction -> Cursor +step _ _ (Cursor x y N) L = Cursor x y W +step _ _ (Cursor x y S) L = Cursor x y E +step _ _ (Cursor x y E) L = Cursor x y N +step _ _ (Cursor x y W) L = Cursor x y S +step _ _ (Cursor x y N) R = Cursor x y E +step _ _ (Cursor x y S) R = Cursor x y W +step _ _ (Cursor x y E) R = Cursor x y S +step _ _ (Cursor x y W) R = Cursor x y N +step m _ c (Move 0) = c +step m s (Cursor x y h) (Move i) | isOut m x' y' = stepOutside m s x y h i + | tile == '.' = step m s (Cursor x' y' h) (Move $ i - 1) + | tile == '#' = Cursor x y h + where + (x', y') = case h of + N -> (x, y-1) + S -> (x, y+1) + E -> (x+1, y) + W -> (x-1, y) + tile = m V.! y' V.! x' + +compute :: Input -> Int +compute (Input m i) = 1000 * (y+1) + 4 * (x+1) + hv + where + xmin = length (V.filter (== ' ') (m V.! 0)) + startingCursor = Cursor xmin 0 E + s = length (m V.! 0) `div` 3 + Cursor x y h = L.foldl' (step m s) startingCursor i + hv = case h of + E -> 0 + S -> 1 + W -> 2 + N -> 3 + +main :: IO () +main = do + -- not doing the example, this solution is dependent on the shape of the input cube and sadly the example does not match it + -- example <- parseInput "example" + -- let exampleOutput = compute example + -- when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- parseInput "input" + print $ compute input |