diff options
-rw-r--r-- | AoC2023/day18/eg-in | 14 | ||||
-rw-r--r-- | AoC2023/day18/input | 720 | ||||
-rw-r--r-- | AoC2023/day18/solver.lisp | 62 |
3 files changed, 796 insertions, 0 deletions
diff --git a/AoC2023/day18/eg-in b/AoC2023/day18/eg-in new file mode 100644 index 0000000..fc7612e --- /dev/null +++ b/AoC2023/day18/eg-in @@ -0,0 +1,14 @@ +R 6 (#70c710) +D 5 (#0dc571) +L 2 (#5713f0) +D 2 (#d2c081) +R 2 (#59c680) +D 2 (#411b91) +L 5 (#8ceee2) +U 2 (#caa173) +L 1 (#1b58a2) +U 2 (#caa171) +R 2 (#7807d2) +U 3 (#a77fa3) +L 2 (#015232) +U 2 (#7a21e3) diff --git a/AoC2023/day18/input b/AoC2023/day18/input new file mode 100644 index 0000000..84525fa --- /dev/null +++ b/AoC2023/day18/input @@ -0,0 +1,720 @@ +L 9 (#0e8fc0) +U 3 (#186423) +L 2 (#c2d020) +U 9 (#789c23) +L 8 (#43c582) +U 2 (#a5ff73) +L 7 (#8d9a62) +U 5 (#24ad83) +L 6 (#45b5a2) +U 7 (#3de791) +L 5 (#54b532) +U 11 (#981cb3) +L 2 (#a73ad2) +U 4 (#640bb1) +L 4 (#248a92) +U 4 (#341101) +L 10 (#b39c62) +U 8 (#3de793) +R 7 (#998942) +U 3 (#6e8db3) +R 12 (#1d0042) +U 9 (#9bc383) +R 2 (#13a372) +U 8 (#2b7523) +R 2 (#810ed2) +U 10 (#2baa03) +R 9 (#84f582) +D 4 (#83a133) +R 5 (#794e22) +D 10 (#45b441) +R 2 (#007952) +D 5 (#180061) +R 6 (#6b68a2) +D 8 (#949f81) +R 8 (#389562) +U 4 (#240ce1) +R 4 (#85fc02) +U 11 (#b01fd3) +R 8 (#0769d2) +U 4 (#664133) +R 4 (#421912) +U 16 (#9e9541) +L 4 (#4a0592) +U 6 (#434431) +R 15 (#031912) +U 4 (#105a81) +R 3 (#a2f1c2) +U 5 (#1d8161) +R 2 (#0b2772) +U 3 (#8268e1) +R 9 (#70a052) +U 3 (#1b8fc1) +R 7 (#d1c0a2) +U 4 (#376391) +R 3 (#3b6a82) +U 15 (#6d7883) +R 4 (#43d132) +U 13 (#6d7881) +R 5 (#7169d2) +U 3 (#479553) +R 5 (#50d710) +U 4 (#484b43) +R 7 (#1dd7a0) +U 2 (#c15953) +R 3 (#6d9250) +U 11 (#20ec73) +R 3 (#016d02) +U 7 (#b12003) +R 5 (#5f7182) +U 4 (#31b9e3) +R 7 (#ac29d2) +U 9 (#4dd1e3) +L 8 (#53fbf0) +U 9 (#044643) +L 12 (#22b0a0) +U 5 (#085593) +R 11 (#71c8f0) +U 4 (#ac50b3) +R 9 (#2492d0) +U 9 (#2aadb3) +R 4 (#7170c0) +D 6 (#1cbe71) +R 3 (#242170) +D 10 (#77baa1) +R 10 (#916dc0) +D 3 (#14ef11) +R 2 (#7be840) +D 7 (#5eb911) +L 6 (#c15fb2) +D 4 (#6c4b11) +L 6 (#c15fb0) +D 7 (#2516a1) +R 14 (#49de90) +D 2 (#4cb353) +R 6 (#2c7270) +D 6 (#b5f073) +R 8 (#7e9460) +D 11 (#4d1e93) +L 7 (#3aeb30) +D 6 (#316cd3) +R 7 (#1d9032) +D 9 (#18ad23) +R 3 (#9edd12) +U 9 (#18ad21) +R 11 (#2984c2) +U 8 (#1853c3) +R 13 (#0ac990) +U 5 (#bc14f3) +R 6 (#6ef300) +U 5 (#314353) +L 6 (#679d50) +U 11 (#06cea3) +L 5 (#01d5d0) +U 7 (#283693) +L 8 (#8fb490) +U 6 (#9e7783) +L 11 (#2c4fe0) +U 3 (#249453) +R 4 (#5cfe12) +U 5 (#694703) +R 11 (#547382) +U 6 (#84aec3) +R 3 (#a85eb0) +U 7 (#8aea73) +R 4 (#0912e0) +U 4 (#040e83) +L 5 (#7817a2) +U 4 (#084f33) +L 13 (#45c2a2) +U 5 (#4af3a3) +R 8 (#1374e0) +U 5 (#12ef81) +R 12 (#81b1c0) +U 5 (#12ef83) +R 3 (#46cee0) +D 5 (#57cd33) +R 12 (#c875a0) +D 5 (#738fe1) +R 4 (#2e9100) +D 3 (#253503) +R 6 (#750ac0) +D 8 (#253501) +R 6 (#7b1860) +D 3 (#9b4821) +R 9 (#5020e2) +D 6 (#62cfb3) +R 2 (#cabea2) +D 8 (#62cfb1) +R 9 (#03d4a2) +D 3 (#70aee1) +R 8 (#3ad7b0) +D 8 (#07f9c1) +R 13 (#3a1a00) +D 5 (#af7a61) +R 6 (#3a1a02) +D 7 (#866991) +R 10 (#595450) +D 2 (#05ad03) +R 3 (#68c560) +D 3 (#191121) +L 8 (#7501f0) +D 11 (#191123) +L 5 (#8ac5e0) +D 5 (#05ad01) +L 12 (#46a7d0) +D 9 (#5cab21) +L 7 (#2405b0) +D 4 (#7701d3) +R 3 (#5d0390) +D 10 (#401133) +L 3 (#5d0392) +D 3 (#453123) +L 12 (#7935a0) +U 8 (#307551) +L 5 (#50e840) +U 10 (#a2e7e1) +R 5 (#2fb6e0) +U 4 (#28e6f1) +L 2 (#0fc6a0) +U 8 (#8a9a03) +L 9 (#33f740) +D 6 (#9d4f63) +L 8 (#11ba50) +U 6 (#065603) +L 5 (#03b5c2) +U 9 (#ac67b3) +L 3 (#7c6492) +U 15 (#9dd8d3) +L 4 (#4e0902) +U 4 (#7502c1) +L 5 (#27b432) +D 11 (#3565a1) +R 4 (#41d8b2) +D 4 (#9fd821) +L 5 (#2f5be2) +D 7 (#aa7c53) +R 5 (#69cd60) +D 6 (#3c20b3) +L 4 (#15dbd0) +D 7 (#680473) +L 2 (#b95350) +D 2 (#2cfda3) +L 5 (#2e0f90) +D 5 (#2491e3) +L 9 (#332b40) +D 4 (#48d691) +L 9 (#06a720) +D 4 (#3891b1) +L 3 (#b9b5e0) +D 8 (#5e1701) +L 10 (#095730) +D 5 (#5ff163) +R 9 (#541fe2) +D 7 (#227553) +R 10 (#541fe0) +D 3 (#5d1893) +L 4 (#412ea0) +D 8 (#710861) +L 9 (#03b860) +D 2 (#63b2c3) +L 6 (#903700) +D 4 (#821a43) +R 10 (#5d9ef0) +D 6 (#8ea3e3) +R 5 (#054310) +D 7 (#a15321) +R 11 (#9ac5f0) +D 10 (#238b31) +R 8 (#9ac5f2) +D 12 (#9b92c1) +R 6 (#1743e0) +D 3 (#13ffd1) +R 3 (#5ebfb0) +D 9 (#022cb3) +R 4 (#7f0140) +D 7 (#908ec3) +R 3 (#5139f0) +U 11 (#85a3d3) +R 10 (#7ba250) +U 5 (#6b5161) +R 5 (#867c40) +D 7 (#6b5163) +R 10 (#0062a0) +D 3 (#4cdc33) +R 6 (#30d382) +D 11 (#4badc3) +R 7 (#5af3e2) +D 4 (#4badc1) +R 6 (#5898d2) +D 6 (#3282b3) +R 6 (#20e1b2) +D 5 (#797693) +R 9 (#84fb60) +D 4 (#28b2c3) +L 11 (#804680) +D 7 (#7d0803) +L 3 (#a4b840) +D 2 (#848111) +L 7 (#8d53c0) +D 5 (#086151) +R 5 (#6cfcb0) +D 2 (#18d4d1) +R 10 (#204a32) +D 5 (#b98171) +R 6 (#204a30) +D 4 (#11bbd1) +R 9 (#449900) +D 7 (#b2c8d3) +R 5 (#3e68f0) +D 5 (#39aa93) +R 5 (#5a27e0) +D 4 (#9021a1) +R 7 (#028ba0) +D 14 (#7c7ff1) +R 6 (#5e7262) +D 2 (#029611) +R 6 (#03b522) +D 11 (#743d91) +R 3 (#278162) +D 10 (#7ee343) +R 3 (#8322f2) +D 6 (#7ee341) +L 6 (#381582) +D 3 (#743d93) +R 10 (#1be022) +D 3 (#029613) +R 17 (#794472) +U 3 (#5b30f1) +L 6 (#0ea440) +U 3 (#42c781) +R 4 (#513b20) +U 9 (#50b901) +R 3 (#895d50) +U 10 (#50b903) +L 7 (#50b1b0) +U 5 (#87d461) +R 6 (#36e860) +U 6 (#710863) +R 4 (#4b0750) +D 9 (#04d981) +R 7 (#2e5790) +D 3 (#54cee3) +R 6 (#13e4a0) +D 7 (#7e75b3) +R 5 (#85c8a0) +D 3 (#7e75b1) +R 2 (#4679b0) +D 3 (#54cee1) +L 7 (#6dfa20) +D 4 (#c7a3b1) +L 6 (#205f40) +U 4 (#598a41) +L 7 (#32c740) +D 3 (#261551) +R 2 (#5f3750) +D 5 (#5362c1) +R 7 (#93d1a0) +D 3 (#81e573) +R 7 (#7b5760) +D 3 (#553523) +L 4 (#0405f0) +D 8 (#572033) +L 4 (#9ce570) +D 10 (#1405b1) +L 2 (#7359d0) +D 4 (#4c45e1) +L 7 (#af0710) +U 9 (#679921) +L 9 (#4bb510) +U 6 (#665611) +L 2 (#40d760) +U 7 (#af7671) +L 10 (#331910) +D 10 (#467161) +R 6 (#0ae430) +D 12 (#3ac303) +R 4 (#21e4d0) +D 4 (#829ed3) +R 10 (#7cfcd0) +D 3 (#bd61d1) +R 5 (#65ab20) +D 4 (#1e4741) +R 13 (#5da570) +D 3 (#c7d3d1) +R 3 (#37d870) +D 4 (#0e9721) +R 8 (#1a66b0) +U 6 (#66b701) +L 4 (#6a5820) +U 8 (#7a3c83) +R 4 (#3b97f0) +U 6 (#5f9be3) +R 7 (#34d820) +D 9 (#1ade73) +R 2 (#292822) +D 11 (#8c2783) +R 8 (#292820) +U 7 (#375ba3) +R 7 (#1a2af0) +U 2 (#85a933) +R 6 (#85b870) +U 7 (#984641) +L 5 (#5b3310) +U 5 (#8a3c43) +L 6 (#a9fbd0) +U 6 (#8a3c41) +R 11 (#13b5e0) +U 3 (#8fe6f1) +R 6 (#4c5de2) +D 14 (#7b1623) +R 5 (#5e1a52) +U 8 (#7b1621) +R 8 (#6e6c92) +D 8 (#0bbb51) +R 9 (#2a3b90) +D 12 (#1e77e1) +L 3 (#0cb3a0) +U 6 (#3e0c81) +L 15 (#bce7f0) +D 6 (#6a69e1) +L 4 (#3de000) +D 13 (#022411) +L 4 (#0f90a0) +D 3 (#40e851) +L 8 (#09b140) +D 6 (#2c3221) +R 4 (#905b70) +D 6 (#8cc471) +L 4 (#65fc80) +D 8 (#88bba1) +L 8 (#5cd1a0) +D 11 (#840981) +L 8 (#42f3f0) +D 7 (#536811) +L 4 (#41ddf2) +D 6 (#1e5261) +L 5 (#a55e42) +D 5 (#272da1) +R 6 (#0ae922) +D 9 (#9671e1) +L 6 (#303550) +D 7 (#04a0e1) +L 8 (#801210) +D 4 (#023021) +L 9 (#54f942) +U 5 (#56fbe1) +L 5 (#165612) +U 9 (#685651) +L 6 (#94b5d2) +U 9 (#02e061) +L 6 (#8299e2) +U 6 (#17ba81) +L 4 (#433fa0) +U 10 (#c47d91) +L 2 (#433fa2) +U 3 (#28c141) +R 9 (#900542) +D 9 (#29a633) +R 7 (#903c22) +D 10 (#181bd3) +R 6 (#3803b2) +D 11 (#d8f423) +R 10 (#3803b0) +U 5 (#21b0b3) +R 4 (#80ead2) +U 10 (#568bb3) +L 4 (#80ead0) +U 6 (#3e9083) +R 10 (#96a1b2) +U 9 (#829553) +R 5 (#1ce182) +U 8 (#55d673) +L 10 (#154232) +U 4 (#7adac1) +L 7 (#24a412) +U 7 (#9f9151) +L 5 (#24a410) +U 12 (#528cb1) +L 2 (#63ef22) +U 3 (#2d90a1) +L 5 (#64b5f2) +D 13 (#1ca591) +L 8 (#761b12) +D 4 (#514681) +L 5 (#6df642) +D 5 (#514683) +L 5 (#8691b2) +U 7 (#092ab1) +L 2 (#5707a2) +U 11 (#32af33) +L 6 (#6ffac0) +D 12 (#6bcd43) +L 3 (#6ffac2) +D 3 (#519023) +L 8 (#22ec82) +D 5 (#4df6c1) +L 5 (#d6c0a2) +D 7 (#5d3361) +R 13 (#d6c0a0) +D 7 (#44e271) +L 5 (#761a42) +D 6 (#42d711) +L 4 (#400322) +U 2 (#24ee81) +L 9 (#975332) +U 11 (#24ee83) +L 6 (#01a722) +U 3 (#4da371) +L 12 (#72c380) +U 8 (#304b01) +L 8 (#921fd0) +U 5 (#5c28c1) +L 8 (#7d0e20) +U 5 (#2f3881) +L 5 (#2020d2) +U 3 (#517101) +R 4 (#017862) +U 5 (#821541) +R 10 (#935432) +U 7 (#821543) +R 2 (#454322) +U 3 (#4098d1) +R 9 (#14fd72) +U 4 (#1dd501) +R 4 (#72c382) +U 5 (#363381) +L 4 (#d8fd70) +U 9 (#2ec0c1) +L 3 (#3a4722) +U 3 (#303ab1) +L 8 (#3b6392) +U 4 (#303ab3) +L 14 (#71c762) +U 4 (#336d33) +L 9 (#04d5a2) +U 8 (#3f0dc3) +L 12 (#365672) +D 3 (#411193) +L 4 (#365670) +D 8 (#6f15a3) +L 11 (#165e12) +D 2 (#022f03) +L 4 (#6bed02) +D 10 (#5f5513) +R 8 (#1e9e00) +D 7 (#553b53) +R 10 (#1e9e02) +U 7 (#57def3) +R 4 (#6bed00) +D 10 (#1d05c3) +L 9 (#0fc612) +D 10 (#1bde53) +L 6 (#93a152) +U 10 (#3270c3) +L 7 (#0b6600) +D 11 (#0d29a3) +L 6 (#ca7120) +U 9 (#0d29a1) +L 2 (#417010) +U 10 (#7e0693) +L 8 (#7547f2) +U 3 (#0395d1) +L 4 (#6d3082) +U 11 (#0395d3) +L 6 (#34cec2) +D 8 (#705e13) +L 8 (#60e4e2) +D 8 (#4680e1) +R 12 (#635122) +D 5 (#156441) +R 6 (#9c2be2) +D 12 (#4279a1) +R 2 (#6a87d0) +D 3 (#648191) +R 6 (#94f530) +D 13 (#1df511) +R 3 (#75c562) +D 9 (#5c7651) +R 9 (#5fa0d2) +D 5 (#577d81) +R 5 (#894fe2) +U 13 (#3d9361) +L 9 (#894fe0) +U 2 (#5a61c1) +R 9 (#5ecaf2) +U 12 (#cf0951) +R 7 (#1428b2) +D 5 (#cb9111) +R 3 (#6b7652) +D 15 (#11d851) +L 4 (#77f9f2) +D 11 (#0c01a3) +L 6 (#517782) +D 15 (#d167c3) +L 4 (#467802) +D 3 (#5ce141) +L 15 (#66b9a2) +D 5 (#835721) +L 3 (#4fcb32) +D 11 (#10b7c1) +L 8 (#62dba2) +D 6 (#547941) +L 8 (#874ee0) +D 6 (#1bc891) +L 6 (#67ca50) +D 7 (#d1dd21) +L 5 (#3179a0) +D 3 (#12f7a3) +L 7 (#55d6b0) +D 9 (#573bd3) +L 7 (#6b06d0) +D 3 (#46b173) +L 3 (#6b06d2) +D 4 (#4ccfe3) +L 10 (#5268b0) +U 7 (#295be3) +L 3 (#688e60) +U 3 (#2673e3) +L 4 (#01a9e0) +U 5 (#6b23b1) +L 10 (#569ff0) +U 8 (#4d2591) +R 6 (#73fc20) +U 2 (#4d2593) +R 8 (#2a6340) +U 7 (#88de01) +L 12 (#436592) +U 7 (#1106e3) +L 2 (#3e1942) +U 4 (#1106e1) +R 14 (#738082) +U 5 (#5982d1) +L 12 (#2a85a0) +U 2 (#a22ad1) +L 2 (#236dc2) +U 7 (#42b623) +L 3 (#2d2ca2) +U 11 (#5afae1) +L 11 (#214812) +U 11 (#45f451) +L 6 (#4c9862) +U 4 (#82b831) +L 3 (#2c0d22) +D 2 (#3cd183) +L 6 (#c006d2) +D 15 (#5cace3) +L 3 (#c006d0) +D 3 (#54dc83) +L 9 (#792d92) +D 9 (#354c83) +R 3 (#3d63c2) +D 7 (#42b621) +R 12 (#3527f2) +D 3 (#553991) +L 12 (#874ee2) +D 6 (#19f201) +L 3 (#2f8ba2) +D 8 (#6a0081) +L 3 (#0c4952) +D 2 (#340711) +L 11 (#259f32) +U 7 (#3306b1) +L 2 (#4f6012) +U 3 (#3306b3) +L 7 (#66abb2) +U 7 (#429e71) +L 8 (#09e952) +U 8 (#085031) +L 5 (#b8f4c2) +U 4 (#6e25a1) +R 6 (#27a722) +U 5 (#12e0f1) +R 9 (#a51e92) +U 11 (#4be951) +R 5 (#620da2) +U 3 (#4d1e61) +L 11 (#557ef2) +U 7 (#368f81) +L 5 (#1cd7d2) +U 3 (#1135f1) +L 4 (#47d892) +U 15 (#5b65a3) +R 4 (#5f3962) +U 7 (#5b65a1) +L 8 (#451ac2) +D 13 (#73f901) +L 4 (#8d8292) +D 6 (#92e921) +L 6 (#535112) +U 4 (#c1dd13) +L 6 (#2a6cf2) +U 11 (#0baf03) +R 6 (#687242) +U 4 (#1ecf83) +L 4 (#9e58e2) +U 9 (#6a09f3) +R 5 (#7eda42) +U 10 (#3260c3) +R 5 (#94e7c2) +U 10 (#806413) +R 4 (#18dd62) +D 5 (#2c5d83) +R 2 (#2028d2) +D 15 (#8e4173) +R 6 (#566c12) +U 8 (#3c6503) +R 8 (#14e1c2) +D 5 (#caa671) +R 9 (#651842) +D 4 (#252ab3) +R 12 (#b2ab92) +D 6 (#7c31e3) +R 4 (#29c8f2) +U 10 (#6424d3) +R 4 (#04edc0) +U 5 (#3e6543) +R 5 (#b00670) +U 12 (#4dc583) +R 5 (#2d5050) +U 5 (#9480e3) +R 8 (#9ca180) +D 6 (#869553) +R 4 (#4e1d60) +U 6 (#438b73) +R 8 (#7bdf32) +D 5 (#187383) +R 11 (#6abd12) +U 6 (#c1e0e3) +L 5 (#698900) +U 3 (#092553) +L 11 (#304550) +U 4 (#a72923) +L 6 (#004622) +U 5 (#3526e3) +L 13 (#a6a392) +U 4 (#47ff73) +L 5 (#3b9d90) +D 9 (#4442e3) +L 3 (#6b4c20) +D 8 (#7d3363) +L 4 (#3307c0) +U 15 (#041cf1) +L 2 (#0496a0) +U 2 (#0be741) +L 4 (#052da0) +U 7 (#68aa61) +L 9 (#c6dd00) +U 11 (#50de41) +L 2 (#1ed210) +U 2 (#69dd71) +L 13 (#23aba0) +U 9 (#3a80b1) +L 5 (#100040) +U 14 (#77dac1) +L 2 (#685460) +U 8 (#a94403) +L 14 (#594ae0) +U 4 (#b28783) +L 4 (#29f0d2) +U 9 (#6f2a23) diff --git a/AoC2023/day18/solver.lisp b/AoC2023/day18/solver.lisp new file mode 100644 index 0000000..62adac2 --- /dev/null +++ b/AoC2023/day18/solver.lisp @@ -0,0 +1,62 @@ +;;8:16 +;;9:33 +;;10:45 +(ql:quickload '(fiveam arrows cl-ppcre)) + +(defun move (dir) + (ecase dir + ((R 0) (list 0 1)) + ((D 1) (list 1 0)) + ((L 2) (list 0 -1)) + ((U 3) (list -1 0)))) + +(defun parse (filename part) + (mapcar (lambda (line) + (destructuring-bind (dir len rest) + (cl-ppcre:split " " line) + (if (eq part 'first) + (list (intern dir) (parse-integer len)) + (list + (digit-char-p (aref rest 7)) + (parse-integer + (subseq rest 2 7) :radix 16))))) + (uiop:read-file-lines filename))) + +(defun polygon-area (points) + (destructuring-bind ((fx fy) (lx ly)) (cons (car points) (last points)) + (arrows:-> + (loop for ((x y) (nx ny)) on points by #'cdr + when nx + sum (- (* x ny) (* y nx))) + (+ (- (* lx fy) (* ly fx))) + (/ 2) + (abs)))) + +(fiveam:test partials + (fiveam:is (= 4.5 (polygon-area '((1 1) (3 2) (2 6)))))) + +(defun solver (filename part &aux (row 0) (col 0) (perimeter 0)) + (let ((points + (loop + for (dir len) in (parse filename part) + collect + (destructuring-bind (dr dc) (move dir) + (incf perimeter len) + (list + (incf row (* dr len)) + (incf col (* dc len))))))) + ;; poligon area is for no width boundary + ;; thus add half-perimeter. Think on a square + ;; top and left edges contain area, but right & bottom not + ;; thus add that part of perimeter as with. Then add 1 because + ;; the corner on bottom right + (+ + 1 + (/ perimeter 2) + (polygon-area points)))) + +(fiveam:test solutions + (fiveam:is (= 62 (solver "eg-in" 'first))) + (fiveam:is (= 76387 (solver "input" 'first))) + (fiveam:is (= 952408144115 (solver "eg-in" 'second))) + (fiveam:is (= 250022188522074 (solver "input" 'second)))) |