├── .gitignore ├── NOTES.md ├── README-2020.md ├── README-2021.md ├── README-2022.md ├── README-2023.md ├── README-2024.md ├── README.md ├── assets ├── calendar_2020.png ├── calendar_2021.png ├── calendar_2022.png ├── calendar_2023.png └── golang.png ├── c └── 2023 │ ├── 15 │ ├── Makefile │ ├── hashtable.c │ ├── hashtable.h │ ├── main.c │ ├── main.h │ └── sample.txt │ └── 01 │ ├── Makefile │ ├── main.c │ ├── main.h │ ├── sample.txt │ └── sample2.txt ├── go ├── 2018 │ ├── 10 │ │ ├── day10.go │ │ ├── day10_test.go │ │ └── sample.txt │ ├── 11 │ │ ├── day11.go │ │ └── day11_test.go │ ├── 12 │ │ ├── day12.go │ │ ├── day12_test.go │ │ └── sample.txt │ ├── 13 │ │ ├── day13.go │ │ ├── day13_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 14 │ │ ├── day14.go │ │ └── day14_test.go │ ├── 16 │ │ ├── day16.go │ │ ├── day16_test.go │ │ └── sample.txt │ ├── 17 │ │ ├── day17.go │ │ ├── day17_test.go │ │ └── sample.txt │ ├── 18 │ │ ├── day18.go │ │ ├── day18_test.go │ │ └── sample.txt │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ └── sample.txt │ ├── 21 │ │ ├── code.txt │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ └── sample.txt │ ├── 23 │ │ ├── day23.go │ │ ├── day23_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ └── sample.txt │ ├── 25 │ │ ├── day25.go │ │ ├── day25_test.go │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ └── day01_test.go │ ├── 02 │ │ ├── day02.go │ │ └── day02_test.go │ ├── 03 │ │ ├── day03.go │ │ └── day03_test.go │ ├── 04 │ │ ├── day04.go │ │ ├── day04_test.go │ │ └── sample.txt │ ├── 05 │ │ ├── day05.go │ │ ├── day05_test.go │ │ └── sample.txt │ ├── 06 │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ ├── day07_test.go │ │ └── sample.txt │ ├── 08 │ │ ├── day08.go │ │ ├── day08_test.go │ │ └── sample.txt │ ├── 09 │ │ ├── day09.go │ │ └── day09_test.go │ └── device │ │ └── device.go ├── 2020 │ ├── 10 │ │ ├── day10.go │ │ └── day10_test.go │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ └── sample.txt │ ├── 21 │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ └── sample.txt │ ├── 23 │ │ ├── day23.go │ │ └── day23_test.go │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ └── sample.txt │ ├── 25 │ │ ├── day25.go │ │ ├── day25_test.go │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ ├── day01_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ └── day07_test.go │ ├── 08 │ │ ├── day08.go │ │ └── day08_test.go │ └── 09 │ │ ├── day09.go │ │ └── day09_test.go ├── 2021 │ ├── 10 │ │ ├── day10.go │ │ ├── day10_test.go │ │ └── sample.txt │ ├── 11 │ │ ├── day11.go │ │ ├── day11_test.go │ │ └── sample.txt │ ├── 12 │ │ ├── day12.go │ │ └── day12_test.go │ ├── 13 │ │ ├── day13.go │ │ ├── day13_test.go │ │ └── sample.txt │ ├── 14 │ │ ├── day14.go │ │ ├── day14_test.go │ │ └── sample.txt │ ├── 15 │ │ ├── day15.go │ │ ├── day15_test.go │ │ ├── matrix_test.txt │ │ └── sample.txt │ ├── 16 │ │ ├── day16.go │ │ └── day16_test.go │ ├── 17 │ │ ├── day17.go │ │ └── day17_test.go │ ├── 18 │ │ ├── day18.go │ │ ├── day18_test.go │ │ └── sample.txt │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ └── sample.txt │ ├── 21 │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ ├── sample.txt │ │ ├── world.go │ │ └── world_test.go │ ├── 23 │ │ ├── day23.go │ │ ├── day23_test.go │ │ ├── input2.txt │ │ └── input3.txt │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ ├── eval_interval.go │ │ └── generator.go │ ├── 25 │ │ ├── day25.go │ │ ├── day25_test.go │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ ├── day01_test.go │ │ └── sample.txt │ ├── 02 │ │ ├── day02.go │ │ ├── day02_test.go │ │ └── sample.txt │ ├── 06 │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ ├── day07_test.go │ │ └── sample.txt │ ├── 09 │ │ ├── day09.go │ │ ├── day09_test.go │ │ └── sample.txt │ ├── 09_simplified │ │ ├── day09.go │ │ ├── day09_test.go │ │ └── sample.txt │ └── 24_compiled │ │ ├── run.go │ │ └── search.go ├── 2022 │ ├── 10 │ │ ├── day10.go │ │ ├── day10_test.go │ │ └── sample.txt │ ├── 11 │ │ ├── day11.go │ │ ├── day11_test.go │ │ └── sample.txt │ ├── 12 │ │ ├── day12.go │ │ ├── day12_test.go │ │ └── sample.txt │ ├── 13 │ │ ├── day13.go │ │ ├── day13_test.go │ │ └── sample.txt │ ├── 14 │ │ ├── day14.go │ │ ├── day14_test.go │ │ └── sample.txt │ ├── 15 │ │ ├── day15.go │ │ ├── day15_test.go │ │ └── sample.txt │ ├── 16 │ │ ├── day16.go │ │ ├── day16_test.go │ │ └── sample.txt │ ├── 17 │ │ ├── day17.go │ │ ├── day17_test.go │ │ └── sample.txt │ ├── 18 │ │ ├── day18.go │ │ ├── day18_test.go │ │ └── sample.txt │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ └── sample.txt │ ├── 21 │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ └── sample.txt │ ├── 23 │ │ ├── day23.go │ │ ├── day23_test.go │ │ └── sample.txt │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ └── sample.txt │ ├── 25 │ │ ├── day25.go │ │ ├── day25_test.go │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ ├── day01_test.go │ │ └── sample.txt │ ├── 02 │ │ ├── day02.go │ │ ├── day02_test.go │ │ └── sample.txt │ ├── 03 │ │ ├── day03.go │ │ ├── day03_test.go │ │ └── sample.txt │ ├── 04 │ │ ├── day04.go │ │ ├── day04_test.go │ │ └── sample.txt │ ├── 05 │ │ ├── day05.go │ │ ├── day05_test.go │ │ └── sample.txt │ ├── 06 │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ ├── day07_test.go │ │ ├── fs.go │ │ └── sample.txt │ ├── 08 │ │ ├── day08.go │ │ ├── day08_test.go │ │ └── sample.txt │ └── 09 │ │ ├── day09.go │ │ ├── day09_test.go │ │ ├── sample.txt │ │ └── sample2.txt ├── 2023 │ ├── 10 │ │ ├── day10.go │ │ ├── day10_test.go │ │ ├── sample.txt │ │ ├── sample2_1.txt │ │ ├── sample2_2.txt │ │ └── sample2_3.txt │ ├── 11 │ │ ├── day11.go │ │ ├── day11_test.go │ │ └── sample.txt │ ├── 12 │ │ ├── day12.go │ │ ├── day12_test.go │ │ └── sample.txt │ ├── 13 │ │ ├── day13.go │ │ ├── day13_test.go │ │ └── sample.txt │ ├── 14 │ │ ├── day14.go │ │ ├── day14_test.go │ │ └── sample.txt │ ├── 15 │ │ ├── day15.go │ │ ├── day15_test.go │ │ └── sample.txt │ ├── 16 │ │ ├── day16.go │ │ ├── day16_test.go │ │ └── sample.txt │ ├── 17 │ │ ├── day17.go │ │ ├── day17_test.go │ │ └── sample.txt │ ├── 18 │ │ ├── day18.go │ │ ├── day18_test.go │ │ └── sample.txt │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 21 │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ └── sample.txt │ ├── 23 │ │ ├── day23.go │ │ ├── day23_test.go │ │ └── sample.txt │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ └── sample.txt │ ├── 25 │ │ ├── graph1.dot │ │ ├── graph1.svg │ │ ├── graph2.dot │ │ ├── graph2.svg │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ ├── day01_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 02 │ │ ├── day02.go │ │ ├── day02_test.go │ │ └── sample.txt │ ├── 03 │ │ ├── day03.go │ │ ├── day03_test.go │ │ └── sample.txt │ ├── 04 │ │ ├── day04.go │ │ ├── day04_test.go │ │ └── sample.txt │ ├── 05 │ │ ├── day05.go │ │ ├── day05_test.go │ │ └── sample.txt │ ├── 06 │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ ├── day07_test.go │ │ └── sample.txt │ ├── 08 │ │ ├── day08.go │ │ ├── day08_test.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 09 │ │ ├── day09.go │ │ ├── day09_test.go │ │ └── sample.txt │ ├── 12Worker │ │ ├── day12.go │ │ ├── day12_test.go │ │ └── sample.txt │ ├── 16Recursive │ │ ├── day16.go │ │ ├── day16_test.go │ │ └── sample.txt │ └── 19Tree │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt ├── 2024 │ ├── 10 │ │ ├── day10.go │ │ ├── day10_test.go │ │ └── sample.txt │ ├── 11 │ │ ├── day11.go │ │ ├── day11_test.go │ │ └── sample.txt │ ├── 12 │ │ ├── day12.go │ │ ├── day12_test.go │ │ └── sample.txt │ ├── 13 │ │ ├── day13.go │ │ ├── day13_test.go │ │ └── sample.txt │ ├── 14 │ │ ├── day14.go │ │ ├── day14_test.go │ │ └── sample.txt │ ├── 15 │ │ ├── day15.go │ │ ├── day15_test.go │ │ └── sample.txt │ ├── 16 │ │ ├── day16.go │ │ ├── day16_test.go │ │ └── sample.txt │ ├── 17 │ │ ├── code.txt │ │ ├── day17.go │ │ ├── day17_test.go │ │ ├── device.go │ │ ├── sample.txt │ │ └── sample2.txt │ ├── 18 │ │ ├── day18.go │ │ ├── day18_test.go │ │ └── sample.txt │ ├── 19 │ │ ├── day19.go │ │ ├── day19_test.go │ │ └── sample.txt │ ├── 20 │ │ ├── day20.go │ │ ├── day20_test.go │ │ └── sample.txt │ ├── 21 │ │ ├── day21.go │ │ ├── day21_test.go │ │ └── sample.txt │ ├── 22 │ │ ├── day22.go │ │ ├── day22_test.go │ │ └── sample.txt │ ├── 23 │ │ ├── day23.go │ │ ├── day23_test.go │ │ └── sample.txt │ ├── 24 │ │ ├── day24.go │ │ ├── day24_test.go │ │ └── sample.txt │ ├── 25 │ │ ├── day25.go │ │ ├── day25_test.go │ │ └── sample.txt │ ├── 01 │ │ ├── day01.go │ │ ├── day01_test.go │ │ └── sample.txt │ ├── 02 │ │ ├── day02.go │ │ ├── day02_test.go │ │ └── sample.txt │ ├── 03 │ │ ├── day03.go │ │ └── day03_test.go │ ├── 03Efficient │ │ ├── day03.go │ │ └── day03_test.go │ ├── 04 │ │ ├── day04.go │ │ ├── day04_test.go │ │ └── sample.txt │ ├── 05 │ │ ├── day05.go │ │ ├── day05_test.go │ │ └── sample.txt │ ├── 05Simplified │ │ ├── day05.go │ │ ├── day05_test.go │ │ └── sample.txt │ ├── 06 │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 06Matrix │ │ ├── day06.go │ │ ├── day06_test.go │ │ └── sample.txt │ ├── 07 │ │ ├── day07.go │ │ ├── day07_test.go │ │ └── sample.txt │ ├── 08 │ │ ├── day08.go │ │ ├── day08_test.go │ │ └── sample.txt │ └── 09 │ │ ├── day09.go │ │ ├── day09_test.go │ │ └── sample.txt ├── README.md ├── go.mod ├── go.sum └── utils │ ├── cycle.go │ ├── cycle_test.go │ ├── game2d │ ├── game2d.go │ ├── matrix.go │ └── pos.go │ ├── interval │ ├── cuboid.go │ ├── cuboid_test.go │ └── interval.go │ ├── loadinput.go │ ├── math.go │ ├── pathfinding.go │ ├── priorityqueue │ ├── priorityqueue.go │ └── priorityqueue_test.go │ ├── set │ └── set.go │ ├── stack │ └── stack.go │ └── utils.go ├── rust ├── 2019 │ ├── day01 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day02 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day03 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day04 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day05 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day06 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ ├── sample2.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day07 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day08 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day09 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day10 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ ├── sample2.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day11 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day12 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day13 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day14 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ ├── sample3.txt │ │ ├── sample4.txt │ │ ├── sample5.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day15 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day16 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day17 │ │ ├── Cargo.toml │ │ ├── sol.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day18 │ │ ├── Cargo.toml │ │ ├── sample1.txt │ │ ├── sample2.txt │ │ ├── sample3.txt │ │ ├── sample4.txt │ │ ├── sample5.txt │ │ ├── sample6.txt │ │ ├── sample7.txt │ │ ├── sample8.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day19 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day20 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ ├── sample2.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day21 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day22 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day23 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day24 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day25 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ └── intcode │ │ ├── Cargo.toml │ │ └── src │ │ └── lib.rs ├── 2020 │ ├── borrow │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── day01 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day02 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day03 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day04 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day05 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day06 │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day11 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day12 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day13 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day14 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ ├── sample2.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day15 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day16 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day17 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ └── day18 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ ├── lib.rs │ │ ├── main.rs │ │ └── tests.rs ├── 2021 │ ├── day01 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day02 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day03 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day04 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day05 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day06 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── main.rs │ │ │ └── tests.rs │ ├── day07 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day08 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day10 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ ├── day11 │ │ ├── Cargo.toml │ │ ├── benches │ │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ └── day13 │ │ ├── Cargo.toml │ │ ├── benches │ │ └── benchmark.rs │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ ├── lib.rs │ │ └── main.rs ├── 2022 │ └── day18 │ │ ├── Cargo.toml │ │ ├── rustfmt.toml │ │ ├── sample.txt │ │ └── src │ │ ├── lib.rs │ │ └── main.rs ├── .gitignore ├── template │ └── day01 │ │ ├── Cargo.toml │ │ ├── sample.txt │ │ └── src │ │ ├── lib.rs │ │ ├── main.rs │ │ └── tests.rs └── utils │ ├── Cargo.toml │ └── src │ ├── lib.rs │ └── parsing.rs └── tools ├── initaoc ├── go.mod └── main.go └── wip ├── heapq.go └── heapq_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | **/session.txt 4 | **/input.txt 5 | 6 | # Generated by Cargo 7 | # will have compiled files and executables 8 | /target/ 9 | 10 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 11 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 12 | Cargo.lock 13 | 14 | # These are backup files generated by rustfmt 15 | **/*.rs.bk 16 | go/2020/20/res 17 | go/initaoc/initaoc 18 | 19 | # vim 20 | **/*.swp 21 | **/*.swo 22 | 23 | #OSX 24 | **/.DS_Store 25 | 26 | #C 27 | **/*.out 28 | **/*.o 29 | **/main 30 | 31 | -------------------------------------------------------------------------------- /NOTES.md: -------------------------------------------------------------------------------- 1 | Some interesting repositories 2 | 3 | ### Go 4 | 5 | https://github.com/bozdoz/advent-of-code-2021 6 | https://github.com/Skarlso/aoc2021 7 | https://github.com/danvk/aoc2021 8 | https://github.com/Maitgon/Advent2021/tree/master/Go 9 | https://github.com/alexchao26/advent-of-code-go/tree/main/2021 10 | https://github.com/sebnyberg/aoc/tree/main/aoc2021 11 | https://github.com/jdrst/adventofgo/tree/main/2021 12 | https://github.com/sekullbe/advent-of-code 13 | https://github.com/derat/advent-of-code/tree/main/2021 14 | 15 | https://github.com/janetschel/advent-of-go-2020 16 | 17 | ### Rust 18 | 19 | https://github.com/jontmy/aoc-rust/tree/master/src 20 | https://github.com/AxlLind/adventofcode2021 21 | 22 | ### Python (smart) 23 | 24 | https://github.com/r0f1/adventofcode2021 25 | 26 | pour info pour profiler j'ai fait ça : 27 | 28 | - j'ai ajouté un test qui appelle Part1 au lieu du main 29 | - j'ai fait go test -cpuprofile cpu.prof -bench . 30 | - puis go tool pprof -http=:8800 cpu.prof 31 | -------------------------------------------------------------------------------- /assets/calendar_2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/assets/calendar_2020.png -------------------------------------------------------------------------------- /assets/calendar_2021.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/assets/calendar_2021.png -------------------------------------------------------------------------------- /assets/calendar_2022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/assets/calendar_2022.png -------------------------------------------------------------------------------- /assets/calendar_2023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/assets/calendar_2023.png -------------------------------------------------------------------------------- /assets/golang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/assets/golang.png -------------------------------------------------------------------------------- /c/2023/01/Makefile: -------------------------------------------------------------------------------- 1 | all:main 2 | 3 | main:main.o 4 | gcc -o main main.o 5 | 6 | main.o:main.c 7 | gcc -Wall -W -c main.c 8 | 9 | run:main 10 | ./main 11 | 12 | clean: 13 | rm -f main.o main -------------------------------------------------------------------------------- /c/2023/01/main.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by pem on 14/12/2023. 3 | // 4 | 5 | #ifndef MAIN_H 6 | #define MAIN_H 7 | 8 | #endif //MAIN_H 9 | -------------------------------------------------------------------------------- /c/2023/01/sample.txt: -------------------------------------------------------------------------------- 1 | 1abc2 2 | pqr3stu8vwx 3 | a1b2c3d4e5f 4 | treb7uchet -------------------------------------------------------------------------------- /c/2023/01/sample2.txt: -------------------------------------------------------------------------------- 1 | two1nine 2 | eightwothree 3 | abcone2threexyz 4 | xtwone3four 5 | 4nineeightseven2 6 | zoneight234 7 | 7pqrstsixteen -------------------------------------------------------------------------------- /c/2023/15/Makefile: -------------------------------------------------------------------------------- 1 | FLAGS = -Wall -W -O2 2 | 3 | all:main 4 | 5 | main: main.o hashtable.o 6 | gcc -o main main.o hashtable.o 7 | 8 | test_main: main.o hashtable.o 9 | gcc -o test_main -DTEST main.c hashtable.o 10 | 11 | main.o: main.c main.h 12 | gcc ${FLAGS} -c main.c 13 | 14 | hashtable.o: hashtable.c hashtable.h 15 | gcc ${FLAGS} -c hashtable.c 16 | 17 | run:main 18 | ./main 19 | 20 | test: test_main 21 | ./test_main 22 | 23 | clean: 24 | rm -f *.o main -------------------------------------------------------------------------------- /c/2023/15/hashtable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by pem on 16/12/2023. 3 | // 4 | 5 | #ifndef ADVENT_OF_CODE_HASHTABLE_H 6 | #define ADVENT_OF_CODE_HASHTABLE_H 7 | 8 | typedef struct _Entry { 9 | char *key; 10 | int value; 11 | struct _Entry *next; 12 | } Entry; 13 | 14 | typedef struct _Hashtable { 15 | Entry **entries; 16 | int size; 17 | } Hashtable; 18 | 19 | Hashtable *newHashtable(); 20 | 21 | int hash(char *key); 22 | 23 | void put(Hashtable *ht, char *key, int value); 24 | 25 | void removeEntry(Hashtable *ht, char *key); 26 | 27 | void print_table(Hashtable *ht); 28 | void print_entries(Entry *entry); 29 | 30 | #endif //ADVENT_OF_CODE_HASHTABLE_H 31 | -------------------------------------------------------------------------------- /c/2023/15/main.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by pem on 14/12/2023. 3 | // 4 | 5 | #ifndef MAIN_H 6 | #define MAIN_H 7 | 8 | extern int part1(char *filename); 9 | 10 | extern int part2(char *filename); 11 | 12 | #endif //MAIN_H 13 | -------------------------------------------------------------------------------- /c/2023/15/sample.txt: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 -------------------------------------------------------------------------------- /go/2018/01/day01_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 416 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 56752 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2018/02/day02_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 8610 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := "iosnxmfkpabcjpdywvrtahluy" 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2018/03/day03_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 98005 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 331 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2018/04/sample.txt: -------------------------------------------------------------------------------- 1 | [1518-11-01 00:00] Guard #10 begins shift 2 | [1518-11-01 00:05] falls asleep 3 | [1518-11-01 00:25] wakes up 4 | [1518-11-01 00:30] falls asleep 5 | [1518-11-01 00:55] wakes up 6 | [1518-11-01 23:58] Guard #99 begins shift 7 | [1518-11-02 00:40] falls asleep 8 | [1518-11-02 00:50] wakes up 9 | [1518-11-03 00:05] Guard #10 begins shift 10 | [1518-11-03 00:24] falls asleep 11 | [1518-11-03 00:29] wakes up 12 | [1518-11-04 00:02] Guard #99 begins shift 13 | [1518-11-04 00:36] falls asleep 14 | [1518-11-04 00:46] wakes up 15 | [1518-11-05 00:03] Guard #99 begins shift 16 | [1518-11-05 00:45] falls asleep 17 | [1518-11-05 00:55] wakes up -------------------------------------------------------------------------------- /go/2018/05/sample.txt: -------------------------------------------------------------------------------- 1 | dabAcCaCBAcCcaDA -------------------------------------------------------------------------------- /go/2018/06/sample.txt: -------------------------------------------------------------------------------- 1 | 1, 1 2 | 1, 6 3 | 8, 3 4 | 3, 4 5 | 5, 5 6 | 8, 9 -------------------------------------------------------------------------------- /go/2018/07/sample.txt: -------------------------------------------------------------------------------- 1 | Step C must be finished before step A can begin. 2 | Step C must be finished before step F can begin. 3 | Step A must be finished before step B can begin. 4 | Step A must be finished before step D can begin. 5 | Step B must be finished before step E can begin. 6 | Step D must be finished before step E can begin. 7 | Step F must be finished before step E can begin. -------------------------------------------------------------------------------- /go/2018/08/sample.txt: -------------------------------------------------------------------------------- 1 | 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2 -------------------------------------------------------------------------------- /go/2018/10/day10_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart2Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part2(inputDay) 12 | expected := 10101 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func BenchmarkPart1(b *testing.B) { 19 | var inputDay = utils.Input() 20 | for range b.N { 21 | Part1(inputDay) 22 | } 23 | } 24 | 25 | func BenchmarkPart2(b *testing.B) { 26 | var inputDay = utils.Input() 27 | for range b.N { 28 | Part2(inputDay) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /go/2018/10/sample.txt: -------------------------------------------------------------------------------- 1 | position=< 9, 1> velocity=< 0, 2> 2 | position=< 7, 0> velocity=<-1, 0> 3 | position=< 3, -2> velocity=<-1, 1> 4 | position=< 6, 10> velocity=<-2, -1> 5 | position=< 2, -4> velocity=< 2, 2> 6 | position=<-6, 10> velocity=< 2, -2> 7 | position=< 1, 8> velocity=< 1, -1> 8 | position=< 1, 7> velocity=< 1, 0> 9 | position=<-3, 11> velocity=< 1, -2> 10 | position=< 7, 6> velocity=<-1, -1> 11 | position=<-2, 3> velocity=< 1, 0> 12 | position=<-4, 3> velocity=< 2, 0> 13 | position=<10, -3> velocity=<-1, 1> 14 | position=< 5, 11> velocity=< 1, -2> 15 | position=< 4, 7> velocity=< 0, -1> 16 | position=< 8, -2> velocity=< 0, 1> 17 | position=<15, 0> velocity=<-2, 0> 18 | position=< 1, 6> velocity=< 1, 0> 19 | position=< 8, 9> velocity=< 0, -1> 20 | position=< 3, 3> velocity=<-1, 1> 21 | position=< 0, 5> velocity=< 0, -1> 22 | position=<-2, 2> velocity=< 2, 0> 23 | position=< 5, -2> velocity=< 1, 2> 24 | position=< 1, 4> velocity=< 2, 1> 25 | position=<-2, 7> velocity=< 2, -2> 26 | position=< 3, 6> velocity=<-1, -1> 27 | position=< 5, 0> velocity=< 1, 0> 28 | position=<-6, 0> velocity=< 2, 0> 29 | position=< 5, 9> velocity=< 1, -2> 30 | position=<14, 7> velocity=<-2, 0> 31 | position=<-3, 6> velocity=< 2, -1> -------------------------------------------------------------------------------- /go/2018/11/day11_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := "216,12" 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := "236,175,11" 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | 34 | func BenchmarkPart2(b *testing.B) { 35 | var inputDay = utils.Input() 36 | for range b.N { 37 | Part2(inputDay) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /go/2018/12/day12_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 2911 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 2500000000695 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | 34 | func BenchmarkPart2(b *testing.B) { 35 | var inputDay = utils.Input() 36 | for range b.N { 37 | Part2(inputDay) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /go/2018/12/sample.txt: -------------------------------------------------------------------------------- 1 | initial state: #..#.#..##......###...### 2 | 3 | ...## => # 4 | ..#.. => # 5 | .#... => # 6 | .#.#. => # 7 | .#.## => # 8 | .##.. => # 9 | .#### => # 10 | #.#.# => # 11 | #.### => # 12 | ##.#. => # 13 | ##.## => # 14 | ###.. => # 15 | ###.# => # 16 | ####. => # -------------------------------------------------------------------------------- /go/2018/13/sample.txt: -------------------------------------------------------------------------------- 1 | /->-\ 2 | | | /----\ 3 | | /-+--+-\ | 4 | | | | | v | 5 | \-+-/ \-+--/ 6 | \------/ 7 | -------------------------------------------------------------------------------- /go/2018/13/sample2.txt: -------------------------------------------------------------------------------- 1 | />-<\ 2 | | | 3 | | /<+-\ 4 | | | | v 5 | \>+/ -------------------------------------------------------------------------------- /go/2018/14/day14_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := "1041411104" 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 20174745 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | 34 | func BenchmarkPart2(b *testing.B) { 35 | var inputDay = utils.Input() 36 | for range b.N { 37 | Part2(inputDay) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /go/2018/16/day16_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 614 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 656 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | 34 | func BenchmarkPart2(b *testing.B) { 35 | var inputDay = utils.Input() 36 | for range b.N { 37 | Part2(inputDay) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /go/2018/16/sample.txt: -------------------------------------------------------------------------------- 1 | Before: [3, 2, 1, 1] 2 | 9 2 1 2 3 | After: [3, 2, 2, 1] 4 | 5 | 6 | 7 | 0 0 0 0 -------------------------------------------------------------------------------- /go/2018/17/sample.txt: -------------------------------------------------------------------------------- 1 | x=495, y=2..7 2 | y=7, x=495..501 3 | x=501, y=3..7 4 | x=498, y=2..4 5 | x=506, y=1..2 6 | x=498, y=10..13 7 | x=504, y=10..13 8 | y=13, x=498..504 -------------------------------------------------------------------------------- /go/2018/18/sample.txt: -------------------------------------------------------------------------------- 1 | .#.#...|#. 2 | .....#|##| 3 | .|..|...#. 4 | ..|#.....# 5 | #.#|||#|#| 6 | ...#.||... 7 | .|....|... 8 | ||...#|.#| 9 | |.||||..|. 10 | ...#.|..|. -------------------------------------------------------------------------------- /go/2018/19/day19_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 1694 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func BenchmarkPart1(b *testing.B) { 19 | var inputDay = utils.Input() 20 | for range b.N { 21 | Part1(inputDay) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /go/2018/19/sample.txt: -------------------------------------------------------------------------------- 1 | #ip 0 2 | seti 5 0 1 3 | seti 6 0 2 4 | addi 0 1 0 5 | addr 1 2 3 6 | setr 1 0 0 7 | seti 8 0 4 8 | seti 9 0 5 -------------------------------------------------------------------------------- /go/2018/20/sample.txt: -------------------------------------------------------------------------------- 1 | ^ENWWW(NEEE|SSE(EE|N))$ -------------------------------------------------------------------------------- /go/2018/21/code.txt: -------------------------------------------------------------------------------- 1 | 0: R5 = 123 2 | 1: R5 = R5 & 456 (R5 = 72) 3 | 2: IF R5!=72 THEN GOTO 1 4 | 5: R5 = 0 5 | 6: R4 = R5 | 65536 6 | 7: R5 = 8858047 7 | 8: R2 = R4 & 255 8 | 9: R5 = R5 + R2 9 | 10: R5 = R5 & 16777215 10 | 11: R5 = R5 * 65899 11 | 12: R5 = R5 & 16777215 12 | 13: IF 256>R4 THEN GOTO 28 13 | 17: R2 = 0 14 | 18: R1 = R2 + 1 15 | 19: R1 = R1 * 256 16 | 20: IF R1 > R4 THEN GOTO 26 17 | 24: R2 = R2 + 1 addi 2 1 2 18 | 25: GOTO 18 19 | 26: R4 = R2 20 | 27: GOTO 8 21 | 28: IF R5!=R0 THEN GOTO GOTO 6 -------------------------------------------------------------------------------- /go/2018/21/day21.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | . "github.com/wordygravy/advent-of-code/go/2018/device" 7 | "github.com/wordygravy/advent-of-code/go/utils" 8 | "github.com/wordygravy/advent-of-code/go/utils/set" 9 | "time" 10 | ) 11 | 12 | //go:embed sample.txt 13 | var inputTest string 14 | 15 | func Part1(input string) int { 16 | var m = CreateMachine(input) 17 | 18 | //m.registers[0] = 11513432 19 | for m.Run(false) { 20 | if m.Ip() == 28 { 21 | return m.Register(5) 22 | } 23 | } 24 | 25 | return 0 26 | } 27 | 28 | func Part2(input string) int { 29 | var m = CreateMachine(input) 30 | 31 | var previous int 32 | var history = set.NewSet[int]() 33 | for m.Run(false) { 34 | if m.Ip() == 28 { 35 | if history.Contains(m.Register(5)) { 36 | return previous 37 | } 38 | previous = m.Register(5) 39 | history.Add(previous) 40 | } 41 | //fmt.Println(m.registers[0]) 42 | } 43 | 44 | return 0 45 | } 46 | 47 | func main() { 48 | fmt.Println("--2018 day 21 solution--") 49 | var inputDay = utils.Input() 50 | start := time.Now() 51 | fmt.Println("part1: ", Part1(inputDay)) 52 | fmt.Println(time.Since(start)) 53 | 54 | start = time.Now() 55 | fmt.Println("part2: ", Part2(inputDay)) 56 | fmt.Println(time.Since(start)) 57 | } 58 | -------------------------------------------------------------------------------- /go/2018/21/sample.txt: -------------------------------------------------------------------------------- 1 | #ip 0 2 | seti 5 0 1 3 | seti 6 0 2 4 | addi 0 1 0 5 | addr 1 2 3 6 | setr 1 0 0 7 | seti 8 0 4 8 | seti 9 0 5 -------------------------------------------------------------------------------- /go/2018/22/sample.txt: -------------------------------------------------------------------------------- 1 | depth: 510 2 | target: 10,10 -------------------------------------------------------------------------------- /go/2018/23/sample.txt: -------------------------------------------------------------------------------- 1 | pos=<0,0,0>, r=4 2 | pos=<1,0,0>, r=1 3 | pos=<4,0,0>, r=3 4 | pos=<0,2,0>, r=1 5 | pos=<0,5,0>, r=3 6 | pos=<0,0,3>, r=1 7 | pos=<1,1,1>, r=1 8 | pos=<1,1,2>, r=1 9 | pos=<1,3,1>, r=1 -------------------------------------------------------------------------------- /go/2018/23/sample2.txt: -------------------------------------------------------------------------------- 1 | pos=<10,12,12>, r=2 2 | pos=<12,14,12>, r=2 3 | pos=<16,12,12>, r=4 4 | pos=<14,14,14>, r=6 5 | pos=<50,50,50>, r=200 6 | pos=<10,10,10>, r=5 -------------------------------------------------------------------------------- /go/2018/24/sample.txt: -------------------------------------------------------------------------------- 1 | Immune System: 2 | 17 units each with 5390 hit points (weak to radiation, bludgeoning) with an attack that does 4507 fire damage at initiative 2 3 | 989 units each with 1274 hit points (immune to fire; weak to bludgeoning, slashing) with an attack that does 25 slashing damage at initiative 3 4 | 5 | Infection: 6 | 801 units each with 4706 hit points (weak to radiation) with an attack that does 116 bludgeoning damage at initiative 1 7 | 4485 units each with 2961 hit points (immune to radiation; weak to fire, cold) with an attack that does 12 slashing damage at initiative 4 -------------------------------------------------------------------------------- /go/2018/25/day25_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 8 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 388 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go/2018/25/sample.txt: -------------------------------------------------------------------------------- 1 | 1,-1,-1,-2 2 | -2,-2,0,1 3 | 0,2,1,3 4 | -2,3,-2,1 5 | 0,2,3,-2 6 | -1,-1,1,-2 7 | 0,-2,-1,0 8 | -2,2,3,-1 9 | 1,2,2,0 10 | -1,-2,0,-2 -------------------------------------------------------------------------------- /go/2020/01/day01.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "time" 8 | ) 9 | 10 | //go:embed sample.txt 11 | var inputTest string 12 | 13 | func Part1(input string) int { 14 | values := utils.LinesToNumbers(input) 15 | for i1, v1 := range values { 16 | for i2, v2 := range values { 17 | if i1 != i2 && v1+v2 == 2020 { 18 | return v1 * v2 19 | } 20 | } 21 | } 22 | return 0 23 | } 24 | 25 | func Part2(input string) int { 26 | values := utils.LinesToNumbers(input) 27 | for i1, v1 := range values { 28 | for i2, v2 := range values { 29 | for i3, v3 := range values { 30 | if i1 != i2 && i2 != i3 && i1 != i3 && v1+v2+v3 == 2020 { 31 | return v1 * v2 * v3 32 | } 33 | } 34 | } 35 | } 36 | return 0 37 | } 38 | 39 | func main() { 40 | fmt.Println("--2020 day 01 solution--") 41 | var inputDay = utils.Input() 42 | start := time.Now() 43 | fmt.Println("part1: ", Part1(inputDay)) 44 | fmt.Println(time.Since(start)) 45 | 46 | start = time.Now() 47 | fmt.Println("part1: ", Part2(inputDay)) 48 | fmt.Println(time.Since(start)) 49 | } 50 | -------------------------------------------------------------------------------- /go/2020/01/sample.txt: -------------------------------------------------------------------------------- 1 | 1721 2 | 979 3 | 366 4 | 299 5 | 675 6 | 1456 7 | -------------------------------------------------------------------------------- /go/2020/07/day07_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 128 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 20189 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2020/08/day08_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 1801 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 2060 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2020/09/day09_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 393911906 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 59341885 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2020/10/day10_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 1984 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 3543369523456 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2020/19/sample.txt: -------------------------------------------------------------------------------- 1 | 0: 4 1 5 2 | 1: 2 3 | 3 2 3 | 2: 4 4 | 5 5 4 | 3: 4 5 | 5 4 5 | 4: "a" 6 | 5: "b" 7 | 8 | ababbb 9 | bababa 10 | abbbab 11 | aaabbb 12 | aaaabbb -------------------------------------------------------------------------------- /go/2020/19/sample2.txt: -------------------------------------------------------------------------------- 1 | 42: 9 14 | 10 1 2 | 9: 14 27 | 1 26 3 | 10: 23 14 | 28 1 4 | 1: "a" 5 | 11: 42 31 6 | 5: 1 14 | 15 1 7 | 19: 14 1 | 14 14 8 | 12: 24 14 | 19 1 9 | 16: 15 1 | 14 14 10 | 31: 14 17 | 1 13 11 | 6: 14 14 | 1 14 12 | 2: 1 24 | 14 4 13 | 0: 8 11 14 | 13: 14 3 | 1 12 15 | 15: 1 | 14 16 | 17: 14 2 | 1 7 17 | 23: 25 1 | 22 14 18 | 28: 16 1 19 | 4: 1 1 20 | 20: 14 14 | 1 15 21 | 3: 5 14 | 16 1 22 | 27: 1 6 | 14 18 23 | 14: "b" 24 | 21: 14 1 | 1 14 25 | 25: 1 1 | 1 14 26 | 22: 14 14 27 | 8: 42 28 | 26: 14 22 | 1 20 29 | 18: 15 15 30 | 7: 14 5 | 1 21 31 | 24: 14 1 32 | 33 | abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa 34 | bbabbbbaabaabba 35 | babbbbaabbbbbabbbbbbaabaaabaaa 36 | aaabbbbbbaaaabaababaabababbabaaabbababababaaa 37 | bbbbbbbaaaabbbbaaabbabaaa 38 | bbbababbbbaaaaaaaabbababaaababaabab 39 | ababaaaaaabaaab 40 | ababaaaaabbbaba 41 | baabbaaaabbaaaababbaababb 42 | abbbbabbbbaaaababbbbbbaaaababb 43 | aaaaabbaabaaaaababaa 44 | aaaabbaaaabbaaa 45 | aaaabbaabbaaaaaaabbbabbbaaabbaabaaa 46 | babaaabbbaaabaababbaabababaaab 47 | aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba -------------------------------------------------------------------------------- /go/2020/21/sample.txt: -------------------------------------------------------------------------------- 1 | mxmxvkd kfcds sqjhc nhms (contains dairy, fish) 2 | trh fvjkl sbzzf mxmxvkd (contains dairy) 3 | sqjhc fvjkl (contains soy) 4 | sqjhc mxmxvkd sbzzf (contains fish) -------------------------------------------------------------------------------- /go/2020/22/sample.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 9 3 | 2 4 | 6 5 | 3 6 | 1 7 | 8 | Player 2: 9 | 5 10 | 8 11 | 4 12 | 7 13 | 10 14 | -------------------------------------------------------------------------------- /go/2020/24/sample.txt: -------------------------------------------------------------------------------- 1 | sesenwnenenewseeswwswswwnenewsewsw 2 | neeenesenwnwwswnenewnwwsewnenwseswesw 3 | seswneswswsenwwnwse 4 | nwnwneseeswswnenewneswwnewseswneseene 5 | swweswneswnenwsewnwneneseenw 6 | eesenwseswswnenwswnwnwsewwnwsene 7 | sewnenenenesenwsewnenwwwse 8 | wenwwweseeeweswwwnwwe 9 | wsweesenenewnwwnwsenewsenwwsesesenwne 10 | neeswseenwwswnwswswnw 11 | nenwswwsewswnenenewsenwsenwnesesenew 12 | enewnwewneswsewnwswenweswnenwsenwsw 13 | sweneswneswneneenwnewenewwneswswnese 14 | swwesenesewenwneswnwwneseswwne 15 | enesenwswwswneneswsenwnewswseenwsese 16 | wnwnesenesenenwwnenwsewesewsesesew 17 | nenewswnwewswnenesenwnesewesw 18 | eneswnwswnwsenenwnwnwwseeswneewsenese 19 | neswnwewnwnwseenwseesewsenwsweewe 20 | wseweeenwnesenwwwswnew -------------------------------------------------------------------------------- /go/2020/25/day25_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 14897079 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 9620012 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go/2020/25/sample.txt: -------------------------------------------------------------------------------- 1 | 5764801 2 | 17807724 -------------------------------------------------------------------------------- /go/2021/01/day01.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "time" 8 | ) 9 | 10 | //go:embed sample.txt 11 | var inputTest string 12 | 13 | func Part1(input string) int { 14 | values := utils.LinesToNumbers(input) 15 | cpt := 0 16 | for i := 1; i < len(values); i++ { 17 | if values[i-1] < values[i] { 18 | cpt++ 19 | } 20 | } 21 | return cpt 22 | } 23 | 24 | func Part2(input string) int { 25 | values := utils.LinesToNumbers(input) 26 | cpt := 0 27 | for i := 3; i < len(values); i++ { 28 | if values[i-3] < values[i] { 29 | cpt++ 30 | } 31 | } 32 | return cpt 33 | } 34 | 35 | func main() { 36 | fmt.Println("--2021 day 01 solution--") 37 | var inputDay = utils.Input() 38 | start := time.Now() 39 | fmt.Println("part1: ", Part1(inputDay)) 40 | fmt.Println(time.Since(start)) 41 | 42 | start = time.Now() 43 | fmt.Println("part2: ", Part2(inputDay)) 44 | fmt.Println(time.Since(start)) 45 | } 46 | -------------------------------------------------------------------------------- /go/2021/01/sample.txt: -------------------------------------------------------------------------------- 1 | 199 2 | 200 3 | 208 4 | 210 5 | 200 6 | 207 7 | 240 8 | 269 9 | 260 10 | 263 11 | -------------------------------------------------------------------------------- /go/2021/02/sample.txt: -------------------------------------------------------------------------------- 1 | forward 5 2 | down 5 3 | forward 8 4 | up 3 5 | down 8 6 | forward 2 7 | -------------------------------------------------------------------------------- /go/2021/06/day06.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "time" 8 | ) 9 | 10 | //go:embed sample.txt 11 | var inputTest string 12 | 13 | func simulate(values []int, n int) int { 14 | mult := make([]int, 9) 15 | for _, v := range values { 16 | mult[v] = mult[v] + 1 17 | } 18 | 19 | for i := 0; i < n; i++ { 20 | // rotate array left 21 | mult = append(mult[1:], mult[0]) 22 | mult[6] += mult[8] 23 | } 24 | 25 | return count(mult) 26 | } 27 | 28 | func count(values []int) int { 29 | sum := 0 30 | for _, v := range values { 31 | sum += v 32 | } 33 | return sum 34 | } 35 | 36 | func Part1(input string) int { 37 | values := utils.CommaSeparatedToNumbers(input) 38 | return simulate(values, 80) 39 | } 40 | 41 | func Part2(input string) int { 42 | values := utils.CommaSeparatedToNumbers(input) 43 | return simulate(values, 256) 44 | } 45 | 46 | func main() { 47 | fmt.Println("--2021 day 06 solution--") 48 | var inputDay = utils.Input() 49 | start := time.Now() 50 | fmt.Println("part1: ", Part1(inputDay)) 51 | fmt.Println(time.Since(start)) 52 | 53 | start = time.Now() 54 | fmt.Println("part2: ", Part2(inputDay)) 55 | fmt.Println(time.Since(start)) 56 | } 57 | -------------------------------------------------------------------------------- /go/2021/06/sample.txt: -------------------------------------------------------------------------------- 1 | 3,4,3,1,2 2 | -------------------------------------------------------------------------------- /go/2021/07/sample.txt: -------------------------------------------------------------------------------- 1 | 16,1,2,0,4,2,7,1,2,14 2 | -------------------------------------------------------------------------------- /go/2021/09/sample.txt: -------------------------------------------------------------------------------- 1 | 2199943210 2 | 3987894921 3 | 9856789892 4 | 8767896789 5 | 9899965678 -------------------------------------------------------------------------------- /go/2021/09_simplified/sample.txt: -------------------------------------------------------------------------------- 1 | 2199943210 2 | 3987894921 3 | 9856789892 4 | 8767896789 5 | 9899965678 -------------------------------------------------------------------------------- /go/2021/10/sample.txt: -------------------------------------------------------------------------------- 1 | [({(<(())[]>[[{[]{<()<>> 2 | [(()[<>])]({[<{<<[]>>( 3 | {([(<{}[<>[]}>{[]{[(<()> 4 | (((({<>}<{<{<>}{[]{[]{} 5 | [[<[([]))<([[{}[[()]]] 6 | [{[{({}]{}}([{[{{{}}([] 7 | {<[[]]>}<{[{[{[]{()[[[] 8 | [<(<(<(<{}))><([]([]() 9 | <{([([[(<>()){}]>(<<{{ 10 | <{([{{}}[<[[[<>{}]]]>[]] 11 | -------------------------------------------------------------------------------- /go/2021/11/sample.txt: -------------------------------------------------------------------------------- 1 | 5483143223 2 | 2745854711 3 | 5264556173 4 | 6141336146 5 | 6357385478 6 | 4167524645 7 | 2176841721 8 | 6882881134 9 | 4846848554 10 | 5283751526 11 | -------------------------------------------------------------------------------- /go/2021/13/day13_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 17 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 795 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | func BenchmarkPart1(b *testing.B) { 26 | var inputDay = utils.Input() 27 | for range b.N { 28 | Part1(inputDay) 29 | } 30 | } 31 | func BenchmarkPart2(b *testing.B) { 32 | var inputDay = utils.Input() 33 | for range b.N { 34 | Part2(inputDay) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /go/2021/13/sample.txt: -------------------------------------------------------------------------------- 1 | 6,10 2 | 0,14 3 | 9,10 4 | 0,3 5 | 10,4 6 | 4,11 7 | 6,0 8 | 6,12 9 | 4,1 10 | 0,13 11 | 10,12 12 | 3,4 13 | 3,0 14 | 8,4 15 | 1,10 16 | 2,14 17 | 8,10 18 | 9,0 19 | 20 | fold along y=7 21 | fold along x=5 22 | -------------------------------------------------------------------------------- /go/2021/14/sample.txt: -------------------------------------------------------------------------------- 1 | NNCB 2 | 3 | CH -> B 4 | HH -> N 5 | CB -> H 6 | NH -> C 7 | HB -> C 8 | HC -> B 9 | HN -> C 10 | NN -> C 11 | BH -> H 12 | NC -> B 13 | NB -> B 14 | BN -> B 15 | BB -> N 16 | BC -> B 17 | CC -> N 18 | CN -> C -------------------------------------------------------------------------------- /go/2021/15/sample.txt: -------------------------------------------------------------------------------- 1 | 1163751742 2 | 1381373672 3 | 2136511328 4 | 3694931569 5 | 7463417111 6 | 1319128137 7 | 1359912421 8 | 3125421639 9 | 1293138521 10 | 2311944581 11 | -------------------------------------------------------------------------------- /go/2021/17/day17_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 5460 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | func TestPart2Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part2(inputDay) 20 | expected := 3618 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | func BenchmarkPart2(b *testing.B) { 33 | var inputDay = utils.Input() 34 | for range b.N { 35 | Part2(inputDay) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /go/2021/18/sample.txt: -------------------------------------------------------------------------------- 1 | [[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]] 2 | [[[5,[2,8]],4],[5,[[9,9],0]]] 3 | [6,[[[6,2],[5,6]],[[7,6],[4,7]]]] 4 | [[[6,[0,7]],[0,9]],[4,[9,[9,0]]]] 5 | [[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]] 6 | [[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]] 7 | [[[[5,4],[7,7]],8],[[8,3],8]] 8 | [[9,3],[[9,9],[6,[4,9]]]] 9 | [[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] 10 | [[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]] 11 | -------------------------------------------------------------------------------- /go/2021/20/sample.txt: -------------------------------------------------------------------------------- 1 | ..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# 2 | 3 | #..#. 4 | #.... 5 | ##..# 6 | ..#.. 7 | ..### 8 | -------------------------------------------------------------------------------- /go/2021/21/sample.txt: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 4 2 | Player 2 starting position: 8 3 | -------------------------------------------------------------------------------- /go/2021/22/sample.txt: -------------------------------------------------------------------------------- 1 | on x=-20..26,y=-36..17,z=-47..7 2 | on x=-20..33,y=-21..23,z=-26..28 3 | on x=-22..28,y=-29..23,z=-38..16 4 | on x=-46..7,y=-6..46,z=-50..-1 5 | on x=-49..1,y=-3..46,z=-24..28 6 | on x=2..47,y=-22..22,z=-23..27 7 | on x=-27..23,y=-28..26,z=-21..29 8 | on x=-39..5,y=-6..47,z=-3..44 9 | on x=-30..21,y=-8..43,z=-13..34 10 | on x=-22..26,y=-27..20,z=-29..19 11 | off x=-48..-32,y=26..41,z=-47..-37 12 | on x=-12..35,y=6..50,z=-50..-2 13 | off x=-48..-32,y=-32..-16,z=-15..-5 14 | on x=-18..26,y=-33..15,z=-7..46 15 | off x=-40..-22,y=-38..-28,z=23..41 16 | on x=-16..35,y=-41..10,z=-47..6 17 | off x=-32..-23,y=11..30,z=-14..3 18 | on x=-49..-5,y=-3..45,z=-29..18 19 | off x=18..30,y=-20..-8,z=-3..13 20 | on x=-41..9,y=-7..43,z=-33..15 21 | on x=-54112..-39298,y=-85059..-49293,z=-27449..7877 22 | on x=967..23432,y=45373..81175,z=27513..53682 23 | -------------------------------------------------------------------------------- /go/2021/22/world.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/wordygravy/advent-of-code/go/utils/interval" 6 | ) 7 | 8 | type World map[interval.Cuboid]uint8 9 | 10 | func (w World) String() string { 11 | var s string 12 | for c, v := range w { 13 | s += fmt.Sprintf("%v: %v\n", c, v) 14 | } 15 | return s 16 | } 17 | 18 | func (w World) Add(c interval.Cuboid, info uint8) { 19 | for key, ki := range w { 20 | if !key.Disjoint(c) { 21 | if info == ki && key.Contains(c) { 22 | return // do nothing 23 | } 24 | delete(w, key) // remove key 25 | for _, e := range c.Overlap(key) { 26 | if !c.Contains(e) { 27 | w[e] = ki 28 | } 29 | } 30 | } 31 | } 32 | w[c] = info 33 | } 34 | 35 | func (w World) Count(info uint8) int { 36 | count := 0 37 | for c, v := range w { 38 | if v == info { 39 | count += c.Size() 40 | } 41 | } 42 | return count 43 | } 44 | -------------------------------------------------------------------------------- /go/2021/23/input2.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###D#D#C#B### 4 | #B#A#A#C# 5 | ######### 6 | -------------------------------------------------------------------------------- /go/2021/23/input3.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###A#D#B#D### 4 | #C#A#C#B# 5 | ######### 6 | -------------------------------------------------------------------------------- /go/2021/24/day24_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 12996997829399 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 11841231117189 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2021/24/generator.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func compile(input string, index int) (r string, i int) { 9 | cmd := strings.Split(input, " ") 10 | i = index 11 | switch cmd[0] { 12 | case "inp": 13 | r = fmt.Sprintf("%v = inp[%d]", cmd[1], index) 14 | i = index + 1 15 | case "add": 16 | r = fmt.Sprintf("%v = %v + %v", cmd[1], cmd[1], cmd[2]) 17 | case "mul": 18 | if cmd[2] == "0" { 19 | r = fmt.Sprintf("%v = %v", cmd[1], cmd[2]) 20 | } else { 21 | r = fmt.Sprintf("%v = %v * %v", cmd[1], cmd[1], cmd[2]) 22 | } 23 | case "div": 24 | if cmd[2] != "1" { 25 | r = fmt.Sprintf("%v = %v / %v", cmd[1], cmd[1], cmd[2]) 26 | } 27 | case "mod": 28 | r = fmt.Sprintf("%v = %v %% %v", cmd[1], cmd[1], cmd[2]) 29 | case "eql": 30 | r = fmt.Sprintf("if %v == %v {\n %v=1\n} else {\n %v=0\n}", cmd[1], cmd[2], cmd[1], cmd[1]) 31 | } 32 | return 33 | } 34 | 35 | func genCode(lines []string) { 36 | fmt.Println(`package main 37 | 38 | import ( 39 | "fmt" 40 | )`) 41 | fmt.Println(`func Run(inp []int) (w, x, y, z int) { 42 | w = 0 43 | x = 0 44 | y = 0 45 | z = 0 46 | `) 47 | i := 0 48 | for _, line := range lines { 49 | var s string 50 | s, i = compile(line, i) 51 | fmt.Println(s) 52 | } 53 | fmt.Println("return \n}") 54 | 55 | } 56 | -------------------------------------------------------------------------------- /go/2021/25/day25_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/wordygravy/advent-of-code/go/utils" 5 | "testing" 6 | ) 7 | 8 | func TestPart1(t *testing.T) { 9 | result := Part1(inputTest) 10 | expected := 58 11 | if result != expected { 12 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 13 | } 14 | } 15 | 16 | func TestPart1Input(t *testing.T) { 17 | var inputDay = utils.Input() 18 | result := Part1(inputDay) 19 | expected := 426 20 | if result != expected { 21 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 22 | } 23 | } 24 | 25 | func BenchmarkPart1(b *testing.B) { 26 | var inputDay = utils.Input() 27 | for range b.N { 28 | Part1(inputDay) 29 | } 30 | } 31 | func BenchmarkPart2(b *testing.B) { 32 | var inputDay = utils.Input() 33 | for range b.N { 34 | Part2(inputDay) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /go/2021/25/sample.txt: -------------------------------------------------------------------------------- 1 | v...>>.vv> 2 | .vv>>.vv.. 3 | >>.>v>...v 4 | >>v>>.>.v. 5 | v>v.vv.v.. 6 | >.>>..v... 7 | .vv..>.>v. 8 | v.v..>>v.v 9 | ....v..v.> -------------------------------------------------------------------------------- /go/2022/01/sample.txt: -------------------------------------------------------------------------------- 1 | 1000 2 | 2000 3 | 3000 4 | 5 | 4000 6 | 7 | 5000 8 | 6000 9 | 10 | 7000 11 | 8000 12 | 9000 13 | 14 | 10000 -------------------------------------------------------------------------------- /go/2022/02/sample.txt: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z -------------------------------------------------------------------------------- /go/2022/03/sample.txt: -------------------------------------------------------------------------------- 1 | vJrwpWtwJgWrhcsFMMfFFhFp 2 | jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL 3 | PmmdzqPrVvPwwTWBwg 4 | wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn 5 | ttgJtRGJQctTZtZT 6 | CrZsJsPPZsGzwwsLwLmpwMDw -------------------------------------------------------------------------------- /go/2022/04/sample.txt: -------------------------------------------------------------------------------- 1 | 2-4,6-8 2 | 2-3,4-5 3 | 5-7,7-9 4 | 2-8,3-7 5 | 6-6,4-6 6 | 2-6,4-8 -------------------------------------------------------------------------------- /go/2022/05/sample.txt: -------------------------------------------------------------------------------- 1 | [D] 2 | [N] [C] 3 | [Z] [M] [P] 4 | 1 2 3 5 | 6 | move 1 from 2 to 1 7 | move 3 from 1 to 3 8 | move 2 from 2 to 1 9 | move 1 from 1 to 2 -------------------------------------------------------------------------------- /go/2022/06/day06.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "time" 8 | ) 9 | 10 | //go:embed sample.txt 11 | var inputTest string 12 | 13 | func allDifferent(s string) bool { 14 | var tab [26]bool 15 | for i := 0; i < len(s); i++ { 16 | if tab[s[i]-'a'] { 17 | return false 18 | } 19 | tab[s[i]-'a'] = true 20 | } 21 | return true 22 | } 23 | 24 | func solve(input string, n int) int { 25 | for i := 0; i < len(input)-n; i++ { 26 | s := input[i : i+n] 27 | if allDifferent(s) { 28 | return i + n 29 | } 30 | } 31 | return -1 32 | } 33 | 34 | func Part1(input string) int { 35 | return solve(input, 4) 36 | } 37 | 38 | func Part2(input string) int { 39 | return solve(input, 14) 40 | } 41 | 42 | func main() { 43 | fmt.Println("--2022 day 06 solution--") 44 | var inputDay = utils.Input() 45 | start := time.Now() 46 | fmt.Println("part1: ", Part1(inputDay)) 47 | fmt.Println(time.Since(start)) 48 | 49 | start = time.Now() 50 | fmt.Println("part2: ", Part2(inputDay)) 51 | fmt.Println(time.Since(start)) 52 | } 53 | -------------------------------------------------------------------------------- /go/2022/06/sample.txt: -------------------------------------------------------------------------------- 1 | bvwbjplbgvbhsrlpgdmjqwftvncz -------------------------------------------------------------------------------- /go/2022/07/sample.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k -------------------------------------------------------------------------------- /go/2022/08/sample.txt: -------------------------------------------------------------------------------- 1 | 30373 2 | 25512 3 | 65332 4 | 33549 5 | 35390 -------------------------------------------------------------------------------- /go/2022/09/sample.txt: -------------------------------------------------------------------------------- 1 | R 4 2 | U 4 3 | L 3 4 | D 1 5 | R 4 6 | D 1 7 | L 5 8 | R 2 -------------------------------------------------------------------------------- /go/2022/09/sample2.txt: -------------------------------------------------------------------------------- 1 | R 5 2 | U 8 3 | L 8 4 | D 3 5 | R 17 6 | D 10 7 | L 25 8 | U 20 -------------------------------------------------------------------------------- /go/2022/11/day11_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 112815 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | //func TestPart2(t *testing.T) { 19 | // result := Part2(inputTest) 20 | // expected := 2713310158 21 | // if result != expected { 22 | // t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | // } 24 | //} 25 | 26 | func TestPart2Input(t *testing.T) { 27 | var inputDay = utils.Input() 28 | result := Part2(inputDay) 29 | expected := 25738411485 30 | if result != expected { 31 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 32 | } 33 | } 34 | 35 | func BenchmarkPart1(b *testing.B) { 36 | var inputDay = utils.Input() 37 | for range b.N { 38 | Part1(inputDay) 39 | } 40 | } 41 | func BenchmarkPart2(b *testing.B) { 42 | var inputDay = utils.Input() 43 | for range b.N { 44 | Part2(inputDay) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /go/2022/11/sample.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 -------------------------------------------------------------------------------- /go/2022/12/sample.txt: -------------------------------------------------------------------------------- 1 | Sabqponm 2 | abcryxxl 3 | accszExk 4 | acctuvwj 5 | abdefghi -------------------------------------------------------------------------------- /go/2022/13/sample.txt: -------------------------------------------------------------------------------- 1 | [1,1,3,1,1] 2 | [1,1,5,1,1] 3 | 4 | [[1],[2,3,4]] 5 | [[1],4] 6 | 7 | [9] 8 | [[8,7,6]] 9 | 10 | [[4,4],4,4] 11 | [[4,4],4,4,4] 12 | 13 | [7,7,7,7] 14 | [7,7,7] 15 | 16 | [] 17 | [3] 18 | 19 | [[[]]] 20 | [[]] 21 | 22 | [1,[2,[3,[4,[5,6,7]]]],8,9] 23 | [1,[2,[3,[4,[5,6,0]]]],8,9] -------------------------------------------------------------------------------- /go/2022/14/sample.txt: -------------------------------------------------------------------------------- 1 | 498,4 -> 498,6 -> 496,6 2 | 503,4 -> 502,4 -> 502,9 -> 494,9 -------------------------------------------------------------------------------- /go/2022/15/day15_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 5142231 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 10884459367718 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2022/15/sample.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 14 | Sensor at x=20, y=1: closest beacon is at x=15, y=3 -------------------------------------------------------------------------------- /go/2022/16/sample.txt: -------------------------------------------------------------------------------- 1 | Valve AA has flow rate=0; tunnels lead to valves DD, II, BB 2 | Valve BB has flow rate=13; tunnels lead to valves CC, AA 3 | Valve CC has flow rate=2; tunnels lead to valves DD, BB 4 | Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE 5 | Valve EE has flow rate=3; tunnels lead to valves FF, DD 6 | Valve HH has flow rate=22; tunnel leads to valve GG 7 | Valve JJ has flow rate=21; tunnel leads to valve II 8 | Valve FF has flow rate=0; tunnels lead to valves EE, GG 9 | Valve GG has flow rate=0; tunnels lead to valves FF, HH 10 | Valve II has flow rate=0; tunnels lead to valves AA, JJ -------------------------------------------------------------------------------- /go/2022/17/sample.txt: -------------------------------------------------------------------------------- 1 | >>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> -------------------------------------------------------------------------------- /go/2022/18/sample.txt: -------------------------------------------------------------------------------- 1 | 2,1,5 2 | 3,2,5 3 | 2,2,6 4 | 2,3,5 5 | 1,2,5 6 | 2,2,2 7 | 1,2,2 8 | 3,2,2 9 | 2,1,2 10 | 2,3,2 11 | 2,2,1 12 | 2,2,3 13 | 2,2,4 -------------------------------------------------------------------------------- /go/2022/19/sample.txt: -------------------------------------------------------------------------------- 1 | Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian. 2 | Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian. -------------------------------------------------------------------------------- /go/2022/20/sample.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -3 4 | 3 5 | -2 6 | 0 7 | 4 -------------------------------------------------------------------------------- /go/2022/21/sample.txt: -------------------------------------------------------------------------------- 1 | root: pppw + sjmn 2 | dbpl: 5 3 | cczh: sllz + lgvd 4 | zczc: 2 5 | ptdq: humn - dvpt 6 | dvpt: 3 7 | lfqf: 4 8 | humn: 5 9 | ljgn: 2 10 | sjmn: drzm * dbpl 11 | sllz: 4 12 | pppw: cczh / lfqf 13 | lgvd: ljgn * ptdq 14 | drzm: hmdt - zczc 15 | hmdt: 32 -------------------------------------------------------------------------------- /go/2022/22/day22_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 131052 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 4578 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2022/22/sample.txt: -------------------------------------------------------------------------------- 1 | ...# 2 | .#.. 3 | #... 4 | .... 5 | ...#.......# 6 | ........#... 7 | ..#....#.... 8 | ..........#. 9 | ...#.... 10 | .....#.. 11 | .#...... 12 | ......#. 13 | 14 | 10R5L5R10L4R5L5 -------------------------------------------------------------------------------- /go/2022/23/sample.txt: -------------------------------------------------------------------------------- 1 | .............. 2 | .............. 3 | .......#...... 4 | .....###.#.... 5 | ...#...#.#.... 6 | ....#...##.... 7 | ...#.###...... 8 | ...##.#.##.... 9 | ....#..#...... 10 | .............. 11 | .............. 12 | .............. -------------------------------------------------------------------------------- /go/2022/24/sample.txt: -------------------------------------------------------------------------------- 1 | #.###### 2 | #>>.<^<# 3 | #.<..<<# 4 | #>v.><># 5 | #<^v^^># 6 | ######.# -------------------------------------------------------------------------------- /go/2022/25/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | //go:embed sample.txt 12 | var inputTest string 13 | 14 | func fromSnafu(s string) int { 15 | digit := map[byte]int{'0': 0, '1': 1, '2': 2, '-': -1, '=': -2} 16 | res := 0 17 | for i := 0; i < len(s); i++ { 18 | res = 5*res + digit[s[i]] 19 | } 20 | return res 21 | } 22 | 23 | func toSnafu(i int) string { 24 | digit := map[int]byte{0: '0', 1: '1', 2: '2', -1: '-', -2: '='} 25 | res := "" 26 | for i > 0 { 27 | if i%5 > 2 { 28 | res = string(digit[i%5-5]) + res 29 | i = i/5 + 1 30 | } else { 31 | res = string(digit[i%5]) + res 32 | i = i / 5 33 | } 34 | } 35 | return res 36 | } 37 | 38 | func Part1(input string) string { 39 | input = strings.TrimSuffix(input, "\n") 40 | lines := strings.Split(input, "\n") 41 | res := 0 42 | for _, line := range lines { 43 | res += fromSnafu(line) 44 | } 45 | 46 | return toSnafu(res) 47 | } 48 | 49 | func main() { 50 | fmt.Println("--2022 day 25 solution--") 51 | var inputDay = utils.Input() 52 | start := time.Now() 53 | fmt.Println("part1: ", Part1(inputDay)) 54 | fmt.Println(time.Since(start)) 55 | } 56 | -------------------------------------------------------------------------------- /go/2022/25/day25_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := "2=-1=0" 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := "20-==01-2-=1-2---1-0" 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go/2022/25/sample.txt: -------------------------------------------------------------------------------- 1 | 1=-0-2 2 | 12111 3 | 2=0= 4 | 21 5 | 2=01 6 | 111 7 | 20012 8 | 112 9 | 1=-1= 10 | 1-12 11 | 12 12 | 1= 13 | 122 -------------------------------------------------------------------------------- /go/2023/01/sample.txt: -------------------------------------------------------------------------------- 1 | 1abc2 2 | pqr3stu8vwx 3 | a1b2c3d4e5f 4 | treb7uchet -------------------------------------------------------------------------------- /go/2023/01/sample2.txt: -------------------------------------------------------------------------------- 1 | two1nine 2 | eightwothree 3 | abcone2threexyz 4 | xtwone3four 5 | 4nineeightseven2 6 | zoneight234 7 | 7pqrstsixteen -------------------------------------------------------------------------------- /go/2023/02/sample.txt: -------------------------------------------------------------------------------- 1 | Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green 2 | Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue 3 | Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red 4 | Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red 5 | Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green -------------------------------------------------------------------------------- /go/2023/03/sample.txt: -------------------------------------------------------------------------------- 1 | 467..114.. 2 | ...*...... 3 | ..35..633. 4 | ......#... 5 | 617*...... 6 | .....+.58. 7 | ..592..... 8 | ......755. 9 | ...$.*.... 10 | .664.598.. -------------------------------------------------------------------------------- /go/2023/04/sample.txt: -------------------------------------------------------------------------------- 1 | Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 2 | Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 3 | Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 4 | Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 5 | Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 6 | Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 -------------------------------------------------------------------------------- /go/2023/05/sample.txt: -------------------------------------------------------------------------------- 1 | seeds: 79 14 55 13 2 | 3 | seed-to-soil map: 4 | 50 98 2 5 | 52 50 48 6 | 7 | soil-to-fertilizer map: 8 | 0 15 37 9 | 37 52 2 10 | 39 0 15 11 | 12 | fertilizer-to-water map: 13 | 49 53 8 14 | 0 11 42 15 | 42 0 7 16 | 57 7 4 17 | 18 | water-to-light map: 19 | 88 18 7 20 | 18 25 70 21 | 22 | light-to-temperature map: 23 | 45 77 23 24 | 81 45 19 25 | 68 64 13 26 | 27 | temperature-to-humidity map: 28 | 0 69 1 29 | 1 0 69 30 | 31 | humidity-to-location map: 32 | 60 56 37 33 | 56 93 4 -------------------------------------------------------------------------------- /go/2023/06/sample.txt: -------------------------------------------------------------------------------- 1 | Time: 7 15 30 2 | Distance: 9 40 200 -------------------------------------------------------------------------------- /go/2023/07/sample.txt: -------------------------------------------------------------------------------- 1 | 32T3K 765 2 | T55J5 684 3 | KK677 28 4 | KTJJT 220 5 | QQQJA 483 -------------------------------------------------------------------------------- /go/2023/08/sample.txt: -------------------------------------------------------------------------------- 1 | LLR 2 | 3 | AAA = (BBB, BBB) 4 | BBB = (AAA, ZZZ) 5 | ZZZ = (ZZZ, ZZZ) -------------------------------------------------------------------------------- /go/2023/08/sample2.txt: -------------------------------------------------------------------------------- 1 | LR 2 | 3 | 11A = (11B, XXX) 4 | 11B = (XXX, 11Z) 5 | 11Z = (11B, XXX) 6 | 22A = (22B, XXX) 7 | 22B = (22C, 22C) 8 | 22C = (22Z, 22Z) 9 | 22Z = (22B, 22B) 10 | XXX = (XXX, XXX) -------------------------------------------------------------------------------- /go/2023/09/sample.txt: -------------------------------------------------------------------------------- 1 | 0 3 6 9 12 15 2 | 1 3 6 10 15 21 3 | 10 13 16 21 30 45 -------------------------------------------------------------------------------- /go/2023/10/sample.txt: -------------------------------------------------------------------------------- 1 | ..F7. 2 | .FJ|. 3 | SJ.L7 4 | |F--J 5 | LJ... -------------------------------------------------------------------------------- /go/2023/10/sample2_1.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .S-------7. 3 | .|F-----7|. 4 | .||.....||. 5 | .||.....||. 6 | .|L-7.F-J|. 7 | .|..|.|..|. 8 | .L--J.L--J. 9 | ........... -------------------------------------------------------------------------------- /go/2023/10/sample2_2.txt: -------------------------------------------------------------------------------- 1 | .F----7F7F7F7F-7.... 2 | .|F--7||||||||FJ.... 3 | .||.FJ||||||||L7.... 4 | FJL7L7LJLJ||LJ.L-7.. 5 | L--J.L7...LJS7F-7L7. 6 | ....F-J..F7FJ|L7L7L7 7 | ....L7.F7||L7|.L7L7| 8 | .....|FJLJ|FJ|F7|.LJ 9 | ....FJL-7.||.||||... 10 | ....L---J.LJ.LJLJ... -------------------------------------------------------------------------------- /go/2023/10/sample2_3.txt: -------------------------------------------------------------------------------- 1 | FF7FSF7F7F7F7F7F---7 2 | L|LJ||||||||||||F--J 3 | FL-7LJLJ||||||LJL-77 4 | F--JF--7||LJLJ7F7FJ- 5 | L---JF-JLJ.||-FJLJJ7 6 | |F|F-JF---7F7-L7L|7| 7 | |FFJF7L7F-JF7|JL---7 8 | 7-L-JL7||F7|L7F-7F7| 9 | L.L7LFJ|||||FJL7||LJ 10 | L7JLJL-JLJLJL--JLJ.L -------------------------------------------------------------------------------- /go/2023/11/day11_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 374 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 9799681 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func TestPart2Input(t *testing.T) { 27 | var inputDay = utils.Input() 28 | result := Part2(inputDay) 29 | expected := 513171773355 30 | if result != expected { 31 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 32 | } 33 | } 34 | 35 | func BenchmarkPart1(b *testing.B) { 36 | var inputDay = utils.Input() 37 | for range b.N { 38 | Part1(inputDay) 39 | } 40 | } 41 | func BenchmarkPart2(b *testing.B) { 42 | var inputDay = utils.Input() 43 | for range b.N { 44 | Part2(inputDay) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /go/2023/11/sample.txt: -------------------------------------------------------------------------------- 1 | ...#...... 2 | .......#.. 3 | #......... 4 | .......... 5 | ......#... 6 | .#........ 7 | .........# 8 | .......... 9 | .......#.. 10 | #...#..... -------------------------------------------------------------------------------- /go/2023/12/sample.txt: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 -------------------------------------------------------------------------------- /go/2023/12Worker/sample.txt: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 -------------------------------------------------------------------------------- /go/2023/13/sample.txt: -------------------------------------------------------------------------------- 1 | #.##..##. 2 | ..#.##.#. 3 | ##......# 4 | ##......# 5 | ..#.##.#. 6 | ..##..##. 7 | #.#.##.#. 8 | 9 | #...##..# 10 | #....#..# 11 | ..##..### 12 | #####.##. 13 | #####.##. 14 | ..##..### 15 | #....#..# -------------------------------------------------------------------------------- /go/2023/14/sample.txt: -------------------------------------------------------------------------------- 1 | O....#.... 2 | O.OO#....# 3 | .....##... 4 | OO.#O....O 5 | .O.....O#. 6 | O.#..O.#.# 7 | ..O..#O..O 8 | .......O.. 9 | #....###.. 10 | #OO..#.... -------------------------------------------------------------------------------- /go/2023/15/sample.txt: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 -------------------------------------------------------------------------------- /go/2023/16/sample.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /go/2023/16Recursive/sample.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /go/2023/17/sample.txt: -------------------------------------------------------------------------------- 1 | 2413432311323 2 | 3215453535623 3 | 3255245654254 4 | 3446585845452 5 | 4546657867536 6 | 1438598798454 7 | 4457876987766 8 | 3637877979653 9 | 4654967986887 10 | 4564679986453 11 | 1224686865563 12 | 2546548887735 13 | 4322674655533 -------------------------------------------------------------------------------- /go/2023/18/sample.txt: -------------------------------------------------------------------------------- 1 | R 6 (#70c710) 2 | D 5 (#0dc571) 3 | L 2 (#5713f0) 4 | D 2 (#d2c081) 5 | R 2 (#59c680) 6 | D 2 (#411b91) 7 | L 5 (#8ceee2) 8 | U 2 (#caa173) 9 | L 1 (#1b58a2) 10 | U 2 (#caa171) 11 | R 2 (#7807d2) 12 | U 3 (#a77fa3) 13 | L 2 (#015232) 14 | U 2 (#7a21e3) -------------------------------------------------------------------------------- /go/2023/19/sample.txt: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} -------------------------------------------------------------------------------- /go/2023/19Tree/sample.txt: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} -------------------------------------------------------------------------------- /go/2023/20/day20_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | //go:embed sample2.txt 10 | var inputTest2 string 11 | 12 | func TestPart1(t *testing.T) { 13 | result := Part1(inputTest) 14 | expected := 32000000 15 | if result != expected { 16 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 17 | } 18 | } 19 | 20 | func TestPart1_2(t *testing.T) { 21 | result := Part1(inputTest2) 22 | expected := 11687500 23 | if result != expected { 24 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 25 | } 26 | } 27 | 28 | func TestPart1Input(t *testing.T) { 29 | var inputDay = utils.Input() 30 | result := Part1(inputDay) 31 | expected := 912199500 32 | if result != expected { 33 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 34 | } 35 | } 36 | 37 | func BenchmarkPart1(b *testing.B) { 38 | var inputDay = utils.Input() 39 | for range b.N { 40 | Part1(inputDay) 41 | } 42 | } 43 | func BenchmarkPart2(b *testing.B) { 44 | var inputDay = utils.Input() 45 | for range b.N { 46 | Part2(inputDay) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /go/2023/20/sample.txt: -------------------------------------------------------------------------------- 1 | broadcaster -> a, b, c 2 | %a -> b 3 | %b -> c 4 | %c -> inv 5 | &inv -> a -------------------------------------------------------------------------------- /go/2023/20/sample2.txt: -------------------------------------------------------------------------------- 1 | broadcaster -> a 2 | %a -> inv, con 3 | &inv -> b 4 | %b -> con 5 | &con -> output -------------------------------------------------------------------------------- /go/2023/21/day21_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 3605 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 596734624269210 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2023/21/sample.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .....###.#. 3 | .###.##..#. 4 | ..#.#...#.. 5 | ....#.#.... 6 | .##..S####. 7 | .##..#...#. 8 | .......##.. 9 | .##.#.####. 10 | .##..##.##. 11 | ........... -------------------------------------------------------------------------------- /go/2023/22/sample.txt: -------------------------------------------------------------------------------- 1 | 1,0,1~1,2,1 2 | 0,0,2~2,0,2 3 | 0,2,3~2,2,3 4 | 0,0,4~0,2,4 5 | 2,0,5~2,2,5 6 | 0,1,6~2,1,6 7 | 1,1,8~1,1,9 -------------------------------------------------------------------------------- /go/2023/23/sample.txt: -------------------------------------------------------------------------------- 1 | #.##################### 2 | #.......#########...### 3 | #######.#########.#.### 4 | ###.....#.>.>.###.#.### 5 | ###v#####.#v#.###.#.### 6 | ###.>...#.#.#.....#...# 7 | ###v###.#.#.#########.# 8 | ###...#.#.#.......#...# 9 | #####.#.#.#######.#.### 10 | #.....#.#.#.......#...# 11 | #.#####.#.#.#########v# 12 | #.#...#...#...###...>.# 13 | #.#.#v#######v###.###v# 14 | #...#.>.#...>.>.#.###.# 15 | #####v#.#.###v#.#.###.# 16 | #.....#...#...#.#.#...# 17 | #.#########.###.#.#.### 18 | #...###...#...#...#.### 19 | ###.###.#.###v#####v### 20 | #...#...#.#.>.>.#.>.### 21 | #.###.###.#.###.#.#v### 22 | #.....###...###...#...# 23 | #####################.# -------------------------------------------------------------------------------- /go/2023/24/day24_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 20434 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 1025127405449117 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2023/24/sample.txt: -------------------------------------------------------------------------------- 1 | 19, 13, 30 @ -2, 1, -2 2 | 18, 19, 22 @ -1, -1, -2 3 | 20, 25, 34 @ -2, -2, -4 4 | 12, 31, 28 @ -1, -2, -1 5 | 20, 19, 15 @ 1, -5, -3 -------------------------------------------------------------------------------- /go/2023/25/graph1.dot: -------------------------------------------------------------------------------- 1 | graph { 2 | jqt -- { rhn xhk nvd } 3 | rsh -- { frs pzl lsr } 4 | xhk -- { hfx } 5 | cmg -- { qnr nvd lhk bvb } 6 | rhn -- { xhk bvb hfx } 7 | bvb -- { xhk hfx } 8 | pzl -- { lsr hfx nvd } 9 | qnr -- { nvd } 10 | ntq -- { jqt hfx bvb xhk } 11 | nvd -- { lhk } 12 | lsr -- { lhk } 13 | rzs -- { qnr cmg lsr rsh } 14 | frs -- { qnr lhk lsr } 15 | } 16 | -------------------------------------------------------------------------------- /go/2023/25/sample.txt: -------------------------------------------------------------------------------- 1 | 19, 13, 30 @ -2, 1, -2 2 | 18, 19, 22 @ -1, -1, -2 3 | 20, 25, 34 @ -2, -2, -4 4 | 12, 31, 28 @ -1, -2, -1 5 | 20, 19, 15 @ 1, -5, -3 -------------------------------------------------------------------------------- /go/2024/01/sample.txt: -------------------------------------------------------------------------------- 1 | 3 4 2 | 4 3 3 | 2 5 4 | 1 3 5 | 3 9 6 | 3 3 -------------------------------------------------------------------------------- /go/2024/02/sample.txt: -------------------------------------------------------------------------------- 1 | 7 6 4 2 1 2 | 1 2 7 8 9 3 | 9 7 6 2 1 4 | 1 3 2 4 5 5 | 8 6 4 4 1 6 | 1 3 6 7 9 -------------------------------------------------------------------------------- /go/2024/03/day03.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "github.com/wordygravy/advent-of-code/go/utils" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | func parse(input string, part2 bool) int { 12 | var res int 13 | var x, y int 14 | var enable = true 15 | for i := 0; i < len(input); i++ { 16 | if part2 && strings.HasPrefix(input[i:], "do()") { 17 | enable = true 18 | } else if part2 && strings.HasPrefix(input[i:], "don't()") { 19 | enable = false 20 | } else if strings.HasPrefix(input[i:], "mul(") { 21 | if _, err := fmt.Sscanf(input[i+4:], "%d,%d)", &x, &y); err == nil && enable { 22 | res += x * y 23 | } 24 | } 25 | } 26 | return res 27 | } 28 | 29 | func Part1(input string) int { 30 | return parse(input, false) 31 | } 32 | 33 | func Part2(input string) int { 34 | return parse(input, true) 35 | } 36 | 37 | func main() { 38 | fmt.Println("--2024 day 03 solution--") 39 | var inputDay = utils.Input() 40 | //var inputDay = inputTest 41 | start := time.Now() 42 | fmt.Println("part1: ", Part1(inputDay)) 43 | fmt.Println(time.Since(start)) 44 | 45 | start = time.Now() 46 | fmt.Println("part2: ", Part2(inputDay)) 47 | fmt.Println(time.Since(start)) 48 | } 49 | -------------------------------------------------------------------------------- /go/2024/04/day04_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1Input(t *testing.T) { 10 | var inputDay = utils.Input() 11 | result := Part1(inputDay) 12 | expected := 2685 13 | if result != expected { 14 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 15 | } 16 | } 17 | 18 | func TestPart2Input(t *testing.T) { 19 | var inputDay = utils.Input() 20 | result := Part2(inputDay) 21 | expected := 2048 22 | if result != expected { 23 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 24 | } 25 | } 26 | 27 | func BenchmarkPart1(b *testing.B) { 28 | var inputDay = utils.Input() 29 | for range b.N { 30 | Part1(inputDay) 31 | } 32 | } 33 | func BenchmarkPart2(b *testing.B) { 34 | var inputDay = utils.Input() 35 | for range b.N { 36 | Part2(inputDay) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go/2024/04/sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordygravy/advent-of-code/da04db24909ed2ec5efa9334d1b9c2710746aef9/go/2024/04/sample.txt -------------------------------------------------------------------------------- /go/2024/05/sample.txt: -------------------------------------------------------------------------------- 1 | 47|53 2 | 97|13 3 | 97|61 4 | 97|47 5 | 75|29 6 | 61|13 7 | 75|53 8 | 29|13 9 | 97|29 10 | 53|29 11 | 61|53 12 | 97|53 13 | 61|29 14 | 47|13 15 | 75|47 16 | 97|75 17 | 47|61 18 | 75|61 19 | 47|29 20 | 75|13 21 | 53|13 22 | 23 | 75,47,61,53,29 24 | 97,61,53,29,13 25 | 75,29,13 26 | 75,97,47,61,53 27 | 61,13,29 28 | 97,13,75,29,47 -------------------------------------------------------------------------------- /go/2024/05Simplified/sample.txt: -------------------------------------------------------------------------------- 1 | 47|53 2 | 97|13 3 | 97|61 4 | 97|47 5 | 75|29 6 | 61|13 7 | 75|53 8 | 29|13 9 | 97|29 10 | 53|29 11 | 61|53 12 | 97|53 13 | 61|29 14 | 47|13 15 | 75|47 16 | 97|75 17 | 47|61 18 | 75|61 19 | 47|29 20 | 75|13 21 | 53|13 22 | 23 | 75,47,61,53,29 24 | 97,61,53,29,13 25 | 75,29,13 26 | 75,97,47,61,53 27 | 61,13,29 28 | 97,13,75,29,47 -------------------------------------------------------------------------------- /go/2024/06/sample.txt: -------------------------------------------------------------------------------- 1 | ....#..... 2 | .........# 3 | .......... 4 | ..#....... 5 | .......#.. 6 | .......... 7 | .#..^..... 8 | ........#. 9 | #......... 10 | ......#... -------------------------------------------------------------------------------- /go/2024/06Matrix/sample.txt: -------------------------------------------------------------------------------- 1 | ....#..... 2 | .........# 3 | .......... 4 | ..#....... 5 | .......#.. 6 | .......... 7 | .#..^..... 8 | ........#. 9 | #......... 10 | ......#... -------------------------------------------------------------------------------- /go/2024/07/sample.txt: -------------------------------------------------------------------------------- 1 | 190: 10 19 2 | 3267: 81 40 27 3 | 83: 17 5 4 | 156: 15 6 5 | 7290: 6 8 6 15 6 | 161011: 16 10 13 7 | 192: 17 8 14 8 | 21037: 9 7 18 13 9 | 292: 11 6 16 20 -------------------------------------------------------------------------------- /go/2024/08/sample.txt: -------------------------------------------------------------------------------- 1 | ............ 2 | ........0... 3 | .....0...... 4 | .......0.... 5 | ....0....... 6 | ......A..... 7 | ............ 8 | ............ 9 | ........A... 10 | .........A.. 11 | ............ 12 | ............ -------------------------------------------------------------------------------- /go/2024/09/sample.txt: -------------------------------------------------------------------------------- 1 | 2333133121414131402 -------------------------------------------------------------------------------- /go/2024/10/sample.txt: -------------------------------------------------------------------------------- 1 | 89010123 2 | 78121874 3 | 87430965 4 | 96549874 5 | 45678903 6 | 32019012 7 | 01329801 8 | 10456732 -------------------------------------------------------------------------------- /go/2024/11/sample.txt: -------------------------------------------------------------------------------- 1 | 125 17 -------------------------------------------------------------------------------- /go/2024/12/sample.txt: -------------------------------------------------------------------------------- 1 | AAAAAA 2 | AAABBA 3 | AAABBA 4 | ABBAAA 5 | ABBAAA 6 | AAAAAA -------------------------------------------------------------------------------- /go/2024/13/sample.txt: -------------------------------------------------------------------------------- 1 | Button A: X+94, Y+34 2 | Button B: X+22, Y+67 3 | Prize: X=8400, Y=5400 4 | 5 | Button A: X+26, Y+66 6 | Button B: X+67, Y+21 7 | Prize: X=12748, Y=12176 8 | 9 | Button A: X+17, Y+86 10 | Button B: X+84, Y+37 11 | Prize: X=7870, Y=6450 12 | 13 | Button A: X+69, Y+23 14 | Button B: X+27, Y+71 15 | Prize: X=18641, Y=10279 -------------------------------------------------------------------------------- /go/2024/14/sample.txt: -------------------------------------------------------------------------------- 1 | p=0,4 v=3,-3 2 | p=6,3 v=-1,-3 3 | p=10,3 v=-1,2 4 | p=2,0 v=2,-1 5 | p=0,0 v=1,3 6 | p=3,0 v=-2,-2 7 | p=7,6 v=-1,-3 8 | p=3,0 v=-1,-2 9 | p=9,3 v=2,3 10 | p=7,3 v=-1,2 11 | p=2,4 v=2,-3 12 | p=9,5 v=-3,-3 -------------------------------------------------------------------------------- /go/2024/15/sample.txt: -------------------------------------------------------------------------------- 1 | ########## 2 | #..O..O.O# 3 | #......O.# 4 | #.OO..O.O# 5 | #..O@..O.# 6 | #O#..O...# 7 | #O..O..O.# 8 | #.OO.O.OO# 9 | #....O...# 10 | ########## 11 | 12 | ^v>^vv^v>v<>v^v<<><>>v^v^>^<<<><^ 13 | vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<^<^^>>>^<>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^v^^<^^vv< 15 | <>^^^^>>>v^<>vvv^>^^^vv^^>v<^^^^v<>^>vvvv><>>v^<<^^^^^ 16 | ^><^><>>><>^^<<^^v>>><^^>v>>>^v><>^v><<<>vvvv>^<><<>^>< 17 | ^>><>^v<><^vvv<^^<><^v<<<><<<^^<^>>^<<<^>>^v^>>^v>vv>^<<^v<>><<><<>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^ 19 | <><^^>^^^<>^vv<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<> 20 | ^^>vv<^v^v^<>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<>< 21 | v^^>>><<^^<>>^v^v^<<>^<^v^v><^<<<><<^vv>>v>v^<<^ -------------------------------------------------------------------------------- /go/2024/16/sample.txt: -------------------------------------------------------------------------------- 1 | ################# 2 | #...#...#...#..E# 3 | #.#.#.#.#.#.#.#.# 4 | #.#.#.#...#...#.# 5 | #.#.#.#.###.#.#.# 6 | #...#.#.#.....#.# 7 | #.#.#.#.#.#####.# 8 | #.#...#.#.#.....# 9 | #.#.#####.#.###.# 10 | #.#.#.......#...# 11 | #.#.###.#####.### 12 | #.#.#...#.....#.# 13 | #.#.#.#####.###.# 14 | #.#.#.........#.# 15 | #.#.#.#########.# 16 | #S#.............# 17 | ################# -------------------------------------------------------------------------------- /go/2024/17/sample.txt: -------------------------------------------------------------------------------- 1 | Register A: 729 2 | Register B: 0 3 | Register C: 0 4 | 5 | Program: 0,1,5,4,3,0 -------------------------------------------------------------------------------- /go/2024/17/sample2.txt: -------------------------------------------------------------------------------- 1 | Register A: 2024 2 | Register B: 0 3 | Register C: 0 4 | 5 | Program: 0,3,5,4,3,0 -------------------------------------------------------------------------------- /go/2024/18/sample.txt: -------------------------------------------------------------------------------- 1 | 5,4 2 | 4,2 3 | 4,5 4 | 3,0 5 | 2,1 6 | 6,3 7 | 2,4 8 | 1,5 9 | 0,6 10 | 3,3 11 | 2,6 12 | 5,1 13 | 1,2 14 | 5,5 15 | 2,5 16 | 6,5 17 | 1,4 18 | 0,4 19 | 6,4 20 | 1,1 21 | 6,1 22 | 1,0 23 | 0,5 24 | 1,6 25 | 2,0 -------------------------------------------------------------------------------- /go/2024/19/sample.txt: -------------------------------------------------------------------------------- 1 | r, wr, b, g, bwu, rb, gb, br 2 | 3 | brwrr 4 | bggr 5 | gbbr 6 | rrbgbr 7 | ubwu 8 | bwurrg 9 | brgr 10 | bbrgwb -------------------------------------------------------------------------------- /go/2024/20/sample.txt: -------------------------------------------------------------------------------- 1 | ############### 2 | #...#...#.....# 3 | #.#.#.#.#.###.# 4 | #S#...#.#.#...# 5 | #######.#.#.### 6 | #######.#.#...# 7 | #######.#.###.# 8 | ###..E#...#...# 9 | ###.#######.### 10 | #...###...#...# 11 | #.#####.#.###.# 12 | #.#...#.#.#...# 13 | #.#.#.#.#.#.### 14 | #...#...#...### 15 | ############### -------------------------------------------------------------------------------- /go/2024/21/sample.txt: -------------------------------------------------------------------------------- 1 | 029A 2 | 980A 3 | 179A 4 | 456A 5 | 379A -------------------------------------------------------------------------------- /go/2024/22/sample.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 2024 -------------------------------------------------------------------------------- /go/2024/23/sample.txt: -------------------------------------------------------------------------------- 1 | kh-tc 2 | qp-kh 3 | de-cg 4 | ka-co 5 | yn-aq 6 | qp-ub 7 | cg-tb 8 | vc-aq 9 | tb-ka 10 | wh-tc 11 | yn-cg 12 | kh-ub 13 | ta-co 14 | de-co 15 | tc-td 16 | tb-wq 17 | wh-td 18 | ta-ka 19 | td-qp 20 | aq-cg 21 | wq-ub 22 | ub-vc 23 | de-ta 24 | wq-aq 25 | wq-vc 26 | wh-yn 27 | ka-de 28 | kh-ta 29 | co-tc 30 | wh-qp 31 | tb-vc 32 | td-yn -------------------------------------------------------------------------------- /go/2024/24/day24_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 2024 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 59336987801432 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func TestPart2Input(t *testing.T) { 27 | var inputDay = utils.Input() 28 | result := Part2(inputDay) 29 | expected := "ctg,dmh,dvq,rpb,rpv,z11,z31,z38" 30 | if result != expected { 31 | t.Errorf("Result is incorrect, got: %s, want: %s.", result, expected) 32 | } 33 | } 34 | 35 | func BenchmarkPart1(b *testing.B) { 36 | var inputDay = utils.Input() 37 | for range b.N { 38 | Part1(inputDay) 39 | } 40 | } 41 | func BenchmarkPart2(b *testing.B) { 42 | var inputDay = utils.Input() 43 | for range b.N { 44 | Part2(inputDay) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /go/2024/24/sample.txt: -------------------------------------------------------------------------------- 1 | x00: 1 2 | x01: 0 3 | x02: 1 4 | x03: 1 5 | x04: 0 6 | y00: 1 7 | y01: 1 8 | y02: 1 9 | y03: 1 10 | y04: 1 11 | 12 | ntg XOR fgs -> mjb 13 | y02 OR x01 -> tnw 14 | kwq OR kpj -> z05 15 | x00 OR x03 -> fst 16 | tgd XOR rvg -> z01 17 | vdt OR tnw -> bfw 18 | bfw AND frj -> z10 19 | ffh OR nrd -> bqk 20 | y00 AND y03 -> djm 21 | y03 OR y00 -> psh 22 | bqk OR frj -> z08 23 | tnw OR fst -> frj 24 | gnj AND tgd -> z11 25 | bfw XOR mjb -> z00 26 | x03 OR x00 -> vdt 27 | gnj AND wpb -> z02 28 | x04 AND y00 -> kjc 29 | djm OR pbm -> qhw 30 | nrd AND vdt -> hwm 31 | kjc AND fst -> rvg 32 | y04 OR y02 -> fgs 33 | y01 AND x02 -> pbm 34 | ntg OR kjc -> kwq 35 | psh XOR fgs -> tgd 36 | qhw XOR tgd -> z09 37 | pbm OR djm -> kpj 38 | x03 XOR y03 -> ffh 39 | x00 XOR y04 -> ntg 40 | bfw OR bqk -> z06 41 | nrd XOR fgs -> wpb 42 | frj XOR qhw -> z04 43 | bqk OR frj -> z07 44 | y03 OR x01 -> nrd 45 | hwm AND bqk -> z03 46 | tgd XOR rvg -> z12 47 | tnw OR pbm -> gnj -------------------------------------------------------------------------------- /go/2024/25/day25_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "github.com/wordygravy/advent-of-code/go/utils" 6 | "testing" 7 | ) 8 | 9 | func TestPart1(t *testing.T) { 10 | result := Part1(inputTest) 11 | expected := 3 12 | if result != expected { 13 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 14 | } 15 | } 16 | 17 | func TestPart1Input(t *testing.T) { 18 | var inputDay = utils.Input() 19 | result := Part1(inputDay) 20 | expected := 2978 21 | if result != expected { 22 | t.Errorf("Result is incorrect, got: %d, want: %d.", result, expected) 23 | } 24 | } 25 | 26 | func BenchmarkPart1(b *testing.B) { 27 | var inputDay = utils.Input() 28 | for range b.N { 29 | Part1(inputDay) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go/2024/25/sample.txt: -------------------------------------------------------------------------------- 1 | ##### 2 | .#### 3 | .#### 4 | .#### 5 | .#.#. 6 | .#... 7 | ..... 8 | 9 | ##### 10 | ##.## 11 | .#.## 12 | ...## 13 | ...#. 14 | ...#. 15 | ..... 16 | 17 | ..... 18 | #.... 19 | #.... 20 | #...# 21 | #.#.# 22 | #.### 23 | ##### 24 | 25 | ..... 26 | ..... 27 | #.#.. 28 | ###.. 29 | ###.# 30 | ###.# 31 | ##### 32 | 33 | ..... 34 | ..... 35 | ..... 36 | #.... 37 | #.#.. 38 | #.#.# 39 | ##### -------------------------------------------------------------------------------- /go/README.md: -------------------------------------------------------------------------------- 1 | ./initaoc/initaoc -y 2020 -d 19 2 | 3 | ### To run all tests 4 | go test ./... 5 | 6 | 7 | -------------------------------------------------------------------------------- /go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/wordygravy/advent-of-code/go 2 | 3 | go 1.23 4 | 5 | require golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c 6 | 7 | require ( 8 | github.com/bits-and-blooms/bitset v1.14.3 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /go/utils/math.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "golang.org/x/exp/constraints" 5 | ) 6 | 7 | func Abs[T constraints.Integer | constraints.Float](x T) T { 8 | if x < 0 { 9 | return -x 10 | } 11 | return x 12 | } 13 | 14 | func GCD(a, b int) int { 15 | for b != 0 { 16 | a, b = b, a%b 17 | } 18 | return a 19 | } 20 | 21 | func LCM(a, b int, integers ...int) int { 22 | res := a * b / GCD(a, b) 23 | for i := 0; i < len(integers); i++ { 24 | res = LCM(res, integers[i]) 25 | } 26 | return res 27 | } 28 | 29 | func Mod(a, b int) int { 30 | return (a%b + b) % b 31 | } 32 | -------------------------------------------------------------------------------- /go/utils/stack/stack.go: -------------------------------------------------------------------------------- 1 | package stack 2 | 3 | import "errors" 4 | 5 | type Stack[T any] []T 6 | 7 | func NewStack[T any]() Stack[T] { 8 | return make(Stack[T], 0) 9 | } 10 | 11 | func (s *Stack[T]) Push(c T) { 12 | *s = append(*s, c) 13 | } 14 | 15 | func (s *Stack[T]) Pop() (T, error) { 16 | l := len(*s) 17 | if l == 0 { 18 | var zero T 19 | return zero, errors.New("stack is empty") 20 | } 21 | top := (*s)[l-1] 22 | *s = (*s)[:l-1] 23 | return top, nil 24 | } 25 | 26 | func (s *Stack[T]) PushN(c []T) { 27 | *s = append(*s, c...) 28 | } 29 | 30 | func (s *Stack[T]) PopN(n int) ([]T, error) { 31 | l := len(*s) 32 | if l < n { 33 | var zero []T 34 | return zero, errors.New("stack is empty") 35 | } 36 | top := (*s)[l-n:] 37 | *s = (*s)[:l-n] 38 | return top, nil 39 | } 40 | 41 | func (s *Stack[T]) Peek() (T, error) { 42 | if s.IsEmpty() { 43 | var zero T 44 | return zero, errors.New("stack is empty") 45 | } 46 | return (*s)[len(*s)-1], nil 47 | } 48 | 49 | func (s *Stack[T]) IsEmpty() bool { 50 | return len(*s) == 0 51 | } 52 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | 4 | # Generated by Cargo 5 | # will have compiled files and executables 6 | target 7 | 8 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 9 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 10 | Cargo.lock 11 | 12 | # These are backup files generated by rustfmt 13 | **/*.rs.bk 14 | -------------------------------------------------------------------------------- /rust/2019/day01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day01" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day01/src/lib.rs: -------------------------------------------------------------------------------- 1 | use utils::parsing::lines_to_numbers; 2 | 3 | pub fn fuel(mass: i64) -> i64 { 4 | (mass / 3) - 2 5 | } 6 | 7 | pub fn recursive_fuel(mass: i64) -> i64 { 8 | let fuel = fuel(mass); 9 | if fuel <= 0 { 10 | 0 11 | } else { 12 | fuel + recursive_fuel(fuel) 13 | } 14 | } 15 | 16 | fn sum_fuel(masses: &Vec, fuel_func: fn(i64) -> i64) -> i64 { 17 | masses.iter().map(|&mass| fuel_func(mass.into())).sum() 18 | } 19 | 20 | pub fn part1(input: String) -> i64 { 21 | sum_fuel(&lines_to_numbers(input), fuel) 22 | } 23 | 24 | pub fn part2(input: String) -> i64 { 25 | sum_fuel(&lines_to_numbers(input), recursive_fuel) 26 | } 27 | -------------------------------------------------------------------------------- /rust/2019/day01/src/main.rs: -------------------------------------------------------------------------------- 1 | use day01::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 01 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day01/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use day01::fuel; 3 | use day01::recursive_fuel; 4 | use crate::{part1, part2}; 5 | 6 | #[test] 7 | fn test_fuel() { 8 | assert_eq!(2, fuel(12)); 9 | assert_eq!(2, fuel(14)); 10 | } 11 | 12 | #[test] 13 | fn test_recursive_fuel() { 14 | assert_eq!(2, recursive_fuel(12)); 15 | assert_eq!(966, recursive_fuel(1969)); 16 | assert_eq!(50346, recursive_fuel(100756)); 17 | } 18 | 19 | #[test] 20 | fn test_input_part1() { 21 | assert_eq!(3297626, part1(include_str!("../input.txt").to_string())); 22 | } 23 | 24 | #[test] 25 | fn test_input_part2() { 26 | assert_eq!( 27 | 4943578, 28 | part2(include_str!("../input.txt").to_string()) 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rust/2019/day02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day02" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day02/src/main.rs: -------------------------------------------------------------------------------- 1 | use day02::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 02 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day02/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!( 7 | 2692315, 8 | part1(include_str!("../input.txt").to_string()) 9 | ); 10 | } 11 | 12 | #[test] 13 | fn test_input_part2() { 14 | assert_eq!( 15 | 9507, 16 | part2(include_str!("../input.txt").to_string()) 17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rust/2019/day03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day03" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day03/src/main.rs: -------------------------------------------------------------------------------- 1 | use day03::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 03 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day04" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day04/src/main.rs: -------------------------------------------------------------------------------- 1 | use day04::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 04 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1("137683-596253".to_string()), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2("137683-596253".to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day04/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(1864, part1("137683-596253".to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { assert_eq!(1258, part2("137683-596253".to_string())); } 11 | } 12 | -------------------------------------------------------------------------------- /rust/2019/day05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day05" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day05/src/main.rs: -------------------------------------------------------------------------------- 1 | use day05::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 05 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day05/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(16574641, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(15163975, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day06" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day06/sample.txt: -------------------------------------------------------------------------------- 1 | COM)B 2 | B)C 3 | C)D 4 | D)E 5 | E)F 6 | B)G 7 | G)H 8 | D)I 9 | E)J 10 | J)K 11 | K)L -------------------------------------------------------------------------------- /rust/2019/day06/sample2.txt: -------------------------------------------------------------------------------- 1 | COM)B 2 | B)C 3 | C)D 4 | D)E 5 | E)F 6 | B)G 7 | G)H 8 | D)I 9 | E)J 10 | J)K 11 | K)L 12 | K)YOU 13 | I)SAN -------------------------------------------------------------------------------- /rust/2019/day06/src/main.rs: -------------------------------------------------------------------------------- 1 | use day06::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 06 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string(),), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day06/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | #[test] 4 | fn test_part1() { 5 | assert_eq!(42, part1(include_str!("../input_test.txt").to_string())); 6 | } 7 | 8 | #[test] 9 | fn test_part2() { 10 | assert_eq!(4, part2(include_str!("../input_test2.txt").to_string())); 11 | } 12 | 13 | #[test] 14 | fn test_input_part1() { 15 | assert_eq!(253104, part1(include_str!("../input.txt").to_string())); 16 | } 17 | 18 | #[test] 19 | fn test_input_part2() { 20 | assert_eq!(499, part2(include_str!("../input.txt").to_string())); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rust/2019/day07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day07" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | itertools="0.10.1" 11 | -------------------------------------------------------------------------------- /rust/2019/day07/src/main.rs: -------------------------------------------------------------------------------- 1 | use day07::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 07 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day08" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2019/day08/src/main.rs: -------------------------------------------------------------------------------- 1 | use day08::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 08 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day08/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::part1; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(2975, part1(include_str!("../input.txt").to_string())); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /rust/2019/day09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day09" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day09/src/lib.rs: -------------------------------------------------------------------------------- 1 | use intcode::Machine; 2 | use utils::parsing::comma_separated_to_numbers; 3 | 4 | pub fn part1(input: String) -> i64 { 5 | let code = comma_separated_to_numbers(input); 6 | let mut machine = Machine::new(code, vec![1]); 7 | machine.run(); 8 | *machine.get_last_output().last().unwrap() 9 | } 10 | 11 | pub fn part2(input: String) -> i64 { 12 | let code = comma_separated_to_numbers(input); 13 | let mut machine = Machine::new(code, vec![2]); 14 | machine.run(); 15 | *machine.get_last_output().last().unwrap() 16 | } 17 | -------------------------------------------------------------------------------- /rust/2019/day09/src/main.rs: -------------------------------------------------------------------------------- 1 | use day09::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 09 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day09/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(3512778005, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(35920, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day10" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day10/sample.txt: -------------------------------------------------------------------------------- 1 | .#..# 2 | ..... 3 | ##### 4 | ....# 5 | ...## -------------------------------------------------------------------------------- /rust/2019/day10/sample2.txt: -------------------------------------------------------------------------------- 1 | .#..##.###...####### 2 | ##.############..##. 3 | .#.######.########.# 4 | .###.#######.####.#. 5 | #####.##.#.##.###.## 6 | ..#####..#.######### 7 | #################### 8 | #.####....###.#.#.## 9 | ##.################# 10 | #####.##.###..####.. 11 | ..######..##.####### 12 | ####.##.####...##..# 13 | .#####..#.######.### 14 | ##...#.##########... 15 | #.##########.####### 16 | .####.#.###.###.#.## 17 | ....##.##.###..##### 18 | .#.#.###########.### 19 | #.#.#.#####.####.### 20 | ###.##.####.##.#..## -------------------------------------------------------------------------------- /rust/2019/day10/src/main.rs: -------------------------------------------------------------------------------- 1 | use day10::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 10 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day10/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(284, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(404, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day11" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day11/src/main.rs: -------------------------------------------------------------------------------- 1 | use day11::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 11 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day11/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(1934, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | // #[test] 10 | // fn test_input_part2() { 11 | // assert_eq!(404, part2(include_str!("../input.txt").to_string())); 12 | // } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day12" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day12/sample.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /rust/2019/day12/src/main.rs: -------------------------------------------------------------------------------- 1 | use day12::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 12 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day12/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(1934, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | // #[test] 10 | // fn test_input_part2() { 11 | // assert_eq!(404, part2(include_str!("../input.txt").to_string())); 12 | // } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day13" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day13/src/main.rs: -------------------------------------------------------------------------------- 1 | use day13::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 13 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day13/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(173, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(8942, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day14" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day14/sample.txt: -------------------------------------------------------------------------------- 1 | 10 ORE => 10 A 2 | 1 ORE => 1 B 3 | 7 A, 1 B => 1 C 4 | 7 A, 1 C => 1 D 5 | 7 A, 1 D => 1 E 6 | 7 A, 1 E => 1 FUEL -------------------------------------------------------------------------------- /rust/2019/day14/sample3.txt: -------------------------------------------------------------------------------- 1 | 157 ORE => 5 NZVS 2 | 165 ORE => 6 DCFZ 3 | 44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL 4 | 12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ 5 | 179 ORE => 7 PSHF 6 | 177 ORE => 5 HKGWZ 7 | 7 DCFZ, 7 PSHF => 2 XJWVT 8 | 165 ORE => 2 GPVTF 9 | 3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT -------------------------------------------------------------------------------- /rust/2019/day14/sample4.txt: -------------------------------------------------------------------------------- 1 | 2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG 2 | 17 NVRVD, 3 JNWZP => 8 VPVL 3 | 53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL 4 | 22 VJHF, 37 MNCFX => 5 FWMGM 5 | 139 ORE => 4 NVRVD 6 | 144 ORE => 7 JNWZP 7 | 5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC 8 | 5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV 9 | 145 ORE => 6 MNCFX 10 | 1 NVRVD => 8 CXFTF 11 | 1 VJHF, 6 MNCFX => 4 RFSQX 12 | 176 ORE => 6 VJHF -------------------------------------------------------------------------------- /rust/2019/day14/sample5.txt: -------------------------------------------------------------------------------- 1 | 171 ORE => 8 CNZTR 2 | 7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL 3 | 114 ORE => 4 BHXH 4 | 14 VRPVC => 6 BMBT 5 | 6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL 6 | 6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT 7 | 15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW 8 | 13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW 9 | 5 BMBT => 4 WPTQ 10 | 189 ORE => 9 KTJDG 11 | 1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP 12 | 12 VRPVC, 27 CNZTR => 2 XDBXC 13 | 15 KTJDG, 12 BHXH => 5 XCVML 14 | 3 BHXH, 2 VRPVC => 7 MZWV 15 | 121 ORE => 7 VRPVC 16 | 7 XCVML => 6 RJRHP 17 | 5 BHXH, 4 VRPVC => 5 LTCX -------------------------------------------------------------------------------- /rust/2019/day14/src/main.rs: -------------------------------------------------------------------------------- 1 | use day14::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 14 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day14/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1_1() { 6 | assert_eq!(31, part1(include_str!("../input_test.txt").to_string())); 7 | } 8 | #[test] 9 | fn test_part1_2() { 10 | assert_eq!(165, part1(include_str!("../input_test2.txt").to_string())); 11 | } 12 | #[test] 13 | fn test_part1_3() { 14 | assert_eq!(13312, part1(include_str!("../input_test3.txt").to_string())); 15 | } 16 | 17 | #[test] 18 | fn test_input_part1() { 19 | assert_eq!(628586, part1(include_str!("../input.txt").to_string())); 20 | } 21 | 22 | #[test] 23 | fn test_input_part2() { 24 | assert_eq!(3209254, part2(include_str!("../input.txt").to_string())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /rust/2019/day15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day15" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day15/src/main.rs: -------------------------------------------------------------------------------- 1 | use day15::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 15 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day15/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(226, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(342, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day16" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day16/sample.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /rust/2019/day16/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day16::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 16 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day17/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day17" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day17/src/main.rs: -------------------------------------------------------------------------------- 1 | use day17::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 17 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2019/day17/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(6672, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(923017, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day18" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day18/sample1.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #f.D.E.e.C.b.A.@.a.B.c.# 3 | ######################.# 4 | #d.....................# 5 | ######################## -------------------------------------------------------------------------------- /rust/2019/day18/sample2.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #...............b.C.D.f# 3 | #.###################### 4 | #.....@.a.B.c.d.A.e.F.g# 5 | ######################## -------------------------------------------------------------------------------- /rust/2019/day18/sample3.txt: -------------------------------------------------------------------------------- 1 | ################# 2 | #i.G..c...e..H.p# 3 | ########.######## 4 | #j.A..b...f..D.o# 5 | ########@######## 6 | #k.E..a...g..B.n# 7 | ########.######## 8 | #l.F..d...h..C.m# 9 | ################# 10 | -------------------------------------------------------------------------------- /rust/2019/day18/sample4.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #@..............ac.GI.b# 3 | ###d#e#f################ 4 | ###A#B#C################ 5 | ###g#h#i################ 6 | ######################## -------------------------------------------------------------------------------- /rust/2019/day18/sample5.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #......b#..............# 3 | #@###.###..............# 4 | #......a#..............# 5 | ######################## -------------------------------------------------------------------------------- /rust/2019/day18/sample6.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #a.#Cd# 3 | ##...## 4 | ##.@.## 5 | ##...## 6 | #cB#Ab# 7 | ####### -------------------------------------------------------------------------------- /rust/2019/day18/sample7.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #DcBa.#.GhKl# 3 | #.###...#I### 4 | #e#d#.@.#j#k# 5 | ###C#...###J# 6 | #fEbA.#.FgHi# 7 | ############# -------------------------------------------------------------------------------- /rust/2019/day18/sample8.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #g#f.D#..h#l# 3 | #F###e#E###.# 4 | #dCba...BcIJ# 5 | #####.@.##### 6 | #nK.L...G...# 7 | #M###N#H###.# 8 | #o#m..#i#jk.# 9 | ############# -------------------------------------------------------------------------------- /rust/2019/day18/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day18::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 18 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day19/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day19" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day19/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day19::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 19 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day19/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(150, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(12201460, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day20" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day20/sample.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | #######0######### 4 | #######.........# 5 | #######.#######.# 6 | #######.#######.# 7 | #######b#######.# 8 | ##### ###.# 9 | B..## ###.# 10 | ##.## ###.# 11 | ##..d ###.# 12 | ##### ###.# 13 | #########f#####.# 14 | D.#######...###.# 15 | #.#########.###.# 16 | F.#########.....# 17 | ###########1##### 18 | 19 | -------------------------------------------------------------------------------- /rust/2019/day20/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day20::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 20 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | // 2147483647 too high 24 | 25 | #[cfg(test)] 26 | mod tests; 27 | -------------------------------------------------------------------------------- /rust/2019/day20/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::part1; 3 | use crate::part2; 4 | 5 | #[test] 6 | fn test_part1() { 7 | assert_eq!(23, part1(include_str!("../input_test.txt").to_string())); 8 | } 9 | 10 | #[test] 11 | fn test_part2() { 12 | assert_eq!(396, part2(include_str!("../input_test2.txt").to_string())); 13 | } 14 | 15 | #[test] 16 | fn test_input_part1() { 17 | assert_eq!(548, part1(include_str!("../input.txt").to_string())); 18 | } 19 | 20 | #[test] 21 | fn test_input_part2() { 22 | assert_eq!(6452, part2(include_str!("../input.txt").to_string())); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rust/2019/day21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day21" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day21/src/lib.rs: -------------------------------------------------------------------------------- 1 | use intcode::Machine; 2 | use utils::parsing::comma_separated_to_numbers; 3 | const PROGRAM1: &str = r"NOT B J 4 | NOT C T 5 | OR T J 6 | AND D J 7 | NOT A T 8 | OR T J 9 | WALK 10 | "; 11 | const PROGRAM2: &str = r"NOT B J 12 | NOT C T 13 | OR T J 14 | AND D J 15 | AND H J 16 | NOT A T 17 | OR T J 18 | RUN 19 | "; 20 | 21 | pub fn solve(input: String, program: &str) -> i64 { 22 | let code = comma_separated_to_numbers(input); 23 | let input = program.chars().map(|c| c as i64).collect::>(); 24 | let mut machine = Machine::new(code.clone(), input); 25 | machine.run(); 26 | let output = machine.get_output(); 27 | for c in output { 28 | if c < 256 { 29 | print!("{}", c as u8 as char); 30 | } else { 31 | return c; 32 | } 33 | } 34 | 0 35 | } 36 | 37 | pub fn part1(input: String) -> i64 { 38 | solve(input, PROGRAM1) 39 | } 40 | 41 | pub fn part2(input: String) -> i64 { 42 | solve(input, PROGRAM2) 43 | } 44 | -------------------------------------------------------------------------------- /rust/2019/day21/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day21::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 21 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day21/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(19355436, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(1142618405, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day22/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day22" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day22/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day22::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 22 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day23/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day23" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day23/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day23::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 23 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day23/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(24602, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(1142618405, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/day24/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day24" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | num = "0.4.0" -------------------------------------------------------------------------------- /rust/2019/day24/sample.txt: -------------------------------------------------------------------------------- 1 | ....# 2 | #..#. 3 | #..## 4 | ..#.. 5 | #.... -------------------------------------------------------------------------------- /rust/2019/day24/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day24::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 24 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day24/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::part1; 3 | use crate::part2; 4 | 5 | #[test] 6 | fn test_input_test1() { 7 | assert_eq!( 8 | 2129920, 9 | part1(include_str!("../input_test.txt").to_string()) 10 | ); 11 | } 12 | 13 | // #[test] 14 | // fn test_input_test2() { 15 | // assert_eq!(99, part1(include_str!("../input_test.txt").to_string())); 16 | // } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(28717468, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!(2014, part2(include_str!("../input.txt").to_string())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rust/2019/day25/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day25" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | intcode = { path = "../intcode" } 10 | -------------------------------------------------------------------------------- /rust/2019/day25/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | 3 | use day25::{part1, part2}; 4 | 5 | fn main() { 6 | println!("--2019 day 25 solution--"); 7 | let now = Instant::now(); 8 | 9 | println!( 10 | "Part 1: {} in {} ms", 11 | part1(include_str!("../input.txt").to_string()), 12 | now.elapsed().as_micros() as f64 / 1000.0 13 | ); 14 | 15 | let now = Instant::now(); 16 | println!( 17 | "Part 2: {} in {} ms", 18 | part2(include_str!("../input.txt").to_string()), 19 | now.elapsed().as_micros() as f64 / 1000.0 20 | ); 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests; 25 | -------------------------------------------------------------------------------- /rust/2019/day25/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | assert_eq!(24602, part1(include_str!("../input.txt").to_string())); 7 | } 8 | 9 | #[test] 10 | fn test_input_part2() { 11 | assert_eq!(1142618405, part2(include_str!("../input.txt").to_string())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /rust/2019/intcode/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "intcode" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /rust/2020/borrow/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "borrow" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | -------------------------------------------------------------------------------- /rust/2020/borrow/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | fn main() { 3 | let mut map: HashMap = HashMap::new(); 4 | let n = 10; 5 | 6 | let value = map.get(&n); 7 | map.insert(n, "hello".to_string()); 8 | if value.is_some() { 9 | println!("{}", value.unwrap()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /rust/2020/day01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day01" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | itertools = "0.10.2" 10 | -------------------------------------------------------------------------------- /rust/2020/day01/src/main.rs: -------------------------------------------------------------------------------- 1 | use day01::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 01 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day01/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 1019904; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 176647680; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day02" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | regex = "1.5.5" 10 | peg = "0.6.3" 11 | -------------------------------------------------------------------------------- /rust/2020/day02/src/main.rs: -------------------------------------------------------------------------------- 1 | use day02::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 02 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day02/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 493; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 593; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day03" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day03/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub fn part1(input: String) -> i64 { 2 | let values = input.lines().map(|line| line.chars().cycle()); 3 | let cpt = values.enumerate().fold(0, |acc, (i, line)| { 4 | if line.clone().nth(3 * i).unwrap() == '#' { 5 | acc + 1 6 | } else { 7 | acc 8 | } 9 | }); 10 | cpt 11 | } 12 | 13 | pub fn part2(input: String) -> i64 { 14 | let slopes = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]; 15 | let cpt = slopes.iter().fold(1, |prod, (x, y)| { 16 | let values = input.lines().map(|line| line.chars().cycle()); 17 | let cpt = values.enumerate().fold(0, |acc, (j, line)| { 18 | if j % y == 0 { 19 | let i = (x * j) / y; 20 | let element = line.clone().nth(i).unwrap(); 21 | if element == '#' { 22 | acc + 1 23 | } else { 24 | acc 25 | } 26 | } else { 27 | acc 28 | } 29 | }); 30 | prod * cpt 31 | }); 32 | cpt 33 | } 34 | -------------------------------------------------------------------------------- /rust/2020/day03/src/main.rs: -------------------------------------------------------------------------------- 1 | use day03::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 03 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day03/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 167; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 736527114; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day04" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | nom = "7.1.1" 10 | -------------------------------------------------------------------------------- /rust/2020/day04/src/main.rs: -------------------------------------------------------------------------------- 1 | use day04::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 04 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day04/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 256; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 198; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day05" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day05/src/lib.rs: -------------------------------------------------------------------------------- 1 | fn to_bin(input: &str, lower: char) -> usize { 2 | input 3 | .chars() 4 | .fold(0, |acc, c| if c == lower { 2 * acc } else { 2 * acc + 1 }) 5 | } 6 | 7 | pub fn part1(input: String) -> i64 { 8 | // F:0 B:1 9 | // L:0 R:1 10 | let res = input 11 | .lines() 12 | .map(|line| to_bin(&line[0..7], 'F') * 8 + to_bin(&line[7..10], 'L')) 13 | .max() 14 | .unwrap(); 15 | res.try_into().unwrap() 16 | } 17 | 18 | pub fn part2(input: String) -> i64 { 19 | let mut seats = [false; 912]; 20 | input.lines().for_each(|line| { 21 | let seat = to_bin(&line[0..7], 'F') * 8 + to_bin(&line[7..10], 'L'); 22 | seats[seat] = true; 23 | }); 24 | 25 | let mut previous = false; 26 | let mut res = 0; 27 | seats.iter().enumerate().for_each(|(index, element)| { 28 | if !element && previous { 29 | res = index.try_into().unwrap(); 30 | } 31 | previous = *element; 32 | }); 33 | res 34 | } 35 | -------------------------------------------------------------------------------- /rust/2020/day05/src/main.rs: -------------------------------------------------------------------------------- 1 | use day05::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 05 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day05/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 911; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 629; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day06" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day06/src/main.rs: -------------------------------------------------------------------------------- 1 | use day06::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 06 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day06/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_input_part1() { 6 | let expected = 6387; 7 | let result = part1(include_str!("../input.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_input_part2() { 13 | let expected = 3039; 14 | let result = part2(include_str!("../input.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /rust/2020/day11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day11" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day11/sample.txt: -------------------------------------------------------------------------------- 1 | L.LL.LL.LL 2 | LLLLLLL.LL 3 | L.L.L..L.. 4 | LLLL.LL.LL 5 | L.LL.LL.LL 6 | L.LLLLL.LL 7 | ..L.L..... 8 | LLLLLLLLLL 9 | L.LLLLLL.L 10 | L.LLLLL.LL 11 | -------------------------------------------------------------------------------- /rust/2020/day11/src/main.rs: -------------------------------------------------------------------------------- 1 | use day11::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 11 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day11/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 37; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 26; 14 | let result = part2(include_str!("../input_test.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(2166, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!(1955, part2(include_str!("../input.txt").to_string())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rust/2020/day12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day12" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day12/sample.txt: -------------------------------------------------------------------------------- 1 | F10 2 | N3 3 | F7 4 | R90 5 | F11 6 | -------------------------------------------------------------------------------- /rust/2020/day12/src/main.rs: -------------------------------------------------------------------------------- 1 | use day12::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 12 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day12/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 25; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 286; 14 | let result = part2(include_str!("../input_test.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(1319, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!(62434, part2(include_str!("../input.txt").to_string())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rust/2020/day13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day13" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day13/sample.txt: -------------------------------------------------------------------------------- 1 | 939 2 | 7,13,x,x,59,x,31,19 3 | -------------------------------------------------------------------------------- /rust/2020/day13/src/main.rs: -------------------------------------------------------------------------------- 1 | use day13::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 13 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day13/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 295; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 1068781; 14 | let result = part2(include_str!("../input_test.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(102, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!( 26 | 327300950120029, 27 | part2(include_str!("../input.txt").to_string()) 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rust/2020/day14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day14" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | peg = "0.8" 10 | -------------------------------------------------------------------------------- /rust/2020/day14/sample.txt: -------------------------------------------------------------------------------- 1 | mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X 2 | mem[8] = 11 3 | mem[7] = 101 4 | mem[8] = 0 5 | -------------------------------------------------------------------------------- /rust/2020/day14/sample2.txt: -------------------------------------------------------------------------------- 1 | mask = 000000000000000000000000000000X1001X 2 | mem[42] = 100 3 | mask = 00000000000000000000000000000000X0XX 4 | mem[26] = 1 5 | -------------------------------------------------------------------------------- /rust/2020/day14/src/main.rs: -------------------------------------------------------------------------------- 1 | use day14::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 14 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day14/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 165; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 208; 14 | let result = part2(include_str!("../input_test2.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!( 21 | 3059488894985, 22 | part1(include_str!("../input.txt").to_string()) 23 | ); 24 | } 25 | 26 | #[test] 27 | fn test_input_part2() { 28 | assert_eq!( 29 | 2900994392308, 30 | part2(include_str!("../input.txt").to_string()) 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rust/2020/day15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day15" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/2020/day15/sample.txt: -------------------------------------------------------------------------------- 1 | mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X 2 | mem[8] = 11 3 | mem[7] = 101 4 | mem[8] = 0 5 | -------------------------------------------------------------------------------- /rust/2020/day15/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | fn play(turn: usize, n: usize, map: &mut HashMap) -> usize { 4 | let previous = map.insert(n, turn); 5 | if previous.is_some() { 6 | turn - previous.unwrap() 7 | } else { 8 | 0 9 | } 10 | } 11 | 12 | pub fn solve(input: String, n: usize) -> i64 { 13 | let mut map = input 14 | .trim() 15 | .split(",") 16 | .enumerate() 17 | .map(|(i, n)| (n.parse::().unwrap(), i + 1)) 18 | .collect::>(); 19 | 20 | let mut spoken = 0; 21 | for turn in 1 + map.len()..n { 22 | spoken = play(turn, spoken, &mut map); 23 | } 24 | 25 | spoken as i64 26 | // (1 + map.len()..n).fold(0, |spoken, turn| play(turn, spoken, &mut map)) as i64 27 | } 28 | 29 | pub fn part1(input: String) -> i64 { 30 | solve(input, 2020) 31 | } 32 | 33 | pub fn part2(input: String) -> i64 { 34 | solve(input, 30000000) 35 | } 36 | -------------------------------------------------------------------------------- /rust/2020/day15/src/main.rs: -------------------------------------------------------------------------------- 1 | use day15::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 15 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day16" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | peg = "0.8" 10 | -------------------------------------------------------------------------------- /rust/2020/day16/sample.txt: -------------------------------------------------------------------------------- 1 | class: 1-3 or 5-7 2 | row: 6-11 or 33-44 3 | seat: 13-40 or 45-50 4 | 5 | your ticket: 6 | 7,1,14 7 | 8 | nearby tickets: 9 | 7,3,47 10 | 40,4,50 11 | 55,2,20 12 | 38,6,12 13 | -------------------------------------------------------------------------------- /rust/2020/day16/src/main.rs: -------------------------------------------------------------------------------- 1 | use day16::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 16 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day16/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 71; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | // #[test] 12 | // fn test_part2() { 13 | // let expected = 208; 14 | // let result = part2(include_str!("../input_test2.txt").to_string()); 15 | // assert_eq!(expected, result); 16 | // } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(23054, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!( 26 | 51240700105297, 27 | part2(include_str!("../input.txt").to_string()) 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rust/2020/day17/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day17" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | itertools = "0.8.2" 10 | -------------------------------------------------------------------------------- /rust/2020/day17/sample.txt: -------------------------------------------------------------------------------- 1 | .#. 2 | ..# 3 | ### 4 | -------------------------------------------------------------------------------- /rust/2020/day17/src/main.rs: -------------------------------------------------------------------------------- 1 | use day17::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 17 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2020/day17/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 112; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 848; 14 | let result = part2(include_str!("../input_test.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | assert_eq!(223, part1(include_str!("../input.txt").to_string())); 21 | } 22 | 23 | #[test] 24 | fn test_input_part2() { 25 | assert_eq!(1884, part2(include_str!("../input.txt").to_string())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /rust/2020/day18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day18" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | peg = "0.8" 10 | -------------------------------------------------------------------------------- /rust/2020/day18/sample.txt: -------------------------------------------------------------------------------- 1 | .#. 2 | ..# 3 | ### 4 | -------------------------------------------------------------------------------- /rust/2020/day18/src/main.rs: -------------------------------------------------------------------------------- 1 | use day18::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2020 day 18 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/2021/day01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day01" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | 10 | [dev-dependencies] 11 | criterion = "0.3.5" 12 | 13 | [[bench]] 14 | name = "benchmark" 15 | harness = false 16 | -------------------------------------------------------------------------------- /rust/2021/day01/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day01::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day01/sample.txt: -------------------------------------------------------------------------------- 1 | 199 2 | 200 3 | 208 4 | 210 5 | 200 6 | 207 7 | 240 8 | 269 9 | 260 10 | 263 11 | -------------------------------------------------------------------------------- /rust/2021/day01/src/lib.rs: -------------------------------------------------------------------------------- 1 | use utils::parsing::lines_to_numbers; 2 | 3 | pub fn increases(values: &Vec) -> usize { 4 | let iter = values.windows(2); 5 | let diff = iter.map(|pair| pair[1] - pair[0]); 6 | return diff.filter(|&x| x > 0).count(); 7 | } 8 | 9 | pub fn part1(input: String) -> i64 { 10 | let values = lines_to_numbers(input); 11 | return increases(&values).try_into().unwrap(); 12 | } 13 | 14 | pub fn part2(input: String) -> i64 { 15 | let values = lines_to_numbers(input); 16 | let sums = values.windows(3).map(|pair| pair[0] + pair[1] + pair[2]); 17 | let vsums = sums.collect::>(); 18 | return increases(&vsums).try_into().unwrap(); 19 | } 20 | -------------------------------------------------------------------------------- /rust/2021/day01/src/main.rs: -------------------------------------------------------------------------------- 1 | // use aoc_shared::input::load_line_delimited_input_from_autodetect; 2 | use day01::{part1, part2}; 3 | 4 | fn main() { 5 | println!("--2021 day 01 solution--"); 6 | println!( 7 | "Part 1: {}", 8 | part1(include_str!("../input.txt").to_string()) 9 | ); 10 | println!( 11 | "Part 2: {}", 12 | part2(include_str!("../input.txt").to_string()) 13 | ); 14 | } 15 | 16 | #[cfg(test)] 17 | mod tests { 18 | use crate::{part1, part2}; 19 | 20 | #[test] 21 | fn test_part1() { 22 | let expected = 7; 23 | let result = part1(include_str!("../input_test.txt").to_string()); 24 | assert_eq!(expected, result); 25 | } 26 | 27 | #[test] 28 | fn test_part2() { 29 | let expected = 5; 30 | let result = part2(include_str!("../input_test.txt").to_string()); 31 | assert_eq!(expected, result); 32 | } 33 | 34 | #[test] 35 | fn test_input_part1() { 36 | assert_eq!(1722, part1(include_str!("../input.txt").to_string())); 37 | } 38 | 39 | #[test] 40 | fn test_input_part2() { 41 | assert_eq!(1748, part2(include_str!("../input.txt").to_string())); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rust/2021/day02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day02" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | regex = "1.5.5" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day02/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day02::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day02/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day02/sample.txt: -------------------------------------------------------------------------------- 1 | forward 5 2 | down 5 3 | forward 8 4 | up 3 5 | down 8 6 | forward 2 7 | -------------------------------------------------------------------------------- /rust/2021/day03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day03" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | 10 | [dev-dependencies] 11 | criterion = "0.3.5" 12 | 13 | [[bench]] 14 | name = "benchmark" 15 | harness = false 16 | -------------------------------------------------------------------------------- /rust/2021/day03/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day03::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day03/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day03/sample.txt: -------------------------------------------------------------------------------- 1 | 00100 2 | 11110 3 | 10110 4 | 10111 5 | 10101 6 | 01111 7 | 00111 8 | 11100 9 | 10000 10 | 11001 11 | 00010 12 | 01010 13 | -------------------------------------------------------------------------------- /rust/2021/day03/src/main.rs: -------------------------------------------------------------------------------- 1 | use day03::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 03 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 22 * 9; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 23 * 10; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 3242606; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 4856080; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day04" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | array2d = "0.2.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day04/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day04::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day04/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day04/sample.txt: -------------------------------------------------------------------------------- 1 | 7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 2 | 3 | 22 13 17 11 0 4 | 8 2 23 4 24 5 | 21 9 14 16 7 6 | 6 10 3 18 5 7 | 1 12 20 15 19 8 | 9 | 3 15 0 2 22 10 | 9 18 13 17 5 11 | 19 8 7 25 23 12 | 20 11 10 24 4 13 | 14 21 16 12 6 14 | 15 | 14 21 17 24 4 16 | 10 16 15 9 19 17 | 18 8 23 26 20 18 | 22 11 13 6 5 19 | 2 0 12 3 7 20 | -------------------------------------------------------------------------------- /rust/2021/day04/src/main.rs: -------------------------------------------------------------------------------- 1 | use day04::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 04 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 24 * 188; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 148 * 13; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 74320; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 17884; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day05" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | array2d = "0.2.1" 10 | regex = "1.5.5" 11 | 12 | [dev-dependencies] 13 | criterion = "0.3.5" 14 | 15 | [[bench]] 16 | name = "benchmark" 17 | harness = false 18 | -------------------------------------------------------------------------------- /rust/2021/day05/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day05::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day05/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day05/sample.txt: -------------------------------------------------------------------------------- 1 | 0,9 -> 5,9 2 | 8,0 -> 0,8 3 | 9,4 -> 3,4 4 | 2,2 -> 2,1 5 | 7,0 -> 7,4 6 | 6,4 -> 2,0 7 | 0,9 -> 2,9 8 | 3,4 -> 1,4 9 | 0,0 -> 8,8 10 | 5,5 -> 8,2 11 | -------------------------------------------------------------------------------- /rust/2021/day05/src/main.rs: -------------------------------------------------------------------------------- 1 | use day05::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 05 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 5; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 12; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 7297; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 21038; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day06" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | 10 | [dev-dependencies] 11 | criterion = "0.3.5" 12 | 13 | [[bench]] 14 | name = "benchmark" 15 | harness = false 16 | -------------------------------------------------------------------------------- /rust/2021/day06/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day06::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day06/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day06/sample.txt: -------------------------------------------------------------------------------- 1 | 3,4,3,1,2 2 | -------------------------------------------------------------------------------- /rust/2021/day06/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub fn part1(input: String) -> i64 { 2 | simulate(input, 80) 3 | } 4 | 5 | pub fn part2(input: String) -> i64 { 6 | simulate(input, 256) 7 | } 8 | 9 | fn simulate(input: String, n: usize) -> i64 { 10 | let mut mult = input.split(',').fold([0; 9], |mut acc, value| { 11 | acc[value.trim().parse::().unwrap()] += 1; 12 | acc 13 | }); 14 | 15 | for _ in 0..n { 16 | mult.rotate_left(1); 17 | mult[6] += mult[8]; 18 | } 19 | mult.iter().sum::() as i64 20 | } 21 | -------------------------------------------------------------------------------- /rust/2021/day06/src/main.rs: -------------------------------------------------------------------------------- 1 | use day06::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 06 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests; 17 | -------------------------------------------------------------------------------- /rust/2021/day06/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | let expected = 5934; 7 | let result = part1(include_str!("../input_test.txt").to_string()); 8 | assert_eq!(expected, result); 9 | } 10 | 11 | #[test] 12 | fn test_part2() { 13 | let expected = 26984457539; 14 | let result = part2(include_str!("../input_test.txt").to_string()); 15 | assert_eq!(expected, result); 16 | } 17 | 18 | #[test] 19 | fn test_input_part1() { 20 | let expected = 351092; 21 | let result = part1(include_str!("../input.txt").to_string()); 22 | assert_eq!(expected, result); 23 | } 24 | 25 | #[test] 26 | fn test_input_part2() { 27 | let expected = 1595330616005; 28 | let result = part2(include_str!("../input.txt").to_string()); 29 | assert_eq!(expected, result); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rust/2021/day07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day07" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | 10 | [dev-dependencies] 11 | criterion = "0.3.5" 12 | 13 | [[bench]] 14 | name = "benchmark" 15 | harness = false 16 | -------------------------------------------------------------------------------- /rust/2021/day07/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day07::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day07/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day07/sample.txt: -------------------------------------------------------------------------------- 1 | 16,1,2,0,4,2,7,1,2,14 2 | -------------------------------------------------------------------------------- /rust/2021/day07/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub fn part1(input: String) -> i64 { 2 | search(input, |a, b| (a - b).abs()) 3 | } 4 | 5 | pub fn part2(input: String) -> i64 { 6 | search(input, |a, b| { 7 | let n = (a - b).abs(); 8 | n * (n + 1) / 2 9 | }) 10 | } 11 | 12 | pub fn search(input: String, cost: fn(a: i32, b: i32) -> i32) -> i64 { 13 | let values = input 14 | .split(',') 15 | .map(|s| s.trim().parse::().unwrap()) 16 | .collect::>(); 17 | let min_value = values.iter().min().unwrap(); 18 | let max_value = values.iter().max().unwrap(); 19 | let min_sum = (*min_value..*max_value) 20 | .map(|h| values.iter().map(|v| cost(*v, h)).sum::()) 21 | .min() 22 | .unwrap(); 23 | min_sum as i64 24 | } 25 | -------------------------------------------------------------------------------- /rust/2021/day07/src/main.rs: -------------------------------------------------------------------------------- 1 | use day07::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 07 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 37; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 168; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 355989; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 102245489; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day08" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | itertools = "0.10.3" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day08/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day08::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day08/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day08/sample.txt: -------------------------------------------------------------------------------- 1 | be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe 2 | edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc 3 | fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg 4 | fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb 5 | aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea 6 | fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb 7 | dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe 8 | bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef 9 | egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb 10 | gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce 11 | -------------------------------------------------------------------------------- /rust/2021/day08/src/main.rs: -------------------------------------------------------------------------------- 1 | use day08::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 08 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 26; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 61229; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 504; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 1073431; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day10" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | itertools = "0.10.3" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day10/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day10::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day10/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day10/sample.txt: -------------------------------------------------------------------------------- 1 | [({(<(())[]>[[{[]{<()<>> 2 | [(()[<>])]({[<{<<[]>>( 3 | {([(<{}[<>[]}>{[]{[(<()> 4 | (((({<>}<{<{<>}{[]{[]{} 5 | [[<[([]))<([[{}[[()]]] 6 | [{[{({}]{}}([{[{{{}}([] 7 | {<[[]]>}<{[{[{[]{()[[[] 8 | [<(<(<(<{}))><([]([]() 9 | <{([([[(<>()){}]>(<<{{ 10 | <{([{{}}[<[[[<>{}]]]>[]] 11 | -------------------------------------------------------------------------------- /rust/2021/day10/src/main.rs: -------------------------------------------------------------------------------- 1 | use day10::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 10 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 26397; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 288957; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 411471; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 3122628974; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day11" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | itertools = "0.10.3" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day11/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day11::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day11/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day11/sample.txt: -------------------------------------------------------------------------------- 1 | 5483143223 2 | 2745854711 3 | 5264556173 4 | 6141336146 5 | 6357385478 6 | 4167524645 7 | 2176841721 8 | 6882881134 9 | 4846848554 10 | 5283751526 11 | -------------------------------------------------------------------------------- /rust/2021/day11/src/main.rs: -------------------------------------------------------------------------------- 1 | use day11::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 11 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 1656; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | let expected = 195; 29 | let result = part2(include_str!("../input_test.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_input_part1() { 35 | let expected = 1681; 36 | let result = part1(include_str!("../input.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | 40 | #[test] 41 | fn test_input_part2() { 42 | let expected = 276; 43 | let result = part2(include_str!("../input.txt").to_string()); 44 | assert_eq!(expected, result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/2021/day13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day13" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | array2d = "0.2.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3.5" 13 | 14 | [[bench]] 15 | name = "benchmark" 16 | harness = false 17 | -------------------------------------------------------------------------------- /rust/2021/day13/benches/benchmark.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use day13::{part1, part2}; 3 | 4 | criterion_group!(benches, benchmark_part1, benchmark_part2); 5 | criterion_main!(benches); 6 | 7 | fn benchmark_part1(c: &mut Criterion) { 8 | c.bench_function("part-1", |b| { 9 | b.iter(|| black_box(part1(black_box(include_str!("../input.txt").to_string())))); 10 | }); 11 | } 12 | 13 | fn benchmark_part2(c: &mut Criterion) { 14 | c.bench_function("part-2", |b| { 15 | b.iter(|| black_box(part2(black_box(include_str!("../input.txt").to_string())))); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /rust/2021/day13/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2021/day13/sample.txt: -------------------------------------------------------------------------------- 1 | 6,10 2 | 0,14 3 | 9,10 4 | 0,3 5 | 10,4 6 | 4,11 7 | 6,0 8 | 6,12 9 | 4,1 10 | 0,13 11 | 10,12 12 | 3,4 13 | 3,0 14 | 8,4 15 | 1,10 16 | 2,14 17 | 8,10 18 | 9,0 19 | 20 | fold along y=7 21 | fold along x=5 22 | -------------------------------------------------------------------------------- /rust/2021/day13/src/main.rs: -------------------------------------------------------------------------------- 1 | use day13::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2021 day 13 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 17; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_input_part1() { 28 | let expected = 795; 29 | let result = part1(include_str!("../input.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rust/2022/day18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day18" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | 10 | -------------------------------------------------------------------------------- /rust/2022/day18/rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Specifies which edition is used by the parser. 2 | edition = "2021" 3 | 4 | # Prevent carriage returns 5 | newline_style = "Unix" 6 | 7 | # Use field initialize shorthand if possible. 8 | use_field_init_shorthand = true 9 | -------------------------------------------------------------------------------- /rust/2022/day18/sample.txt: -------------------------------------------------------------------------------- 1 | 2,2,2 2 | 1,2,2 3 | 3,2,2 4 | 2,1,2 5 | 2,3,2 6 | 2,2,1 7 | 2,2,3 8 | 2,2,4 9 | 2,2,6 10 | 1,2,5 11 | 3,2,5 12 | 2,1,5 13 | 2,3,5 -------------------------------------------------------------------------------- /rust/2022/day18/src/main.rs: -------------------------------------------------------------------------------- 1 | use day18::{part1, part2}; 2 | 3 | fn main() { 4 | println!("--2022 day 18 solution--"); 5 | println!( 6 | "Part 1: {}", 7 | part1(include_str!("../input.txt").to_string()) 8 | ); 9 | println!( 10 | "Part 2: {}", 11 | part2(include_str!("../input.txt").to_string()) 12 | ); 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use crate::{part1, part2}; 18 | 19 | #[test] 20 | fn test_part1() { 21 | let expected = 64; 22 | let result = part1(include_str!("../input_test.txt").to_string()); 23 | assert_eq!(expected, result); 24 | } 25 | 26 | #[test] 27 | fn test_input_part1() { 28 | let expected = 3470; 29 | let result = part1(include_str!("../input.txt").to_string()); 30 | assert_eq!(expected, result); 31 | } 32 | 33 | #[test] 34 | fn test_part2() { 35 | let expected = 58; 36 | let result = part2(include_str!("../input_test.txt").to_string()); 37 | assert_eq!(expected, result); 38 | } 39 | #[test] 40 | fn test_input_part2() { 41 | let expected = 1986; 42 | let result = part2(include_str!("../input.txt").to_string()); 43 | assert_eq!(expected, result); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rust/template/day01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day01" 3 | version = "0.1.0" 4 | authors = ["PEM"] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | utils = { path = "../../utils" } 9 | -------------------------------------------------------------------------------- /rust/template/day01/sample.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /rust/template/day01/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub fn part1(input: String) -> i64 { 2 | 0 3 | } 4 | 5 | pub fn part2(input: String) -> i64 { 6 | 0 7 | } 8 | 9 | -------------------------------------------------------------------------------- /rust/template/day01/src/main.rs: -------------------------------------------------------------------------------- 1 | use day01::{part1, part2}; 2 | use std::time::Instant; 3 | 4 | fn main() { 5 | println!("--2019 day 01 solution--"); 6 | let now = Instant::now(); 7 | 8 | println!( 9 | "Part 1: {} in {} ms", 10 | part1(include_str!("../input.txt").to_string(),), 11 | now.elapsed().as_micros() as f64 / 1000.0 12 | ); 13 | 14 | let now = Instant::now(); 15 | println!( 16 | "Part 2: {} in {} ms", 17 | part2(include_str!("../input.txt").to_string()), 18 | now.elapsed().as_micros() as f64 / 1000.0 19 | ); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | -------------------------------------------------------------------------------- /rust/template/day01/src/tests.rs: -------------------------------------------------------------------------------- 1 | mod tests { 2 | use crate::{part1, part2}; 3 | 4 | #[test] 5 | fn test_part1() { 6 | assert_eq!( 7 | 0, 8 | part1(include_str!("../input_test.txt").to_string()) 9 | ); 10 | } 11 | 12 | #[test] 13 | fn test_part2() { 14 | assert_eq!( 15 | 0, 16 | part2(include_str!("../input_test.txt").to_string()) 17 | ); 18 | } 19 | 20 | #[test] 21 | fn test_input_part1() { 22 | assert_eq!( 23 | 0, 24 | part1(include_str!("../input.txt").to_string()) 25 | ); 26 | } 27 | 28 | #[test] 29 | fn test_input_part2() { 30 | assert_eq!( 31 | 0, 32 | part2(include_str!("../input.txt").to_string()) 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rust/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "utils" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["rlib"] 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | -------------------------------------------------------------------------------- /rust/utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod parsing; 2 | -------------------------------------------------------------------------------- /rust/utils/src/parsing.rs: -------------------------------------------------------------------------------- 1 | pub fn lines_to_numbers(input: String) -> Vec { 2 | input 3 | .lines() 4 | .map(|line| line.trim().parse().unwrap()) 5 | .collect() 6 | } 7 | 8 | pub fn comma_separated_to_numbers(input: String) -> Vec { 9 | input 10 | .split(',') 11 | .map(|line| line.trim().parse().unwrap()) 12 | .collect() 13 | } 14 | -------------------------------------------------------------------------------- /tools/initaoc/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/wordygravy/advent-of-code/tools/initaoc 2 | 3 | go 1.19 4 | --------------------------------------------------------------------------------