Skip to content

Commit

Permalink
Rust/2024/18: add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Dec 18, 2024
1 parent 94aee51 commit 227d78c
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
|[2021](https://adventofcode.com/2021/leaderboard)|**136**|438|13.41% (of 1014)|0.0532% (of ≥255548)|
|[2020](https://adventofcode.com/2020/leaderboard)|**621**|46|65.23% (of 952)|0.3146% (of ≥197402)|

## [2024](https://adventofcode.com/2024) ([<img height=18 src=".assets/rs.svg"> Rust](Rust/2024): 17/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2024): 16/25 | [<img height=18 src=".assets/rb.svg"> Ruby](Ruby/2024): 5/25 | [<img height=18 src=".assets/hs.svg"> Haskell](Haskell/2024): 4/25 | [<img height=18 src=".assets/nix.svg"> Nix](Nix/2024): 1/25)
## [2024](https://adventofcode.com/2024) ([<img height=18 src=".assets/rs.svg"> Rust](Rust/2024): 18/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2024): 16/25 | [<img height=18 src=".assets/rb.svg"> Ruby](Ruby/2024): 5/25 | [<img height=18 src=".assets/hs.svg"> Haskell](Haskell/2024): 4/25 | [<img height=18 src=".assets/nix.svg"> Nix](Nix/2024): 1/25)
|Mo|Tu|We|Th|Fr|Sa|Su|
|-|-|-|-|-|-|-|
|||||||[**1**](https://adventofcode.com/2024/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2024/01.rs "Rust solution for 2024/01") [<img height=12 src=".assets/hs.svg">](Haskell/2024/01.hs "Haskell solution for 2024/01") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrCsOKKn-KNieKKnOKKnOKLleKIqeKJoEBcbixAIC4K4oipLyviioMo4pmtw5fiip7iirg9fOKMtS3iiKnijYYpCg== "Uiua solution for 2024/01") [<img height=12 src=".assets/nix.svg">](Nix/2024/01.nix "Nix solution for 2024/01") [<img height=12 src=".assets/rb.svg">](Ruby/2024/01.rb "Ruby solution for 2024/01")|
|[**2**](https://adventofcode.com/2024/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2024/02.rs "Rust solution for 2024/02") [<img height=12 src=".assets/hs.svg">](Haskell/2024/02.hs "Haskell solution for 2024/02") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipwo4pah4oqc4ouVKeKIqeKJoEBcbixAIC4KCkNoZWNrIOKGkCDDl-KKgygvw5fiiaQz4oy1fOKJjcKkMeKMteKXtMKxKeKniC0K4oipLyviiaHil4fiioMoL-KGpeKJoShDaGVja-KWvSniip7iiaAu4oeh4qe74p-cwqR8Q2hlY2spCg== "Uiua solution for 2024/02") [<img height=12 src=".assets/rb.svg">](Ruby/2024/02.rb "Ruby solution for 2024/02")|[**3**](https://adventofcode.com/2024/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2024/03.rs "Rust solution for 2024/03") [<img height=12 src=".assets/hs.svg">](Haskell/2024/03.hs "Haskell solution for 2024/03") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrilr3irJoxXCjihqXihqfiipnCsOKKnynijYniip_CrOKIqeKMlSJkb24ndCgpIiwiZG8oKSIuLgriiKkoLysvw5fii5Xihpgx4o2JcmVnZXgibXVsXFwoKFxcZCspLChcXGQrKVxcKSIpCg== "Uiua solution for 2024/03") [<img height=12 src=".assets/rb.svg">](Ruby/2024/03.rb "Ruby solution for 2024/03")|[**4**](https://adventofcode.com/2024/day/4) [<img height=12 src=".assets/rs.svg">](Rust/2024/04.rs "Rust solution for 2024/04") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiiaBAXG4uCgripLAg4oaQIOKIqeKKleKWoeKKmSzijZzima3iipviip7iioMtK-KIqeKHocKw4oqf4oq44pazCgrin5woLyviiaHil4coLyvijJUiWE1BUyIp4oqC4p-c4o2a4oeM4oqC4oqDKOKKguKksHziioLiiKniiaHilqHin5zijYkpKQovK-KZreKniCjDl-KIqSgv4oal4omh4omN4pahIk1BUyLiioLin5zijZrih4wp4qSwKTNfMwo= "Uiua solution for 2024/04") [<img height=12 src=".assets/rb.svg">](Ruby/2024/04.rb "Ruby solution for 2024/04")|[**5**](https://adventofcode.com/2024/day/5) [<img height=12 src=".assets/rs.svg">](Rust/2024/05.rs "Rust solution for 2024/05") [<img height=12 src=".assets/hs.svg">](Haskell/2024/05.hs "Haskell solution for 2024/05") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriioPihpjihpniiqLiiprijJUiXG5cbiIuCuKKmSjiipziipzii5XiiKniiaBAXG4sQHwuKQriipwo4pah4oqc4ouVKeKIqeKJoEBcbixALC4KCk1pbiAgICDihpAg4oqi4pa9wqziirjiiIo64p-cKOKJoeKKo-KWveKIiuKKmeKKuOKJoeKKoikKUmVtb3ZlIOKGkCDiioLiioMo4oaZfOKGmCsxKeKKouKKmuKKuD0KU29ydCAgIOKGkCDiipnii4Xil4zijaIo4oqD4oqC4ouFUmVtb3Zl4oqZ4pehTWlufOKJoDDip7vil4wpW10KTWlkICAgIOKGkCDiio_ijIrDtzLiirjip7sKCuKIqSgvK-KJoeKXh01pZOKWvSkgwqwsLOKKuOKJoeKJjSDin5zijZpTb3J04oqZwqQK "Uiua solution for 2024/05") [<img height=12 src=".assets/rb.svg">](Ruby/2024/05.rb "Ruby solution for 2024/05")|[**6**](https://adventofcode.com/2024/day/6) [<img height=12 src=".assets/rs.svg">](Rust/2024/06.rs "Rust solution for 2024/06") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiiaBAXG4uCgpJbml0ICDihpAgwq8xXzDiiqLiipo9QF4KU3RlcCAg4oaQIOKorCjin5wrfOKHjOKNnOKKosKvKT1AI-KXoSjirJpALuKKoSspClZhbGlkIOKGkCAvw5fDl-KIqT7CrzEu4oqZ4pazCgptYXAuW10g4oq4SW5pdAomcOKKuOKnuyDiipnii4Xil4zijaIo4oqDKGluc2VydOKKmTA64oqZ4peMfOKLhVN0ZXApfOKLheKLhVZhbGlkKQoKU2tpcEZvcndhcmQg4oaQIOKNoijin5wrfMOX4oqDKOKLhVZhbGlkfOKJoEAj4qyaQC7iiqErKSkKQ2hlY2tDeWNsZSDihpAgKAogIG1hcC5bXSDiirhJbml0CiAg4o2iKOKKgyhpbnNlcnTiipkwOuKKmeKKgnzih4zijZziiqLCr1NraXBGb3J3YXJk4peMKXzCrGhhc-KWoTriipniioIpCiAgVmFsaWTii4Xil4wKKQoK4pa9PUAu4peh4oqh4oqZ4peMwrBtYXAKJnAgLyviiaF3YWl04omhcG9vbChDaGVja0N5Y2xl4o2c4oqh4ouFQCMp4oqZwqQK "Uiua solution for 2024/06")|[**7**](https://adventofcode.com/2024/day/7) [<img height=12 src=".assets/rs.svg">](Rust/2024/07.rs "Rust solution for 2024/07") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=IyBFeHBlcmltZW50YWwhCgomc2MKCuKKnCjiipnilqHCsOKKguKKnOKLlSniiaBAXG4swqziirjiiIoiOiAiCgpDaGVjayEg4oaQIHwyIOKNoygKICA94oqZwrDCpAp8IOKNoyjijaQuLkNoZWNrIV4w4o2c4oipKOKHjMKw4ouVKeKMneKKgl4wfOKNpC4uQ2hlY2shXjDijaQuPTDiioPil7_Dt3xDaGVjayFeMC0pIDriipnijZzih4zCsOKKgikKCuKIqSgvK8OXKeKJoSjin5w64p-c4oqDQ2hlY2sh4oiYQ2hlY2shKOKNpC4wKeKKmcKw4pahKQo= "Uiua solution for 2024/07")|[**8**](https://adventofcode.com/2024/day/8) [<img height=12 src=".assets/rs.svg">](Rust/2024/08.rs "Rust solution for 2024/08") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiiaBAXG4uCgpWYWxpZCDihpAgL8OXw5fiiKk-wq8xLgpXYWxrICDihpAg4oqZ4ouF4ouF4peM4o2iKOKKgyjiioLiipnil4x84ouF4p-cKyl84ouF4ouFVmFsaWQp4oavMC7iirgtCgriiaEo4pah4qeFPDLiipo9KeKKmcKk4pa94oq44omgQC7il7Tiirjima3in5wowqTCpOKWsykKCkEg4oaQIOKNmuKJoSjilqHilr064p-c4omhVmFsaWTiip_iiKkoK-KKuC0p4pehOsKw4oqfKQpCIOKGkCDijZriiaEo4pah4oqC4oipV2FsayDil6EoOuKKmeKKmeKImCnCsOKKnykKCuKIqSjip7vil7Qv4peH4oqC4o2aL-KXh-KKgikg4oqDQiBBCg== "Uiua solution for 2024/08")|
|[**9**](https://adventofcode.com/2024/day/9) [<img height=12 src=".assets/rs.svg">](Rust/2024/09.rs "Rust solution for 2024/09")|[**10**](https://adventofcode.com/2024/day/10) [<img height=12 src=".assets/rs.svg">](Rust/2024/10.rs "Rust solution for 2024/10") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiaHii5XiirjiiaBAXG4KCk5laWdoIOKGkCDilr09KzHiirjiiqI64p-c4qyaMOKKoSviioIwW-KXoeKIqcKv4p-c4oeM4oehMl3CpAriiKkvK-KJoSjiiKnip7vin5zil7TiiaHil4fiiqNwYXRoKE5laWdofD054oqhKSniipo9MOKfnMKkCg== "Uiua solution for 2024/10")|[**11**](https://adventofcode.com/2024/day/11) [<img height=12 src=".assets/rs.svg">](Rust/2024/11.rs "Rust solution for 2024/11") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipzii5XiirjiiIorQDDih6ExMAoKTmV4dCAg4oaQIOKNoyjCpDHCsDB84omh4ouV4oavMl_iiJ7CsDDil78y4oq44qe7wrDii5V8wqTDlzIwMjQpCkJsaW5rIOKGkCDiiKco4oinKOKNnOKsmjBnZXQr4oqZOilOZXh0KcKwbWFw4oqZKG1hcC5bXSkKCi8r4o2lQmxpbms1MCDin5wvK-KNpUJsaW5rMjUgbWFw4oqV4oqD4oqi4qe74oq44oqbCg== "Uiua solution for 2024/11")|[**12**](https://adventofcode.com/2024/day/12) [<img height=12 src=".assets/rs.svg">](Rust/2024/12.rs "Rust solution for 2024/12") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiirjiiaBAXG4KCuKKnOKWoSsx4oqD4o2c4pmt4oqbKOKHoeKWsykKCkEg4oaQIC8r4omhKC8rwqziiIo6K-KKguKfnMKv4ouvMV8ywqQp4p-cwqQKQiDihpAgKAogIOKXtOKZreKCguKKnistMcOXMuKLr-KHoTTin5zCpMOXMgogIC8r4omhKOKGpeKKgyjil78yLyt8w5cyL8OX4qeI4omgKeKIijorLTHDlzLijZzihpjigoLih4zii6_ih6E0wqQpCikKCuKIqSgvK8OXKeKKmSziiaHil4fiioNCIEEg4p-c4omh4peH4qe7Cg== "Uiua solution for 2024/12")|[**13**](https://adventofcode.com/2024/day/13) [<img height=12 src=".assets/rs.svg">](Rust/2024/13.rs "Rust solution for 2024/13") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrihq_iiJ5fM18y4oqc4ouV4oq44oiKK0Aw4oehMTAKCivCpFsuMCAxMDAwMDAwMDAwMDAwMF0uCuKIqSgvK-KJoeKNoygvK8OXM18x4omhKMKvwrAw4oqDL-KXvy_Dt-KniCgvLcOX4oeMKSniip_in5zijZzihpnigoLih4x8MCkpCg== "Uiua solution for 2024/13")|[**14**](https://adventofcode.com/2024/day/14) [<img height=12 src=".assets/rs.svg">](Rust/2024/14.rs "Rust solution for 2024/14") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipzii5XiirjiiIriioJALStAMOKHoTEwCuKGmTLiioLiipkxMDFfMTAz4oqD4oaY4oaZwq_ijZwo4pe_NCnii4Uw4oq44qe7CuKGr-KInl8yXzI6CgpTaW0g4oaQIOKXvzorw5fiipkoOsKw4oqf4qS4wq8yfMKkKQoKQSDihpAgL8OX4oqV4qe7LuKKm-KWveKJoDAvw5fiirjijYnCsS0rMcOXMuKKmcKk4oq4U2ltMTAwCkIg4oaQIOKKouKKmj3iirgv4oan4oy1L-KEguKNieKNnOKMhSjDt-KKg-Knuy8rKSjCsOKImi3CpCku4qS4MVNpbeKHoS_Dl-KkmeKIqcKkCgriioNCIEEK "Uiua solution for 2024/14")|[**15**](https://adventofcode.com/2024/day/15) [<img height=12 src=".assets/rs.svg">](Rust/2024/15.rs "Rust solution for 2024/15") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrCsCQiX1xuXG5fIgriipziiJjiirjiiaBAXG4K4oqP4oqX4oqZKCJ2Pl48IuKKguKfnMKv4ouvMV8yKSDilr3iirjiiIoiPD5ediI6CgpOZXh0IOKGkCAoCiAgOuKGr-KKmSgr4peh4ouF4oqZ4ouF4ouF4oiYKeKKuOKIiiJAT1tdIiDiiqHil6Hiipnii4Xii4Xii4XiiJgg4oqZ4oqZ4o2c4oqh4ouFMeKfnDoKICDiioLiqKwo4oqCKzBfMXziioItMF8xfOKXjCniipfiipkoIltdIjopCikKVGFyZ2V0cyDihpAg4oqa4ouF4oqZ4ouF4peM4o2iKOKorChOZXh0fOKXjCniiqHil6Hiipnii4XiiJjCsOKKgnziiaAw4qe7KSDCpOKKmSjiiLXii4UwLCk6Ck1vdmUg4oaQICgKICDCsDAv4oalPUAj4oqh4peh4ouF4oqZ4oiYIOKfnOKKuFRhcmdldHMKICDijZziiqHil4wrwqTiipko4p-c4o2c4oqh4omhKEAu4oiYKSDilr3iiaBALuKXoeKKoSkKKQpTb2x2ZSAg4oaQIC8r4pmtw5fCpDEwMF8x4oqa4oiKIk9bIiDil4ziiKfijaMo4oqDK01vdmV84peMKSDiipko4oqi4oqa4oq4PUBAKQpFeHBhbmQg4oaQIOKNnOKNieKZreKCguKorCgiLi4ifCIjIyJ8IkAuInwiW10iKeKItSjiipfiipkiLiNATyIpCgriiKlTb2x2ZSAsRXhwYW5kLAo= "Uiua solution for 2024/15")|
|[**16**](https://adventofcode.com/2024/day/16) [<img height=12 src=".assets/rs.svg">](Rust/2024/16.rs "Rust solution for 2024/16") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiirjiiaBAXG4KClN0ZXAg4oaQICgKICBb4o2cwrDiip_iirgrIOKfnOKNnOKKoyjih4zijZziiqPCrykg4p-c4o2c4oqjKOKNnOKKo8Kv4oeMKV0KICDiiKnihpjin5w6PUAj4oqh4oqZ4qSZ4oqZ4oqZ4peM4oqi4oqiLCBbMSAuMTAwMF0KKQoK4oqf4oqZMF8x4oqi4oqa4oq4PUBTCuKnu-KXtOKKouKkuDEv4peH4oqCIHBhdGgoU3RlcHw9QEXiiqHiiqIpCg== "Uiua solution for 2024/16")|[**17**](https://adventofcode.com/2024/day/17) [<img height=12 src=".assets/rs.svg">](Rust/2024/17.rs "Rust solution for 2024/17") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=IyBFeHBlcmltZW50YWwhCgomc2MKCuKKg-KGmeKGmDPiipzii5XiirjiiIorQDDih6ExMAoKQ29tYm8g4oaQIOKKj-KKlzrih6EzLTTiipniioLin5w6CgpBZHYg4oaQIOKNnOKKouKNnOKLr_CdhIjihpg64oq4Q29tYm8KQnhsIOKGkCDijZziio_igoHijZziiKnii6_irJow4omgOgpCc3Qg4oaQIOKNnOKKj-KCgeKXjDril7844oq4Q29tYm8KSm56IOKGkCDiqKwo4peMfOKKmSgtMnzil4wpOiniiaAw4oqiLApCeGMg4oaQIOKNnOKGmOKCgeKNnMKw4oqf4oq44o2c4oip4ouv4qyaMOKJoOKXjApPdXQg4oaQIOKKmeKKmeKKmeKKguKkmuKLheKKmeKKmeKKmeKImOKXvzjiirhDb21ibwpCZHYg4oaQIOKNnOKKj-KCgeKXjDrijZzii6_wnYSI4oaY4oqiLOKKuENvbWJvCkNkdiDihpAg4o2c4oqP4oKC4peMOuKNnOKLr_CdhIjihpjiiqIs4oq4Q29tYm8KClN0ZXAg4oaQIOKKmSvigoLiqKwoQWR2fEJ4bHxCc3R8Sm56fEJ4Y3xPdXR8QmR2fENkdikgwrDiip_iio8r4oehMuKXoeKLheKKmeKImApSdW4gIOKGkCDii4Xii4Xil4zijaIoU3RlcHw-4ouF4oqZ4qe7KeKKmSgwfFtdKQoKQ2hlY2sg4oaQIOKJjeKKmeKGmTogwq_iipko4oq4UnVu4o2c4oqi4peMOikKCuKXoCgv4peHKOKKguKKgilALMKw4ouVUnVuKQov4oan4oqj4oqj4o2JIHBhdGgo4pa9OuKfnOKJoShDaGVja8Kw4oqfKeKKmeKIqcKkK-KNieKKnzDih6E4wqTijZzCsOKKn-KKkyvigoHDl-KCiHw94oqT4oqi4ouF4qe7KTBfMAriiKkmcAo= "Uiua solution for 2024/17")|[**18**](https://adventofcode.com/2024/day/18)|[**19**](https://adventofcode.com/2024/day/19)|[**20**](https://adventofcode.com/2024/day/20)|[**21**](https://adventofcode.com/2024/day/21)|[**22**](https://adventofcode.com/2024/day/22)|
|[**16**](https://adventofcode.com/2024/day/16) [<img height=12 src=".assets/rs.svg">](Rust/2024/16.rs "Rust solution for 2024/16") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipziiJjiirjiiaBAXG4KClN0ZXAg4oaQICgKICBb4o2cwrDiip_iirgrIOKfnOKNnOKKoyjih4zijZziiqPCrykg4p-c4o2c4oqjKOKNnOKKo8Kv4oeMKV0KICDiiKnihpjin5w6PUAj4oqh4oqZ4qSZ4oqZ4oqZ4peM4oqi4oqiLCBbMSAuMTAwMF0KKQoK4oqf4oqZMF8x4oqi4oqa4oq4PUBTCuKnu-KXtOKKouKkuDEv4peH4oqCIHBhdGgoU3RlcHw9QEXiiqHiiqIpCg== "Uiua solution for 2024/16")|[**17**](https://adventofcode.com/2024/day/17) [<img height=12 src=".assets/rs.svg">](Rust/2024/17.rs "Rust solution for 2024/17") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=IyBFeHBlcmltZW50YWwhCgomc2MKCuKKg-KGmeKGmDPiipzii5XiirjiiIorQDDih6ExMAoKQ29tYm8g4oaQIOKKj-KKlzrih6EzLTTiipniioLin5w6CgpBZHYg4oaQIOKNnOKKouKNnOKLr_CdhIjihpg64oq4Q29tYm8KQnhsIOKGkCDijZziio_igoHijZziiKnii6_irJow4omgOgpCc3Qg4oaQIOKNnOKKj-KCgeKXjDril7844oq4Q29tYm8KSm56IOKGkCDiqKwo4peMfOKKmSgtMnzil4wpOiniiaAw4oqiLApCeGMg4oaQIOKNnOKGmOKCgeKNnMKw4oqf4oq44o2c4oip4ouv4qyaMOKJoOKXjApPdXQg4oaQIOKKmeKKmeKKmeKKguKkmuKLheKKmeKKmeKKmeKImOKXvzjiirhDb21ibwpCZHYg4oaQIOKNnOKKj-KCgeKXjDrijZzii6_wnYSI4oaY4oqiLOKKuENvbWJvCkNkdiDihpAg4o2c4oqP4oKC4peMOuKNnOKLr_CdhIjihpjiiqIs4oq4Q29tYm8KClN0ZXAg4oaQIOKKmSvigoLiqKwoQWR2fEJ4bHxCc3R8Sm56fEJ4Y3xPdXR8QmR2fENkdikgwrDiip_iio8r4oehMuKXoeKLheKKmeKImApSdW4gIOKGkCDii4Xii4Xil4zijaIoU3RlcHw-4ouF4oqZ4qe7KeKKmSgwfFtdKQoKQ2hlY2sg4oaQIOKJjeKKmeKGmTogwq_iipko4oq4UnVu4o2c4oqi4peMOikKCuKXoCgv4peHKOKKguKKgilALMKw4ouVUnVuKQov4oan4oqj4oqj4o2JIHBhdGgo4pa9OuKfnOKJoShDaGVja8Kw4oqfKeKKmeKIqcKkK-KNieKKnzDih6E4wqTijZzCsOKKn-KKkyvigoHDl-KCiHw94oqT4oqi4ouF4qe7KTBfMAriiKkmcAo= "Uiua solution for 2024/17")|[**18**](https://adventofcode.com/2024/day/18) [<img height=12 src=".assets/rs.svg">](Rust/2024/18.rs "Rust solution for 2024/18")|[**19**](https://adventofcode.com/2024/day/19)|[**20**](https://adventofcode.com/2024/day/20)|[**21**](https://adventofcode.com/2024/day/21)|[**22**](https://adventofcode.com/2024/day/22)|
|[**23**](https://adventofcode.com/2024/day/23)|[**24**](https://adventofcode.com/2024/day/24)|[**25**](https://adventofcode.com/2024/day/25)|26|27|28|29|
|30|31||||||

Expand Down
94 changes: 94 additions & 0 deletions Rust/2024/18.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#![feature(test)]

use std::collections::VecDeque;

use aoc::grid::Direction;
use itertools::Itertools;

struct Input {
width: usize,
height: usize,
grid: Vec<usize>,
prefix_len: usize,
bytes: Vec<(usize, usize)>,
}

fn setup(input: &str) -> Input {
let mut lines = input.trim().lines().peekable();
let (width, height, prefix_len) = match lines.next_if(|l| l.starts_with('#')) {
Some(line) => line
.trim_start_matches('#')
.split_whitespace()
.map(|n| n.parse().unwrap())
.collect_tuple()
.unwrap(),
None => (71, 71, 1024),
};

let bytes = lines
.map(|l| {
l.split(',')
.map(|n| n.parse().unwrap())
.collect_tuple()
.unwrap()
})
.collect::<Vec<_>>();

let mut grid = vec![usize::MAX; width * height];
for (i, &(x, y)) in bytes.iter().enumerate() {
grid[y * width + x] = i;
}

Input {
width,
height,
grid,
prefix_len,
bytes,
}
}

fn bfs(input: &Input, prefix_len: usize) -> Option<usize> {
let mut queue = VecDeque::from([(0, 0, 0)]);
let mut visited = vec![false; input.width * input.height];
while let Some((d, x, y)) = queue.pop_front() {
let idx = y * input.width + x;
if std::mem::replace(&mut visited[idx], true) {
continue;
}

if (x, y) == (input.width - 1, input.height - 1) {
return Some(d);
}

queue.extend(
Direction::iter()
.flat_map(|d| d.step(x, y, input.width, input.height))
.filter(|&(nx, ny)| input.grid[ny * input.width + nx] >= prefix_len)
.map(|(nx, ny)| (d + 1, nx, ny)),
);
}

None
}

fn part1(input: &Input) -> usize {
bfs(input, input.prefix_len).unwrap()
}

fn part2(input: &Input) -> String {
let mut left = 0;
let mut right = input.bytes.len();
while left + 1 < right {
let m = left.midpoint(right);
match bfs(input, m) {
Some(_) => left = m,
None => right = m,
}
}
debug_assert_eq!(left + 1, right);
let (x, y) = input.bytes[right - 1];
format!("{x},{y}")
}

aoc::main!(2024, 18, ex: 1);
2 changes: 1 addition & 1 deletion Rust/2024/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ aoc::year! {
"15.rs",
"16.rs",
"17.rs",
// "18.rs",
"18.rs",
// "19.rs",
// "20.rs",
// "21.rs",
Expand Down
3 changes: 3 additions & 0 deletions Rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,6 @@ path = "2024/16.rs"
[[bin]]
name = "2024_17"
path = "2024/17.rs"
[[bin]]
name = "2024_18"
path = "2024/18.rs"
26 changes: 26 additions & 0 deletions examples/2024/18/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 7 7 12
5,4
4,2
4,5
3,0
2,1
6,3
2,4
1,5
0,6
3,3
2,6
5,1
1,2
5,5
2,5
6,5
1,4
0,4
6,4
1,1
6,1
1,0
0,5
1,6
2,0
1 change: 1 addition & 0 deletions examples/2024/18/1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
1 change: 1 addition & 0 deletions examples/2024/18/1.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6,1

0 comments on commit 227d78c

Please sign in to comment.