├── flamegraphs └── .gitkeep ├── y2020 ├── ex15 │ ├── input.txt │ ├── Cargo.toml │ ├── benches │ │ └── bench_ex15.rs │ └── src │ │ └── lib.rs ├── ex23 │ ├── input.txt │ ├── Cargo.toml │ ├── benches │ │ └── bench_ex23.rs │ └── src │ │ └── cllist.rs ├── ex25 │ ├── input.txt │ ├── Cargo.toml │ ├── benches │ │ └── bench_ex25.rs │ └── src │ │ └── lib.rs ├── ex07 │ ├── part2.png │ ├── Cargo.toml │ └── example.txt ├── ex17 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_ex17.rs ├── ex22 │ ├── example.txt │ ├── examples │ │ └── part2.rs │ ├── Cargo.toml │ ├── input.txt │ └── benches │ │ └── bench_ex22.rs ├── ex13 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_ex13.rs ├── ex01 │ ├── Cargo.toml │ ├── src │ │ └── lib.rs │ ├── input.txt │ └── README.md ├── ex03 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── ex05 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── ex06 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── ex08 │ └── Cargo.toml ├── ex09 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── ex10 │ ├── Cargo.toml │ └── input.txt ├── ex11 │ └── Cargo.toml ├── ex12 │ └── Cargo.toml ├── ex04 │ └── Cargo.toml ├── ex02 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── ex20 │ ├── Cargo.toml │ ├── benches │ │ └── bench_ex20.rs │ └── src │ │ └── tiles_index.rs ├── ex21 │ ├── Cargo.toml │ └── benches │ │ └── bench_ex21.rs ├── ex24 │ ├── Cargo.toml │ └── benches │ │ └── bench_ex24.rs ├── ex19 │ ├── Cargo.toml │ └── benches │ │ └── bench_ex19.rs ├── ex14 │ ├── Cargo.toml │ └── benches │ │ └── bench_ex14.rs ├── ex16 │ ├── benches │ │ └── bench_ex16.rs │ └── Cargo.toml └── ex18 │ ├── Cargo.toml │ └── benches │ └── bench_ex18.rs ├── y2021 ├── ex17 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex17.rs ├── ex21 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex21.rs ├── ex23 │ ├── input.txt │ ├── src │ │ ├── command.rs │ │ ├── amphipod.rs │ │ ├── hole.rs │ │ └── lib.rs │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex23.rs ├── ex11 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex11.rs ├── ex01 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex01.rs ├── ex12 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex12.rs ├── ex02 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex02.rs ├── ex03 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex03.rs ├── ex04 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex04.rs ├── ex05 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex05.rs ├── ex06 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2021ex06.rs │ └── input.txt ├── ex07 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex07.rs ├── ex08 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex08.rs ├── ex09 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex09.rs ├── ex13 │ ├── Cargo.toml │ └── benches │ │ └── y2021bench_ex13.rs ├── ex14 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2021ex14.rs │ └── input.txt ├── ex15 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex15.rs ├── ex16 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2021ex16.rs │ ├── NOTES.md │ └── input.txt ├── ex20 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex20.rs ├── ex24 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex24.rs ├── ex25 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex25.rs ├── ex10 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex10.rs ├── ex19 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2021ex19.rs │ └── src │ │ ├── point3d.rs │ │ └── lib.rs ├── ex22 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2021ex22.rs └── ex18 │ ├── Cargo.toml │ ├── src │ ├── permutator_gen.rs │ └── permutator.rs │ └── benches │ └── bench_y2021ex18.rs ├── y2023 ├── ex06 │ ├── input.txt │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex06.rs ├── ex16 │ ├── example_input.txt │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex16.rs │ └── src │ │ └── lib.rs ├── ex02 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex02.rs ├── ex01 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex01.rs ├── ex03 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex03.rs ├── ex11 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex11.rs ├── ex13 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex13.rs │ └── src │ │ └── lib.rs ├── ex14 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex14.rs │ └── src │ │ └── lib.rs ├── ex21 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex21.rs │ └── src │ │ └── models.rs ├── ex04 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex04.rs ├── ex05 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex05.rs ├── ex07 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex07.rs │ └── src │ │ └── lib.rs ├── ex09 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex09.rs │ └── src │ │ └── lib.rs ├── ex12 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex12.rs │ └── src │ │ └── lib.rs ├── ex15 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex15.rs │ └── src │ │ └── lib.rs ├── ex19 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2023ex19.rs ├── ex10 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2023ex10.rs │ └── src │ │ └── lib.rs └── ex08 │ ├── Cargo.toml │ └── benches │ └── bench_y2023ex08.rs ├── rpi-pico ├── rp2040-full │ ├── .vscode │ │ ├── settings.json │ │ ├── tasks.json │ │ └── launch.json │ ├── .gitignore │ ├── openocd.gdb │ ├── memory.x │ ├── input.txt │ ├── .cargo │ │ └── config.toml │ ├── build.rs │ ├── debug_probes.md │ └── Cargo.toml └── rp2040-minimal │ ├── Cargo.toml │ ├── src │ └── main.rs │ ├── link.x │ └── .cargo │ └── config.toml ├── y2022 ├── ex11 │ ├── src │ │ ├── monkey.rs │ │ ├── expr.rs │ │ └── lib.rs │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex11.rs │ ├── input_example.txt │ └── input.txt ├── ex02 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2022ex02.rs ├── ex03 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex03.rs │ └── src │ │ ├── by3.rs │ │ └── lib.rs ├── ex12 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex12.rs │ └── src │ │ └── lib.rs ├── ex04 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex04.rs │ └── src │ │ └── lib.rs ├── ex05 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2022ex05.rs ├── ex06 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2022ex06.rs ├── ex07 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex07.rs │ └── src │ │ └── lib.rs ├── ex08 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex08.rs │ └── src │ │ ├── cell_iter.rs │ │ └── map.rs ├── ex09 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2022ex09.rs ├── ex10 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex10.rs │ ├── src │ │ ├── parser.rs │ │ └── display.rs │ ├── input.txt │ └── sample_input.txt ├── ex13 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex13.rs │ └── src │ │ └── lib.rs ├── ex14 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex14.rs │ └── src │ │ └── lib.rs ├── ex25 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2022ex25.rs │ └── input.txt ├── ex01 │ ├── Cargo.toml │ └── benches │ │ └── bench_y2022ex01.rs └── ex15 │ ├── Cargo.toml │ └── benches │ └── bench_y2022ex15.rs ├── y2024 ├── ex02 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2024ex02.rs │ └── src │ │ └── lib.rs ├── ex01 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2024ex01.rs │ └── src │ │ └── lib.rs ├── ex03 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2024ex03.rs │ └── src │ │ └── lib.rs └── ex04 │ ├── Cargo.toml │ └── benches │ └── bench_y2024ex04.rs ├── y2025 ├── ex01 │ ├── Cargo.toml │ ├── benches │ │ └── bench_y2025ex01.rs │ └── src │ │ ├── parser.rs │ │ ├── dial.rs │ │ └── lib.rs └── ex02 │ ├── Cargo.toml │ ├── benches │ └── bench_y2025ex02.rs │ ├── input.txt │ └── src │ ├── parser.rs │ ├── lib.rs │ └── utils.rs ├── .editorconfig ├── .github └── workflows │ ├── rust.yml │ └── post_to_pr.yaml ├── .gitignore ├── tools ├── flamegraph_comment_template.py └── delta.py ├── LICENSE └── Cargo.toml /flamegraphs/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /y2020/ex15/input.txt: -------------------------------------------------------------------------------- 1 | 2,1,10,11,0,6 -------------------------------------------------------------------------------- /y2020/ex23/input.txt: -------------------------------------------------------------------------------- 1 | 284573961 -------------------------------------------------------------------------------- /y2020/ex25/input.txt: -------------------------------------------------------------------------------- 1 | 8421034 2 | 15993936 -------------------------------------------------------------------------------- /y2021/ex17/input.txt: -------------------------------------------------------------------------------- 1 | target area: x=81..129, y=-150..-108 -------------------------------------------------------------------------------- /y2021/ex21/input.txt: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 5 2 | Player 2 starting position: 9 -------------------------------------------------------------------------------- /y2020/ex07/part2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmammino/rust-advent/HEAD/y2020/ex07/part2.png -------------------------------------------------------------------------------- /y2023/ex06/input.txt: -------------------------------------------------------------------------------- 1 | Time: 60 80 86 76 2 | Distance: 601 1163 1559 1300 -------------------------------------------------------------------------------- /y2021/ex23/input.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###A#C#B#A### 4 | #D#D#B#C# 5 | ######### -------------------------------------------------------------------------------- /y2020/ex17/input.txt: -------------------------------------------------------------------------------- 1 | ##..#.#. 2 | #####.## 3 | #######. 4 | #..#..#. 5 | #.#...## 6 | ..#....# 7 | ....#..# 8 | ..##.#.. -------------------------------------------------------------------------------- /y2020/ex22/example.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 -------------------------------------------------------------------------------- /y2021/ex11/input.txt: -------------------------------------------------------------------------------- 1 | 2238518614 2 | 4552388553 3 | 2562121143 4 | 2666685337 5 | 7575518784 6 | 3572534871 7 | 8411718283 8 | 7742668385 9 | 1235133231 10 | 2546165345 -------------------------------------------------------------------------------- /y2021/ex23/src/command.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | pub(crate) enum Command { 3 | In { pos_hallway: usize, home_x: usize }, 4 | Out { home_x: usize, pos_hallway: usize }, 5 | } 6 | -------------------------------------------------------------------------------- /y2023/ex16/example_input.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /y2020/ex22/examples/part2.rs: -------------------------------------------------------------------------------- 1 | use ex22::part2; 2 | 3 | pub fn main() { 4 | let input = include_str!("../input.txt"); 5 | assert_eq!(part2(input), 33651); 6 | println!("Foo") 7 | } 8 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.cargo.target": "thumbv6m-none-eabi", 3 | "rust-analyzer.checkOnSave.allTargets": false, 4 | "editor.formatOnSave": true 5 | } -------------------------------------------------------------------------------- /y2020/ex13/input.txt: -------------------------------------------------------------------------------- 1 | 1000340 2 | 13,x,x,x,x,x,x,37,x,x,x,x,x,401,x,x,x,x,x,x,x,x,x,x,x,x,x,17,x,x,x,x,19,x,x,x,23,x,x,x,x,x,29,x,613,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41 -------------------------------------------------------------------------------- /y2023/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex02" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dev-dependencies] 7 | criterion = "0.5.1" 8 | 9 | [[bench]] 10 | name = "bench_y2023ex02" 11 | harness = false 12 | 13 | [dependencies] 14 | nom = "7.1.3" 15 | -------------------------------------------------------------------------------- /y2021/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex01" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | itertools = "0.10.1" 8 | 9 | [dev-dependencies] 10 | criterion = "0.3" 11 | 12 | [[bench]] 13 | name = "bench_y2021ex01" 14 | harness = false 15 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/.gitignore: -------------------------------------------------------------------------------- 1 | **/*.rs.bk 2 | .#* 3 | .gdb_history 4 | Cargo.lock 5 | target/ 6 | 7 | # editor files 8 | .vscode/* 9 | !.vscode/*.md 10 | !.vscode/*.svd 11 | !.vscode/launch.json 12 | !.vscode/tasks.json 13 | !.vscode/extensions.json 14 | !.vscode/settings.json -------------------------------------------------------------------------------- /y2020/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex01" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex03" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex05" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex06" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex08" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex09" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex10" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex11" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2020/ex12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex12" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /y2021/ex12/input.txt: -------------------------------------------------------------------------------- 1 | start-qs 2 | qs-jz 3 | start-lm 4 | qb-QV 5 | QV-dr 6 | QV-end 7 | ni-qb 8 | VH-jz 9 | qs-lm 10 | qb-end 11 | dr-fu 12 | jz-lm 13 | start-VH 14 | QV-jz 15 | VH-qs 16 | lm-dr 17 | dr-ni 18 | ni-jz 19 | lm-QV 20 | jz-dr 21 | ni-end 22 | VH-dr 23 | VH-ni 24 | qb-HE -------------------------------------------------------------------------------- /y2020/ex04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex04" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | regex = "1" -------------------------------------------------------------------------------- /y2020/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2020ex02" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | regex = "1" 11 | -------------------------------------------------------------------------------- /y2020/ex07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex07" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | regex = "1" 11 | lazy_static = "1.4.0" -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/openocd.gdb: -------------------------------------------------------------------------------- 1 | target extended-remote :3333 2 | 3 | set print asm-demangle on 4 | 5 | set backtrace limit 32 6 | 7 | # break DefaultHandler 8 | # break HardFault 9 | 10 | # break main 11 | 12 | # monitor arm semihosting enable 13 | 14 | load 15 | 16 | next 17 | next 18 | next 19 | step 20 | # stepi 21 | -------------------------------------------------------------------------------- /y2020/ex20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex20" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex20" 15 | harness = false -------------------------------------------------------------------------------- /y2020/ex21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex21" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex21" 15 | harness = false -------------------------------------------------------------------------------- /y2020/ex24/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex24" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex24" 15 | harness = false -------------------------------------------------------------------------------- /y2020/ex19/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex19" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex19" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2020/ex25/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex25" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex25" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2022/ex11/src/monkey.rs: -------------------------------------------------------------------------------- 1 | use std::collections::VecDeque; 2 | 3 | use crate::expr::Expr; 4 | 5 | #[derive(Debug, PartialEq)] 6 | pub(crate) struct Monkey { 7 | pub id: usize, 8 | pub items: VecDeque, 9 | pub operation: Expr, 10 | pub test_divisible_by: u64, 11 | pub if_true: u64, 12 | pub if_false: u64, 13 | } 14 | -------------------------------------------------------------------------------- /y2021/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex02" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex02" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex03" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex03" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex04" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex04" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex05" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex05" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex06" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex06" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex07" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex07" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex08" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex08" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex09" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex09" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex11" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex11" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex12" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex12" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex13" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "y2021bench_ex13" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex14" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex14" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex15" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex15" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex16" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex16" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex20" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex20" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex21" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex21" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex23/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex23" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex23" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex24/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex24" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex24" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2021/ex25/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex25" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2021ex25" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2022/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex02" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2022ex02" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2022/ex03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex03" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2022ex03" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2022/ex12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex12" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_y2022ex12" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2023/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex01" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.5.1" 12 | 13 | [[bench]] 14 | name = "bench_y2023ex01" 15 | harness = false 16 | -------------------------------------------------------------------------------- /y2023/ex03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex03" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex03" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2023/ex11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex11" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex11" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2023/ex13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex13" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex13" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2023/ex14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex14" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex14" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2023/ex16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex16" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex16" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2023/ex21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex21" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2023ex21" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2024/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2024ex02" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [[bench]] 11 | name = "bench_y2024ex02" 12 | harness = false 13 | 14 | [dev-dependencies] 15 | criterion = "0.5.1" 16 | -------------------------------------------------------------------------------- /y2020/ex23/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex23" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | itertools = "0.10.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex23" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2021/ex17/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex17" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | anyhow = "1.0.57" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2021ex17" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex04" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex04" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex05" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex05" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex06" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex06" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex07" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex07" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex08" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex08" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex09" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex09" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex10" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex10" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex11" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex11" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex13" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex13" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex14" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex14" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex25/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex25" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.1" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex25" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2023/ex04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex04" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex04" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex05" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex05" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex06" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex06" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex07" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex07" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex09" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex09" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex12" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex12" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex15" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex15" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2023/ex19/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex19" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex19" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2021/ex10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex10" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | thiserror = "1.0.30" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2021ex10" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2021/ex19/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex19" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dev-dependencies] 9 | criterion = "0.3" 10 | 11 | [[bench]] 12 | name = "bench_y2021ex19" 13 | harness = false 14 | 15 | [dependencies] 16 | generator = "0.7.1" 17 | -------------------------------------------------------------------------------- /y2021/ex22/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex22" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | itertools = "0.10.3" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2021ex22" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2022/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex01" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | itertools = "0.10.5" 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_y2022ex01" 16 | harness = false 17 | -------------------------------------------------------------------------------- /y2023/ex10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex10" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nannou = "0.18.1" 10 | 11 | [[bench]] 12 | name = "bench_y2023ex10" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2024/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2024ex01" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | winnow = "0.6.20" 10 | 11 | [[bench]] 12 | name = "bench_y2024ex01" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2024/ex03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2024ex03" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | winnow = "0.6.20" 10 | 11 | [[bench]] 12 | name = "bench_y2024ex03" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2024/ex04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2024ex04" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | winnow = "0.6.20" 10 | 11 | [[bench]] 12 | name = "bench_y2024ex04" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2025/ex01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2025ex01" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | winnow = "0.7.14" 10 | 11 | [[bench]] 12 | name = "bench_y2025ex01" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2025/ex02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2025ex02" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | winnow = "0.7.14" 10 | 11 | [[bench]] 12 | name = "bench_y2025ex02" 13 | harness = false 14 | 15 | [dev-dependencies] 16 | criterion = "0.5.1" 17 | -------------------------------------------------------------------------------- /y2020/ex22/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex22" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | 10 | [dev-dependencies] 11 | criterion = "0.3" 12 | 13 | [[bench]] 14 | name = "bench_ex22" 15 | harness = false 16 | 17 | [[example]] 18 | name="part2" 19 | -------------------------------------------------------------------------------- /y2020/ex13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex13" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex13" 16 | harness = false -------------------------------------------------------------------------------- /y2020/ex14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex14" 3 | version = "0.1.0" 4 | authors = ["Luciano "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex14" 16 | harness = false -------------------------------------------------------------------------------- /y2023/ex08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2023ex08" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | nom = "7.1.3" 10 | num = "0.4.1" 11 | 12 | [[bench]] 13 | name = "bench_y2023ex08" 14 | harness = false 15 | 16 | [dev-dependencies] 17 | criterion = "0.5.1" 18 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/memory.x: -------------------------------------------------------------------------------- 1 | MEMORY { 2 | BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 3 | FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 4 | RAM : ORIGIN = 0x20000000, LENGTH = 256K 5 | } 6 | 7 | EXTERN(BOOT2_FIRMWARE) 8 | 9 | SECTIONS { 10 | /* ### Boot loader */ 11 | .boot2 ORIGIN(BOOT2) : 12 | { 13 | KEEP(*(.boot2)); 14 | } > BOOT2 15 | } INSERT BEFORE .text; -------------------------------------------------------------------------------- /y2020/ex13/benches/bench_ex13.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex13::part2; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex13::part2", |b| b.iter(|| part2(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /y2020/ex14/benches/bench_ex14.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex14::part1; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex14::part1", |b| b.iter(|| part1(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /y2020/ex15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex15" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex15" 16 | harness = false -------------------------------------------------------------------------------- /y2020/ex16/benches/bench_ex16.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex16::part1; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex16::part1", |b| b.iter(|| part1(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /y2020/ex17/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex17" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex17" 16 | harness = false -------------------------------------------------------------------------------- /y2020/ex18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex18" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | 11 | [dev-dependencies] 12 | criterion = "0.3" 13 | 14 | [[bench]] 15 | name = "bench_ex18" 16 | harness = false -------------------------------------------------------------------------------- /y2020/ex25/benches/bench_ex25.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex25::part1; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex25::part1", |b| b.iter(|| part1(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /y2021/ex18/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2021ex18" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dev-dependencies] 9 | criterion = "0.3" 10 | 11 | [[bench]] 12 | name = "bench_y2021ex18" 13 | harness = false 14 | 15 | [dependencies] 16 | generator = "0.7.1" 17 | itertools = "0.10.3" 18 | -------------------------------------------------------------------------------- /y2022/ex15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "y2022ex15" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | lazy_static = "1.4.0" 10 | nom = "7.1.1" 11 | regex = "1.7.1" 12 | 13 | [dev-dependencies] 14 | criterion = "0.3" 15 | 16 | [[bench]] 17 | name = "bench_y2022ex15" 18 | harness = false 19 | -------------------------------------------------------------------------------- /y2022/ex25/benches/bench_y2022ex25.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex25::part1; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex25::part1", |b| b.iter(|| part1(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | 7 | 8 | # Unix-style newlines with a newline ending every file 9 | [*] 10 | end_of_line = lf 11 | insert_final_newline = true 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 4 15 | 16 | [*.{yml,yaml}] 17 | indent_size = 2 18 | 19 | [*.txt] 20 | insert_final_newline = false 21 | -------------------------------------------------------------------------------- /y2021/ex25/benches/bench_y2021ex25.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex25::{part1}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex25::part1", |b| b.iter(|| part1(black_box(input)))); 7 | } 8 | 9 | criterion_group!(benches, criterion_benchmark); 10 | criterion_main!(benches); 11 | -------------------------------------------------------------------------------- /y2020/ex22/input.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 4 3 | 25 4 | 3 5 | 11 6 | 2 7 | 29 8 | 41 9 | 23 10 | 30 11 | 21 12 | 50 13 | 8 14 | 1 15 | 24 16 | 27 17 | 10 18 | 42 19 | 43 20 | 38 21 | 15 22 | 18 23 | 13 24 | 32 25 | 37 26 | 34 27 | 28 | Player 2: 29 | 12 30 | 6 31 | 36 32 | 35 33 | 40 34 | 47 35 | 31 36 | 9 37 | 46 38 | 49 39 | 19 40 | 16 41 | 5 42 | 26 43 | 39 44 | 48 45 | 7 46 | 44 47 | 45 48 | 20 49 | 17 50 | 14 51 | 33 52 | 28 53 | 22 54 | -------------------------------------------------------------------------------- /y2020/ex16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ex16" 3 | version = "0.1.0" 4 | authors = ["Luciano Mammino "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | regex = "1" 11 | lazy_static = "1.4.0" 12 | 13 | [dev-dependencies] 14 | criterion = "0.3" 15 | 16 | [[bench]] 17 | name = "bench_ex16" 18 | harness = false -------------------------------------------------------------------------------- /rpi-pico/rp2040-minimal/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rp2040-minimal" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | cortex-m = "0.7.3" 10 | y2021ex06 = { path = "../../y2021/ex06" } 11 | 12 | [profile.dev] 13 | panic = "abort" 14 | 15 | [profile.release] 16 | panic = "abort" 17 | 18 | [[bin]] 19 | name = "rp2040-minimal" 20 | path = "src/main.rs" 21 | -------------------------------------------------------------------------------- /y2020/ex17/benches/bench_ex17.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex17::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex17::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex17::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex18/benches/bench_ex18.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex18::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex18::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex18::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex19/benches/bench_ex19.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex19::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex19::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex19::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex20/benches/bench_ex20.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex20::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex20::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex20::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex21/benches/bench_ex21.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex21::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex21::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex21::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex22/benches/bench_ex22.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex22::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex22::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex22::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex23/benches/bench_ex23.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex23::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex23::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex23::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex24/benches/bench_ex24.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex24::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("ex24::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("ex24::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2020/ex15/benches/bench_ex15.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use ex15::part1; 3 | use ex15::part2; 4 | 5 | fn criterion_benchmark(c: &mut Criterion) { 6 | let input = include_str!("../input.txt"); 7 | c.bench_function("ex15::part1", |b| b.iter(|| part1(black_box(input)))); 8 | c.bench_function("ex15::part2", |b| b.iter(|| part2(black_box(input)))); 9 | } 10 | 11 | criterion_group!(benches, criterion_benchmark); 12 | criterion_main!(benches); 13 | -------------------------------------------------------------------------------- /y2021/ex02/benches/bench_y2021ex02.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex02::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex02::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex02::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex04/benches/bench_y2021ex04.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex04::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex04::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex04::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex05/benches/bench_y2021ex05.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex05::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex05::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex05::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex06/benches/bench_y2021ex06.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex06::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex06::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex06::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex08/benches/bench_y2021ex08.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex08::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex08::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex08::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex09/benches/bench_y2021ex09.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex09::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex09::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex09::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex10/benches/bench_y2021ex10.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex10::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex10::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex10::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex11/benches/bench_y2021ex11.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex11::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex11::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex11::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex12/benches/bench_y2021ex12.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex12::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex12::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex12::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex13/benches/y2021bench_ex13.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex13::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex13::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex13::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex14/benches/bench_y2021ex14.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex14::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex14::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex14::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex15/benches/bench_y2021ex15.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex15::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex15::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex15::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex16/benches/bench_y2021ex16.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex16::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex16::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex16::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex17/benches/bench_y2021ex17.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex17::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex17::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex17::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex19/benches/bench_y2021ex19.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex19::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex19::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex19::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex20/benches/bench_y2021ex20.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex20::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex20::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex20::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex21/benches/bench_y2021ex21.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex21::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex21::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex21::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex22/benches/bench_y2021ex22.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex22::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex22::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex22::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex23/benches/bench_y2021ex23.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex23::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex23::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex23::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2021/ex24/benches/bench_y2021ex24.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex24::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex24::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex24::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex02/benches/bench_y2022ex02.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex02::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex02::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex02::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex03/benches/bench_y2022ex03.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex03::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex03::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex03::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex04/benches/bench_y2022ex04.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex04::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex04::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex04::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex05/benches/bench_y2022ex05.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex05::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex05::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex05::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex06/benches/bench_y2022ex06.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex06::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex06::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex06::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex07/benches/bench_y2022ex07.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex07::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex07::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex07::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex08/benches/bench_y2022ex08.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex08::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex08::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex08::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex09/benches/bench_y2022ex09.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex09::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex09::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex09::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex10/benches/bench_y2022ex10.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex10::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex10::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex10::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex11/benches/bench_y2022ex11.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex11::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex11::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex11::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex12/benches/bench_y2022ex12.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex12::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex12::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex12::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex13/benches/bench_y2022ex13.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex13::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex13::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex13::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2022/ex14/benches/bench_y2022ex14.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex14::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2022ex14::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2022ex14::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex01/benches/bench_y2023ex01.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex01::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex01::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex01::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex02/benches/bench_y2023ex02.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex02::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex02::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex02::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex03/benches/bench_y2023ex03.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex03::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex03::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex03::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex04/benches/bench_y2023ex04.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex04::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex04::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex04::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex05/benches/bench_y2023ex05.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex05::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex05::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex05::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex06/benches/bench_y2023ex06.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex06::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex06::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex06::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex07/benches/bench_y2023ex07.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex07::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex07::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex07::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex08/benches/bench_y2023ex08.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex08::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex08::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex08::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex09/benches/bench_y2023ex09.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex09::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex09::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex09::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex10/benches/bench_y2023ex10.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex10::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex10::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex10::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex11/benches/bench_y2023ex11.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex11::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex11::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex11::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex12/benches/bench_y2023ex12.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex12::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex12::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex12::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex13/benches/bench_y2023ex13.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex13::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex13::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex13::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex14/benches/bench_y2023ex14.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex14::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex14::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex14::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex15/benches/bench_y2023ex15.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex15::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex15::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex15::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex16/benches/bench_y2023ex16.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex16::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex16::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex16::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex19/benches/bench_y2023ex19.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex19::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex19::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex19::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2023/ex21/benches/bench_y2023ex21.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2023ex21::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2023ex21::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2023ex21::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2024/ex01/benches/bench_y2024ex01.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2024ex01::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2024ex01::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2024ex01::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2024/ex02/benches/bench_y2024ex02.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2024ex02::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2024ex02::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2024ex02::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2024/ex03/benches/bench_y2024ex03.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2024ex03::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2024ex03::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2024ex03::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2024/ex04/benches/bench_y2024ex04.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2024ex04::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2024ex04::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2024ex04::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /y2025/ex02/benches/bench_y2025ex02.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2025ex02::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2025ex02::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2025ex02::part2", |b| b.iter(|| part2(black_box(input)))); 8 | } 9 | 10 | criterion_group!(benches, criterion_benchmark); 11 | criterion_main!(benches); 12 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'flamegraphs/**' 7 | pull_request: 8 | branches: [ main ] 9 | paths-ignore: 10 | - 'flamegraphs/**' 11 | 12 | env: 13 | CARGO_TERM_COLOR: always 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Build 23 | run: cargo build --verbose 24 | - name: Run tests 25 | run: cargo test --verbose 26 | -------------------------------------------------------------------------------- /y2025/ex01/benches/bench_y2025ex01.rs: -------------------------------------------------------------------------------- 1 | 2 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 3 | use y2025ex01::{part1, part2}; 4 | 5 | fn criterion_benchmark(c: &mut Criterion) { 6 | let input = include_str!("../input.txt"); 7 | c.bench_function("y2025ex01::part1", |b| b.iter(|| part1(black_box(input)))); 8 | c.bench_function("y2025ex01::part2", |b| b.iter(|| part2(black_box(input)))); 9 | } 10 | 11 | criterion_group!(benches, criterion_benchmark); 12 | criterion_main!(benches); 13 | -------------------------------------------------------------------------------- /y2025/ex02/input.txt: -------------------------------------------------------------------------------- 1 | 16100064-16192119,2117697596-2117933551,1-21,9999936269-10000072423,1770-2452,389429-427594,46633-66991,877764826-877930156,880869-991984,18943-26512,7216-9427,825-1162,581490-647864,2736-3909,39327886-39455605,430759-454012,1178-1741,219779-244138,77641-97923,1975994465-1976192503,3486612-3602532,277-378,418-690,74704280-74781349,3915-5717,665312-740273,69386294-69487574,2176846-2268755,26-45,372340114-372408052,7996502103-7996658803,7762107-7787125,48-64,4432420-4462711,130854-178173,87-115,244511-360206,69-86 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | # Perf files 13 | **/*.data 14 | **/*.data.old 15 | **/*.svg 16 | .DS_Store 17 | 18 | /rpi-pico/rp2040-minimal/target 19 | /rpi-pico/rp2040-full/target 20 | -------------------------------------------------------------------------------- /y2020/ex07/example.txt: -------------------------------------------------------------------------------- 1 | light red bags contain 1 bright white bag, 2 muted yellow bags. 2 | dark orange bags contain 3 bright white bags, 4 muted yellow bags. 3 | bright white bags contain 1 shiny gold bag. 4 | muted yellow bags contain 2 shiny gold bags, 9 faded blue bags. 5 | shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags. 6 | dark olive bags contain 3 faded blue bags, 4 dotted black bags. 7 | vibrant plum bags contain 5 faded blue bags, 6 dotted black bags. 8 | faded blue bags contain no other bags. 9 | dotted black bags contain no other bags. -------------------------------------------------------------------------------- /y2021/ex16/NOTES.md: -------------------------------------------------------------------------------- 1 | `C0015000016115A2E0802F182340` 2 | 3 | 4 | ```plain 5 | 110 000 0 000000001010100 000000000000000001011000010001010110100010111000001000000000101111000110000010001101000000 6 | 7 0 0 84 000 000 0 000000000010110 0001000101011010001011 100 000 1 00000000010 1111000110000010001101 7 | 22 0001000101011010001011 4 0 1 2 1111000110000010001101 8 | 0 4---10 6 4---11 7 4---12 0 4---13 9 | ``` 10 | -------------------------------------------------------------------------------- /y2021/ex03/benches/bench_y2021ex03.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex03::{part1, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex03::part1", |b| { 7 | b.iter(|| part1::<12>(black_box(input))) 8 | }); 9 | c.bench_function("y2021ex03::part2", |b| { 10 | b.iter(|| part2::<12>(black_box(input))) 11 | }); 12 | } 13 | 14 | criterion_group!(benches, criterion_benchmark); 15 | criterion_main!(benches); 16 | -------------------------------------------------------------------------------- /y2021/ex18/src/permutator_gen.rs: -------------------------------------------------------------------------------- 1 | use generator::*; 2 | 3 | pub fn permutations(elements: &[T]) -> Generator<'_, (), (&T, &T)> 4 | where 5 | T: Send + Sync, 6 | { 7 | Gn::new_scoped(move |mut s| { 8 | for i in 0..elements.len() { 9 | for j in 0..elements.len() { 10 | if i != j { 11 | let el1 = elements.get(i).unwrap(); 12 | let el2 = elements.get(j).unwrap(); 13 | s.yield_with((el1, el2)); 14 | } 15 | } 16 | } 17 | done!(); 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /y2021/ex06/input.txt: -------------------------------------------------------------------------------- 1 | 4,1,4,1,3,3,1,4,3,3,2,1,1,3,5,1,3,5,2,5,1,5,5,1,3,2,5,3,1,3,4,2,3,2,3,3,2,1,5,4,1,1,1,2,1,4,4,4,2,1,2,1,5,1,5,1,2,1,4,4,5,3,3,4,1,4,4,2,1,4,4,3,5,2,5,4,1,5,1,1,1,4,5,3,4,3,4,2,2,2,2,4,5,3,5,2,4,2,3,4,1,4,4,1,4,5,3,4,2,2,2,4,3,3,3,3,4,2,1,2,5,5,3,2,3,5,5,5,4,4,5,5,4,3,4,1,5,1,3,4,4,1,3,1,3,1,1,2,4,5,3,1,2,4,3,3,5,4,4,5,4,1,3,1,1,4,4,4,4,3,4,3,1,4,5,1,2,4,3,5,1,1,2,1,1,5,4,2,1,5,4,5,2,4,4,1,5,2,2,5,3,3,2,3,1,5,5,5,4,3,1,1,5,1,4,5,2,1,3,1,2,4,4,1,1,2,5,3,1,5,2,4,5,1,2,3,1,2,2,1,2,2,1,4,1,3,4,2,1,1,5,4,1,5,4,4,3,1,3,3,1,1,3,3,4,2,3,4,2,3,1,4,1,5,3,1,1,5,3,2,3,5,1,3,1,1,3,5,1,5,1,1,3,1,1,1,1,3,3,1 -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/input.txt: -------------------------------------------------------------------------------- 1 | 4,1,4,1,3,3,1,4,3,3,2,1,1,3,5,1,3,5,2,5,1,5,5,1,3,2,5,3,1,3,4,2,3,2,3,3,2,1,5,4,1,1,1,2,1,4,4,4,2,1,2,1,5,1,5,1,2,1,4,4,5,3,3,4,1,4,4,2,1,4,4,3,5,2,5,4,1,5,1,1,1,4,5,3,4,3,4,2,2,2,2,4,5,3,5,2,4,2,3,4,1,4,4,1,4,5,3,4,2,2,2,4,3,3,3,3,4,2,1,2,5,5,3,2,3,5,5,5,4,4,5,5,4,3,4,1,5,1,3,4,4,1,3,1,3,1,1,2,4,5,3,1,2,4,3,3,5,4,4,5,4,1,3,1,1,4,4,4,4,3,4,3,1,4,5,1,2,4,3,5,1,1,2,1,1,5,4,2,1,5,4,5,2,4,4,1,5,2,2,5,3,3,2,3,1,5,5,5,4,3,1,1,5,1,4,5,2,1,3,1,2,4,4,1,1,2,5,3,1,5,2,4,5,1,2,3,1,2,2,1,2,2,1,4,1,3,4,2,1,1,5,4,1,5,4,4,3,1,3,3,1,1,3,3,4,2,3,4,2,3,1,4,1,5,3,1,1,5,3,2,3,5,1,3,1,1,3,5,1,5,1,1,3,1,1,1,1,3,3,1 -------------------------------------------------------------------------------- /y2022/ex03/src/by3.rs: -------------------------------------------------------------------------------- 1 | pub struct By3Iter(I); 2 | 3 | impl By3Iter { 4 | pub fn new(inner: I) -> Self { 5 | By3Iter(inner) 6 | } 7 | } 8 | 9 | impl Iterator for By3Iter { 10 | type Item = (I::Item, I::Item, I::Item); 11 | 12 | fn next(&mut self) -> Option { 13 | let i1 = self.0.next(); 14 | let i2 = self.0.next(); 15 | let i3 = self.0.next(); 16 | 17 | match (i1, i2, i3) { 18 | (Some(i1), Some(i2), Some(i3)) => Some((i1, i2, i3)), 19 | _ => None, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /y2021/ex07/benches/bench_y2021ex07.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex07::{part1, part1_select_nth, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex07::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex07::part1_select_nth", |b| { 8 | b.iter(|| part1_select_nth(black_box(input))) 9 | }); 10 | c.bench_function("y2021ex07::part2", |b| b.iter(|| part2(black_box(input)))); 11 | } 12 | criterion_group!(benches, criterion_benchmark); 13 | criterion_main!(benches); 14 | -------------------------------------------------------------------------------- /y2022/ex11/input_example.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 -------------------------------------------------------------------------------- /y2020/ex10/input.txt: -------------------------------------------------------------------------------- 1 | 97 2 | 62 3 | 23 4 | 32 5 | 51 6 | 19 7 | 98 8 | 26 9 | 90 10 | 134 11 | 73 12 | 151 13 | 116 14 | 76 15 | 6 16 | 94 17 | 113 18 | 127 19 | 119 20 | 44 21 | 115 22 | 50 23 | 143 24 | 150 25 | 86 26 | 91 27 | 36 28 | 104 29 | 131 30 | 101 31 | 38 32 | 66 33 | 46 34 | 96 35 | 54 36 | 70 37 | 8 38 | 30 39 | 1 40 | 108 41 | 69 42 | 139 43 | 24 44 | 29 45 | 77 46 | 124 47 | 107 48 | 14 49 | 137 50 | 16 51 | 140 52 | 80 53 | 68 54 | 25 55 | 31 56 | 59 57 | 45 58 | 126 59 | 148 60 | 67 61 | 13 62 | 125 63 | 53 64 | 57 65 | 41 66 | 47 67 | 35 68 | 145 69 | 120 70 | 12 71 | 37 72 | 5 73 | 110 74 | 138 75 | 130 76 | 2 77 | 63 78 | 83 79 | 22 80 | 79 81 | 52 82 | 7 83 | 95 84 | 58 85 | 149 86 | 123 87 | 89 88 | 109 89 | 15 90 | 144 91 | 114 92 | 9 93 | 78 -------------------------------------------------------------------------------- /tools/flamegraph_comment_template.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | import sys 3 | 4 | github_repository = sys.argv[1] 5 | hash = sys.argv[2] 6 | 7 | for filename in sys.argv[3:]: 8 | summary = os.path.basename(filename) 9 | summary = summary[: summary.rfind(".")] 10 | print( 11 | f""" 12 |
13 | { summary } 14 |

15 | 17 | 19 | 20 |

21 |
""" 22 | ) 23 | -------------------------------------------------------------------------------- /y2023/ex10/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::{find_loop, get_enclosed, Map}; 2 | mod models; 3 | 4 | pub fn part1(input: &str) -> usize { 5 | let map: Map<140, 140> = input.parse().unwrap(); 6 | let path = find_loop(&map).unwrap(); 7 | path.len() / 2 8 | } 9 | 10 | pub fn part2(input: &str) -> usize { 11 | let map: Map<140, 140> = input.parse().unwrap(); 12 | let enclosed = get_enclosed(&map); 13 | enclosed.len() 14 | } 15 | 16 | #[cfg(test)] 17 | mod tests { 18 | use super::*; 19 | const INPUT: &str = include_str!("../input.txt"); 20 | 21 | #[test] 22 | fn test_part1() { 23 | assert_eq!(part1(INPUT), 6697); 24 | } 25 | 26 | #[test] 27 | fn test_part2() { 28 | assert_eq!(part2(INPUT), 423); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /y2021/ex01/benches/bench_y2021ex01.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex01::{part1, part1_iter, part1_zip, part2}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex01::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex01::part1_iter", |b| { 8 | b.iter(|| part1_iter(black_box(input))) 9 | }); 10 | c.bench_function("y2021ex01::part1_zip", |b| { 11 | b.iter(|| part1_zip(black_box(input))) 12 | }); 13 | c.bench_function("y2021ex01::part2", |b| b.iter(|| part2(black_box(input)))); 14 | } 15 | 16 | criterion_group!(benches, criterion_benchmark); 17 | criterion_main!(benches); 18 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-minimal/src/main.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | #![no_std] 3 | 4 | use core::panic::PanicInfo; 5 | 6 | // The reset handler 7 | /// # Safety 8 | /// this is low level unsafe pico code 9 | #[no_mangle] 10 | #[inline(always)] 11 | pub unsafe extern "C" fn Reset() -> ! { 12 | let _x = 42; 13 | 14 | // can't return so we go into an infinite loop here 15 | loop { 16 | let res = y2021ex06::part1("3,4,3,1,2"); 17 | assert_eq!(5934, res); 18 | cortex_m::asm::nop(); 19 | } 20 | } 21 | 22 | // The reset vector, a pointer into the reset handler 23 | #[link_section = ".vector_table.reset_vector"] 24 | #[no_mangle] 25 | pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset; 26 | 27 | #[panic_handler] 28 | fn panic(_panic: &PanicInfo<'_>) -> ! { 29 | loop {} 30 | } 31 | 32 | // #[lang = "eh_personality"] 33 | // extern "C" fn eh_personality() {} 34 | -------------------------------------------------------------------------------- /y2022/ex10/src/parser.rs: -------------------------------------------------------------------------------- 1 | use nom::{ 2 | branch::alt, 3 | bytes::complete::tag, 4 | character::complete::digit1, 5 | combinator::{map_res, opt}, 6 | IResult, 7 | }; 8 | 9 | use crate::program::Cmd; 10 | 11 | pub(crate) fn parse_line(input: &str) -> IResult<&str, Cmd> { 12 | let (input, cmd) = alt((parse_noop, parse_addx))(input)?; 13 | Ok((input, cmd)) 14 | } 15 | 16 | fn parse_noop(input: &str) -> IResult<&str, Cmd> { 17 | let (input, _) = tag("noop")(input)?; 18 | Ok((input, Cmd::Noop)) 19 | } 20 | 21 | fn parse_addx(input: &str) -> IResult<&str, Cmd> { 22 | let (input, _) = tag("addx ")(input)?; 23 | let (input, sign) = opt(tag("-"))(input)?; 24 | let sign = sign.map(|_| -1).unwrap_or(1); 25 | let (input, unsigned_value) = map_res(digit1, |s: &str| s.parse::())(input)?; 26 | Ok((input, Cmd::AddX(unsigned_value * sign))) 27 | } 28 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-minimal/link.x: -------------------------------------------------------------------------------- 1 | MEMORY { 2 | FLASH : ORIGIN = 0x10000000, LENGTH = 2048K 3 | RAM : ORIGIN = 0x20000000, LENGTH = 256K 4 | } 5 | 6 | /* The entry point is the reset handler */ 7 | ENTRY(Reset); 8 | 9 | EXTERN(RESET_VECTOR); 10 | 11 | SECTIONS 12 | { 13 | .vector_table ORIGIN(FLASH) : 14 | { 15 | /* First entry: initial Stack Pointer value */ 16 | LONG(ORIGIN(RAM) + LENGTH(RAM)); 17 | 18 | /* Second entry: reset vector */ 19 | KEEP(*(.vector_table.reset_vector)); 20 | } > FLASH 21 | 22 | .text : 23 | { 24 | *(.text .text.*); 25 | } > FLASH 26 | 27 | .rodata : 28 | { 29 | *(.rodata .rodata.*); 30 | } > FLASH 31 | 32 | .bss : 33 | { 34 | *(.bss .bss.*); 35 | } > RAM 36 | 37 | .data : 38 | { 39 | *(.data .data.*); 40 | } > RAM 41 | 42 | /DISCARD/ : 43 | { 44 | *(.ARM.exidx .ARM.exidx.*); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Cargo build", 6 | "type": "shell", 7 | "command": "cargo", 8 | "args": [ 9 | "build" 10 | ], 11 | "problemMatcher": [ 12 | "$rustc" 13 | ], 14 | "group": "build" 15 | }, 16 | { 17 | "label": "Build binary", 18 | "dependsOn": "Cargo build", 19 | "type": "shell", 20 | "command": "arm-none-eabi-objcopy", 21 | "args": [ 22 | "--output-target", 23 | "binary", 24 | "./target/thumbv6m-none-eabi/debug/rp2040-project-template", 25 | "./target/thumbv6m-none-eabi/debug/rp2040-project-template.bin" 26 | ], 27 | "problemMatcher": [ 28 | "$rustc" 29 | ], 30 | "group": { 31 | "kind": "build", 32 | "isDefault": true 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | # Choose a default "cargo run" tool. 2 | # probe-run is recommended if you have a debugger 3 | # elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode 4 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] 5 | # runner = "probe-run --chip RP2040" 6 | # runner = "elf2uf2-rs -d" 7 | runner = "gdb-multiarch -q -x openocd.gdb" 8 | 9 | rustflags = [ 10 | "-C", "linker=flip-link", 11 | "-C", "link-arg=--nmagic", 12 | "-C", "link-arg=-Tlink.x", 13 | "-C", "link-arg=-Tdefmt.x", 14 | 15 | # Code-size optimizations. 16 | # trap unreachable can save a lot of space, but requires nightly compiler. 17 | # uncomment the next line if you wish to enable it 18 | # "-Z", "trap-unreachable=no", 19 | "-C", "inline-threshold=5", 20 | "-C", "no-vectorize-loops", 21 | ] 22 | 23 | [build] 24 | target = "thumbv6m-none-eabi" 25 | 26 | [env] 27 | DEFMT_LOG = "debug" 28 | -------------------------------------------------------------------------------- /y2022/ex12/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod map; 2 | use map::*; 3 | 4 | pub fn part1(input: &str) -> usize { 5 | let map: Map<144, 41> = input.parse().unwrap(); 6 | let paths_from_start = map.find_paths(&map.start, false); 7 | let end_edge = paths_from_start[&map.end]; 8 | end_edge.0 9 | } 10 | 11 | pub fn part2(input: &str) -> usize { 12 | let map: Map<144, 41> = input.parse().unwrap(); 13 | let walkable_paths = map.find_paths(&map.end, true); 14 | 15 | map.scenic_points 16 | .iter() 17 | .filter_map(|&p| walkable_paths.get(&p).map(|(dist, _)| *dist)) 18 | .min() 19 | .unwrap() 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests { 24 | use super::*; 25 | const INPUT: &str = include_str!("../input.txt"); 26 | 27 | #[test] 28 | fn test_part1() { 29 | assert_eq!(part1(INPUT), 423); 30 | } 31 | 32 | #[test] 33 | fn test_part2() { 34 | assert_eq!(part2(INPUT), 416); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /y2021/ex18/benches/bench_y2021ex18.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2021ex18::{part1, part2, part2_itertools, part2_permutator, part2_permutator_gen}; 3 | 4 | fn criterion_benchmark(c: &mut Criterion) { 5 | let input = include_str!("../input.txt"); 6 | c.bench_function("y2021ex18::part1", |b| b.iter(|| part1(black_box(input)))); 7 | c.bench_function("y2021ex18::part2", |b| b.iter(|| part2(black_box(input)))); 8 | c.bench_function("y2021ex18::part2_permutator", |b| { 9 | b.iter(|| part2_permutator(black_box(input))) 10 | }); 11 | c.bench_function("y2021ex18::part2_permutator_gen", |b| { 12 | b.iter(|| part2_permutator_gen(black_box(input))) 13 | }); 14 | c.bench_function("y2021ex18::part2_itertools", |b| { 15 | b.iter(|| part2_itertools(black_box(input))) 16 | }); 17 | } 18 | 19 | criterion_group!(benches, criterion_benchmark); 20 | criterion_main!(benches); 21 | -------------------------------------------------------------------------------- /y2020/ex20/src/tiles_index.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, convert::TryInto, str::FromStr}; 2 | 3 | use crate::tile::Tile; 4 | 5 | pub struct TilesIndex(pub HashMap>); 6 | 7 | impl FromStr for TilesIndex { 8 | type Err = (); 9 | 10 | fn from_str(s: &str) -> Result { 11 | let mut tiles: HashMap> = HashMap::new(); 12 | 13 | for raw_tile in s.split("\n\n").take_while(|t| !t.is_empty()) { 14 | let mut lines = raw_tile.lines(); 15 | let raw_id = lines.next().unwrap(); 16 | let id: u16 = raw_id[5..9].parse().unwrap(); 17 | let cells: [[char; N]; N] = lines 18 | .map(|l| l.chars().collect::>().try_into().unwrap()) 19 | .collect::>() 20 | .try_into() 21 | .unwrap(); 22 | 23 | let tile = Tile::new(id, cells); 24 | tiles.insert(id, tile); 25 | } 26 | 27 | Ok(Self(tiles)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tools/delta.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | first = open(sys.argv[1]) 4 | second = open(sys.argv[2]) 5 | 6 | data = {} 7 | delta = {} 8 | k = None 9 | 10 | for line in second: 11 | if line.startswith("##"): 12 | k = line[2 : line.rfind("-")] 13 | elif line.startswith("=="): 14 | _, _, _, counter = line.split() 15 | counter = int(counter.replace(",", "")) 16 | data[k] = counter 17 | 18 | for line in first: 19 | if line.startswith("##"): 20 | k = line[2 : line.rfind("-")] 21 | elif line.startswith("==") and k in data: 22 | _, _, _, counter = line.split() 23 | counter = int(counter.replace(",", "")) 24 | delta[k] = (data[k] - counter) * 100 / counter 25 | 26 | print( 27 | """## Valgrind Benchmarks 28 | 29 |
30 | Negative deltas means faster code 31 |
                      
32 | """
33 | )
34 | for k in data:
35 |     if k in delta:
36 |         print("{} {} ({} %)\n".format(k, data[k], "{:+.02f}".format(delta[k])))
37 | print("
") 38 | -------------------------------------------------------------------------------- /y2025/ex01/src/parser.rs: -------------------------------------------------------------------------------- 1 | use winnow::ascii::digit1; 2 | use winnow::combinator::alt; 3 | use winnow::prelude::*; 4 | use winnow::Result; 5 | 6 | #[derive(Debug, PartialEq, Eq)] 7 | pub(crate) enum DialOp { 8 | TurnLeft(u16), 9 | TurnRight(u16), 10 | } 11 | 12 | pub(crate) fn parse_dial_op(input: &mut &str) -> Result { 13 | let dir = alt(('L', 'R')).parse_next(input)?; 14 | let steps = digit1.try_map(str::parse::).parse_next(input)?; 15 | let op = match dir { 16 | 'L' => DialOp::TurnLeft(steps), 17 | 'R' => DialOp::TurnRight(steps), 18 | _ => unreachable!(), 19 | }; 20 | Ok(op) 21 | } 22 | 23 | #[cfg(test)] 24 | mod tests { 25 | use super::*; 26 | 27 | #[test] 28 | fn test_parse_dial_op() { 29 | let mut input = "L30"; 30 | let op = parse_dial_op(&mut input).unwrap(); 31 | assert_eq!(op, DialOp::TurnLeft(30)); 32 | let mut input = "R70"; 33 | let op = parse_dial_op(&mut input).unwrap(); 34 | assert_eq!(op, DialOp::TurnRight(70)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /y2025/ex02/src/parser.rs: -------------------------------------------------------------------------------- 1 | use std::ops::RangeInclusive; 2 | use winnow::combinator::separated; 3 | use winnow::Result; 4 | use winnow::{ascii::digit1, Parser}; 5 | 6 | fn parse_range(input: &mut &str) -> Result> { 7 | let start = digit1.try_map(str::parse).parse_next(input)?; 8 | let _ = '-'.parse_next(input)?; 9 | let end = digit1.try_map(str::parse).parse_next(input)?; 10 | Ok(RangeInclusive::new(start, end)) 11 | } 12 | 13 | pub(crate) fn parse_input(input: &mut &str) -> Result>> { 14 | separated(1.., parse_range, ",").parse_next(input) 15 | } 16 | 17 | #[cfg(test)] 18 | mod tests { 19 | use super::*; 20 | 21 | #[test] 22 | fn test_parse_range() { 23 | let mut input = "5-10"; 24 | let range = parse_range(&mut input).unwrap(); 25 | assert_eq!(range, 5..=10); 26 | } 27 | 28 | #[test] 29 | fn test_parse_input() { 30 | let mut input = "5-10,15-20,25-30"; 31 | let ranges = parse_input(&mut input).unwrap(); 32 | assert_eq!(ranges, vec![5..=10, 15..=20, 25..=30]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /y2021/ex23/src/amphipod.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Clone, Copy, PartialEq, Hash, Eq)] 2 | pub(crate) enum Amphipod { 3 | A, 4 | B, 5 | C, 6 | D, 7 | } 8 | 9 | impl Amphipod { 10 | pub(crate) fn move_cost(&self) -> usize { 11 | match self { 12 | Amphipod::A => 1, 13 | Amphipod::B => 10, 14 | Amphipod::C => 100, 15 | Amphipod::D => 1000, 16 | } 17 | } 18 | 19 | pub(crate) fn desired_home_idx(&self) -> usize { 20 | match self { 21 | Amphipod::A => 0, 22 | Amphipod::B => 1, 23 | Amphipod::C => 2, 24 | Amphipod::D => 3, 25 | } 26 | } 27 | 28 | pub(crate) fn all() -> [Amphipod; 4] { 29 | [Amphipod::A, Amphipod::B, Amphipod::C, Amphipod::D] 30 | } 31 | } 32 | 33 | impl From for Amphipod { 34 | fn from(c: char) -> Self { 35 | match c { 36 | 'A' => Amphipod::A, 37 | 'B' => Amphipod::B, 38 | 'C' => Amphipod::C, 39 | 'D' => Amphipod::D, 40 | _ => panic!("Invalid amphipod: {c}"), 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-minimal/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [unstable] 2 | build-std = ["core"] 3 | build-std-features = ["panic_immediate_abort"] 4 | 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] 6 | 7 | rustflags = [ 8 | # "-C", "link-arg=--nmagic", 9 | "-C", "link-arg=-Tlink.x", 10 | 11 | # Code-size optimizations. 12 | # "-Z", "trap-unreachable=no", 13 | # "-C", "inline-threshold=5", 14 | # "-C", "no-vectorize-loops", 15 | # "-C", "force-frame-pointers=no", 16 | 17 | # We don't know where the flash loader will be 18 | # placed in memory, so we need to create 19 | # position independent code (pic). 20 | # "-C", "relocation-model=pic", 21 | ] 22 | 23 | [build] 24 | target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ 25 | # target = "thumbv7m-none-eabi" # Cortex-M3 26 | # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) 27 | # target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) 28 | # target = "thumbv8m.base-none-eabi" # Cortex-M23 29 | # target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU) 30 | # target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) -------------------------------------------------------------------------------- /y2021/ex23/src/hole.rs: -------------------------------------------------------------------------------- 1 | use crate::amphipod::Amphipod; 2 | 3 | #[derive(Debug, Clone, PartialEq, Hash, Eq)] 4 | pub(crate) struct Hole { 5 | amphipods: [Option; DEPTH], 6 | size: usize, 7 | } 8 | 9 | impl Hole { 10 | pub(crate) fn new() -> Self { 11 | Hole { 12 | amphipods: [None; DEPTH], 13 | size: 0, 14 | } 15 | } 16 | 17 | pub(crate) fn push(&mut self, amphipod: Amphipod) { 18 | self.amphipods[self.size] = Some(amphipod); 19 | self.size += 1; 20 | } 21 | 22 | pub(crate) fn pop(&mut self) -> Option { 23 | if self.size == 0 { 24 | return None; 25 | } 26 | 27 | self.size -= 1; 28 | self.amphipods[self.size].take() 29 | } 30 | 31 | pub(crate) fn is_empty(&self) -> bool { 32 | self.size == 0 33 | } 34 | 35 | pub(crate) fn iter_filled(&self) -> impl Iterator + '_ { 36 | self.amphipods.iter().filter_map(|a| *a) 37 | } 38 | 39 | pub(crate) fn len(&self) -> usize { 40 | self.size 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /y2021/ex18/src/permutator.rs: -------------------------------------------------------------------------------- 1 | pub struct Permutator<'a, T> { 2 | i: usize, 3 | j: usize, 4 | expressions: &'a [T], 5 | } 6 | 7 | impl<'a, T> Permutator<'a, T> { 8 | pub fn new(expressions: &'a Vec) -> Self { 9 | Permutator { 10 | i: 0, 11 | j: 0, 12 | expressions, 13 | } 14 | } 15 | } 16 | 17 | impl<'a, T> Iterator for Permutator<'a, T> { 18 | type Item = (&'a T, &'a T); 19 | 20 | fn next(&mut self) -> Option { 21 | if self.i == self.j { 22 | self.i += 1; 23 | 24 | if self.i == self.expressions.len() { 25 | self.i = 0; 26 | self.j += 1; 27 | } 28 | } 29 | 30 | if self.j == self.expressions.len() { 31 | return None; 32 | } 33 | 34 | let left = self.expressions.get(self.i).unwrap(); 35 | let right = self.expressions.get(self.j).unwrap(); 36 | 37 | self.i += 1; 38 | 39 | if self.i == self.expressions.len() { 40 | self.i = 0; 41 | self.j += 1; 42 | } 43 | 44 | Some((left, right)) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /y2024/ex03/src/lib.rs: -------------------------------------------------------------------------------- 1 | use matcher::{Match, MatcherIter}; 2 | mod matcher; 3 | 4 | pub fn part1(input: &str) -> u64 { 5 | let iter = MatcherIter::new(input); 6 | let mut sum = 0; 7 | 8 | for m in iter { 9 | if let Match::Mul(l, r) = m { 10 | sum += l * r; 11 | } 12 | } 13 | 14 | sum 15 | } 16 | 17 | pub fn part2(input: &str) -> u64 { 18 | let iter = MatcherIter::new(input); 19 | 20 | let mut sum = 0; 21 | let mut enabled = true; 22 | 23 | for m in iter { 24 | match m { 25 | Match::Do => enabled = true, 26 | Match::Dont => enabled = false, 27 | Match::Mul(l, r) => { 28 | if enabled { 29 | sum += l * r; 30 | } 31 | } 32 | } 33 | } 34 | 35 | sum 36 | } 37 | 38 | #[cfg(test)] 39 | mod tests { 40 | use super::*; 41 | const INPUT: &str = include_str!("../input.txt"); 42 | 43 | #[test] 44 | fn test_part1() { 45 | assert_eq!(part1(INPUT), 185797128); 46 | } 47 | 48 | #[test] 49 | fn test_part2() { 50 | assert_eq!(part2(INPUT), 89798695); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Luciano Mammino, Roberto Gambuzzi, Eugen Serbanescu, Stefano Abalsamo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /y2023/ex16/src/lib.rs: -------------------------------------------------------------------------------- 1 | use crate::models::Direction; 2 | use models::Map; 3 | 4 | mod models; 5 | 6 | pub fn part1(input: &str) -> usize { 7 | let map = Map::<110, 110>::new(input); 8 | let energized_pos = map.simulate((0, 0), Direction::Right); 9 | energized_pos.len() 10 | } 11 | 12 | pub fn part2(input: &str) -> usize { 13 | let map = Map::<110, 110>::new(input); 14 | let top_down = (0..110).map(|x| ((x, 0), Direction::Down)); 15 | let left_right = (0..110).map(|y| ((0, y), Direction::Right)); 16 | let bottom_up = (0..110).map(|x| ((x, 109), Direction::Up)); 17 | let right_left = (0..110).map(|y| ((109, y), Direction::Left)); 18 | top_down 19 | .chain(left_right) 20 | .chain(bottom_up) 21 | .chain(right_left) 22 | .map(|(position, direction)| map.simulate(position, direction).len()) 23 | .max() 24 | .unwrap() 25 | } 26 | 27 | #[cfg(test)] 28 | mod tests { 29 | use super::*; 30 | const INPUT: &str = include_str!("../input.txt"); 31 | 32 | #[test] 33 | fn test_part1() { 34 | assert_eq!(part1(INPUT), 8034); 35 | } 36 | 37 | #[test] 38 | fn test_part2() { 39 | assert_eq!(part2(INPUT), 8225); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /y2022/ex11/src/expr.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, PartialEq)] 2 | pub(crate) struct Const(pub(crate) u64); 3 | 4 | #[derive(Debug, PartialEq)] 5 | pub(crate) enum Var { 6 | Old, 7 | New, 8 | } 9 | 10 | #[derive(Debug, PartialEq)] 11 | pub(crate) enum VarConst { 12 | Var(Var), 13 | Const(Const), 14 | } 15 | 16 | #[derive(Debug, PartialEq)] 17 | pub(crate) enum Op { 18 | Plus, 19 | Mult, 20 | } 21 | 22 | #[derive(Debug, PartialEq)] 23 | pub(crate) struct Expr { 24 | lhs: VarConst, 25 | op: Op, 26 | rhs: VarConst, 27 | } 28 | 29 | impl Expr { 30 | pub(crate) fn new(lhs: VarConst, op: Op, rhs: VarConst) -> Self { 31 | Self { lhs, op, rhs } 32 | } 33 | 34 | pub(crate) fn eval(&self, old: u64, new: u64) -> u64 { 35 | let lhs = match self.lhs { 36 | VarConst::Var(Var::Old) => old, 37 | VarConst::Var(Var::New) => new, 38 | VarConst::Const(Const(c)) => c, 39 | }; 40 | let rhs = match self.rhs { 41 | VarConst::Var(Var::Old) => old, 42 | VarConst::Var(Var::New) => new, 43 | VarConst::Const(Const(c)) => c, 44 | }; 45 | match self.op { 46 | Op::Plus => lhs + rhs, 47 | Op::Mult => lhs * rhs, 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /y2022/ex15/benches/bench_y2022ex15.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex15::{ 3 | part1, part2, 4 | readings::{parse, parse_regex, parse_regex_lazy, Pos}, 5 | }; 6 | 7 | fn parse_and_collect_input< 8 | 'a, 9 | R: Iterator + 'a, 10 | F: FnOnce(&'a str) -> R, 11 | >( 12 | input: &'a str, 13 | f: F, 14 | ) { 15 | let _data: Vec<_> = f(input).collect(); 16 | } 17 | 18 | fn criterion_benchmark(c: &mut Criterion) { 19 | let input = include_str!("../input.txt"); 20 | c.bench_function("y2022ex15::part1", |b| b.iter(|| part1(black_box(input)))); 21 | c.bench_function("y2022ex15::part2", |b| b.iter(|| part2(black_box(input)))); 22 | c.bench_function("y2022ex15::readings::parse", |b| { 23 | b.iter(|| parse_and_collect_input(black_box(input), parse)) 24 | }); 25 | c.bench_function("y2022ex15::readings::parse_regex", |b| { 26 | b.iter(|| parse_and_collect_input(black_box(input), parse_regex)) 27 | }); 28 | c.bench_function("y2022ex15::readings::parse_regex_lazy", |b| { 29 | b.iter(|| parse_and_collect_input(black_box(input), parse_regex_lazy)) 30 | }); 31 | } 32 | 33 | criterion_group!(benches, criterion_benchmark); 34 | criterion_main!(benches); 35 | -------------------------------------------------------------------------------- /y2021/ex16/input.txt: -------------------------------------------------------------------------------- 1 | 820D4100A1000085C6E8331F8401D8E106E1680021708630C50200A3BC01495B99CF6852726A88014DC9DBB30798409BBDF5A4D97F5326F050C02F9D2A971D9B539E0C93323004B4012960E9A5B98600005DA7F11AFBB55D96AFFBE1E20041A64A24D80C01E9D298AF0E22A98027800BD4EE3782C91399FA92901936E0060016B82007B0143C2005280146005300F7840385380146006900A72802469007B0001961801E60053002B2400564FFCE25FEFE40266CA79128037500042626C578CE00085C718BD1F08023396BA46001BF3C870C58039587F3DE52929DFD9F07C9731CC601D803779CCC882767E668DB255D154F553C804A0A00DD40010B87D0D6378002191BE11C6A914F1007C8010F8B1122239803B04A0946630062234308D44016CCEEA449600AC9844A733D3C700627EA391EE76F9B4B5DA649480357D005E622493112292D6F1DF60665EDADD212CF8E1003C29193E4E21C9CF507B910991E5A171D50092621B279D96F572A94911C1D200FA68024596EFA517696EFA51729C9FB6C64019250034F3F69DD165A8E33F7F919802FE009880331F215C4A1007A20C668712B685900804ABC00D50401C89715A3B00021516E164409CE39380272B0E14CB1D9004632E75C00834DB64DB4980292D3918D0034F3D90C958EECD8400414A11900403307534B524093EBCA00BCCD1B26AA52000FB4B6C62771CDF668E200CC20949D8AE2790051133B2ED005E2CC953FE1C3004EC0139ED46DBB9AC9C2655038C01399D59A3801F79EADAD878969D8318008491375003A324C5A59C7D68402E9B65994391A6BCC73A5F2FEABD8804322D90B25F3F4088F33E96D74C0139CF6006C0159BEF8EA6FBE3A9CEC337B859802B2AC9A0084C9DCC9ECD67DD793004E669FA2DE006EC00085C558C5134001088E308A20 -------------------------------------------------------------------------------- /y2023/ex09/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::parse_history; 2 | 3 | mod models; 4 | 5 | pub fn part1(input: &str) -> i64 { 6 | input 7 | .lines() 8 | .map(|line| { 9 | let (_, mut history) = parse_history(line).unwrap(); 10 | history.expand(); 11 | history.extrapolate_right() 12 | }) 13 | .sum() 14 | } 15 | 16 | pub fn part2(input: &str) -> i64 { 17 | input 18 | .lines() 19 | .map(|line| { 20 | let (_, mut history) = parse_history(line).unwrap(); 21 | history.expand(); 22 | history.extrapolate_left() 23 | }) 24 | .sum() 25 | } 26 | 27 | #[cfg(test)] 28 | mod tests { 29 | use super::*; 30 | const INPUT: &str = include_str!("../input.txt"); 31 | const EXAMPLE_INPUT: &str = "0 3 6 9 12 15 32 | 1 3 6 10 15 21 33 | 10 13 16 21 30 45"; 34 | 35 | #[test] 36 | fn test_part1_example() { 37 | assert_eq!(part1(EXAMPLE_INPUT), 114); 38 | } 39 | 40 | #[test] 41 | fn test_part1() { 42 | assert_eq!(part1(INPUT), 1731106378); 43 | } 44 | 45 | #[test] 46 | fn test_part2_example() { 47 | assert_eq!(part2(EXAMPLE_INPUT), 2); 48 | } 49 | 50 | #[test] 51 | fn test_part2() { 52 | assert_eq!(part2(INPUT), 1087); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /y2022/ex10/src/display.rs: -------------------------------------------------------------------------------- 1 | use std::ops::RangeInclusive; 2 | 3 | pub(crate) enum Pixel { 4 | On, 5 | Off, 6 | } 7 | 8 | #[derive(Debug)] 9 | pub(crate) struct Display { 10 | pixels: String, 11 | current_pixel: usize, 12 | } 13 | 14 | impl Display { 15 | pub(crate) fn new() -> Self { 16 | Self { 17 | pixels: String::with_capacity(40 * 6), 18 | current_pixel: 0, 19 | } 20 | } 21 | 22 | pub(crate) fn set_pixel(&mut self, pixel: Pixel) { 23 | let char_to_draw = match pixel { 24 | Pixel::On => '#', 25 | Pixel::Off => '.', 26 | }; 27 | self.pixels.push(char_to_draw); 28 | self.current_pixel += 1; 29 | } 30 | 31 | pub(crate) fn sprite_pos(&self) -> RangeInclusive { 32 | RangeInclusive::new( 33 | ((self.current_pixel % 40) as i32) - 1, 34 | ((self.current_pixel % 40) as i32) + 1, 35 | ) 36 | } 37 | } 38 | 39 | impl std::fmt::Display for Display { 40 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 41 | let mut chars = self.pixels.chars(); 42 | for _ in 0..6 { 43 | let line = chars.by_ref().take(40).collect::(); 44 | writeln!(f, "{line}")?; 45 | } 46 | Ok(()) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /y2021/ex14/input.txt: -------------------------------------------------------------------------------- 1 | SVCHKVFKCSHVFNBKKPOC 2 | 3 | NC -> H 4 | PK -> V 5 | SO -> C 6 | PH -> F 7 | FP -> N 8 | PN -> B 9 | NP -> V 10 | NK -> S 11 | FV -> P 12 | SB -> S 13 | VN -> F 14 | SC -> H 15 | OB -> F 16 | ON -> O 17 | HN -> V 18 | HC -> F 19 | SN -> K 20 | CB -> H 21 | OP -> K 22 | HP -> H 23 | KS -> S 24 | BC -> S 25 | VB -> V 26 | FC -> B 27 | BH -> C 28 | HH -> O 29 | KH -> S 30 | VF -> F 31 | PF -> P 32 | VV -> F 33 | PP -> V 34 | BO -> H 35 | BF -> B 36 | PS -> K 37 | FO -> O 38 | KF -> O 39 | FN -> H 40 | CK -> B 41 | VP -> V 42 | HK -> F 43 | OV -> P 44 | CS -> V 45 | FF -> P 46 | OH -> N 47 | VS -> H 48 | VO -> O 49 | CP -> O 50 | KC -> V 51 | KV -> P 52 | BK -> B 53 | VK -> S 54 | NF -> V 55 | OO -> V 56 | FH -> H 57 | CN -> O 58 | SP -> B 59 | KN -> V 60 | OF -> H 61 | NV -> H 62 | FK -> B 63 | PV -> N 64 | NB -> B 65 | KK -> P 66 | VH -> P 67 | CC -> B 68 | HV -> V 69 | OC -> H 70 | PO -> V 71 | NO -> O 72 | BP -> C 73 | NH -> H 74 | BN -> O 75 | BV -> S 76 | CV -> B 77 | HS -> O 78 | NN -> S 79 | NS -> P 80 | KB -> F 81 | CO -> H 82 | HO -> P 83 | PB -> B 84 | BS -> P 85 | SH -> H 86 | FS -> V 87 | SF -> O 88 | OK -> F 89 | KP -> S 90 | BB -> C 91 | PC -> B 92 | OS -> C 93 | SV -> N 94 | SK -> K 95 | KO -> C 96 | SS -> V 97 | CF -> C 98 | HB -> K 99 | VC -> B 100 | CH -> P 101 | HF -> K 102 | FB -> V -------------------------------------------------------------------------------- /y2022/ex13/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod packet; 2 | use std::cmp::Ordering; 3 | 4 | use packet::*; 5 | 6 | pub fn part1(input: &str) -> usize { 7 | parse_input_in_pairs(input) 8 | .enumerate() 9 | .filter(|(_, (left, right))| { 10 | let cmp = left.cmp(right); 11 | cmp == Ordering::Less 12 | }) 13 | .map(|(i, _)| i + 1) 14 | .sum() 15 | } 16 | 17 | pub fn part2(input: &str) -> usize { 18 | let (_, mut packets) = parse_input_as_list(input).unwrap(); 19 | let divider_packet_1: Packet = "[[2]]".parse().unwrap(); 20 | let divider_packet_2: Packet = "[[6]]".parse().unwrap(); 21 | packets.push(divider_packet_1.clone()); 22 | packets.push(divider_packet_2.clone()); 23 | 24 | packets.sort(); 25 | packets 26 | .iter() 27 | .enumerate() 28 | .filter_map(|(i, p)| { 29 | if *p == divider_packet_1 || *p == divider_packet_2 { 30 | Some(i + 1) 31 | } else { 32 | None 33 | } 34 | }) 35 | .product() 36 | } 37 | 38 | #[cfg(test)] 39 | mod tests { 40 | use super::*; 41 | const INPUT: &str = include_str!("../input.txt"); 42 | 43 | #[test] 44 | fn test_part1() { 45 | assert_eq!(part1(INPUT), 6420); 46 | } 47 | 48 | #[test] 49 | fn test_part2() { 50 | assert_eq!(part2(INPUT), 22000); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/build.rs: -------------------------------------------------------------------------------- 1 | //! This build script copies the `memory.x` file from the crate root into 2 | //! a directory where the linker can always find it at build time. 3 | //! For many projects this is optional, as the linker always searches the 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you 5 | //! are using a workspace or have a more complicated build setup, this 6 | //! build script becomes required. Additionally, by requesting that 7 | //! Cargo re-run the build script whenever `memory.x` is changed, 8 | //! updating `memory.x` ensures a rebuild of the application with the 9 | //! new memory settings. 10 | 11 | use std::env; 12 | use std::fs::File; 13 | use std::io::Write; 14 | use std::path::PathBuf; 15 | 16 | fn main() { 17 | // Put `memory.x` in our output directory and ensure it's 18 | // on the linker search path. 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 20 | File::create(out.join("memory.x")) 21 | .unwrap() 22 | .write_all(include_bytes!("memory.x")) 23 | .unwrap(); 24 | println!("cargo:rustc-link-search={}", out.display()); 25 | 26 | // By default, Cargo will re-run a build script whenever 27 | // any file in the project changes. By specifying `memory.x` 28 | // here, we ensure the build script is only re-run when 29 | // `memory.x` is changed. 30 | println!("cargo:rerun-if-changed=memory.x"); 31 | } 32 | -------------------------------------------------------------------------------- /y2021/ex19/src/point3d.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | ops::{Add, Sub}, 3 | str::FromStr, 4 | }; 5 | 6 | #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash)] 7 | pub struct Point3D(pub i32, pub i32, pub i32); 8 | 9 | impl Add for Point3D { 10 | type Output = Self; 11 | 12 | fn add(self, other: Self) -> Self { 13 | Self(self.0 + other.0, self.1 + other.1, self.2 + other.2) 14 | } 15 | } 16 | 17 | impl Add for &Point3D { 18 | type Output = Point3D; 19 | 20 | fn add(self, other: Self) -> Point3D { 21 | Point3D(self.0 + other.0, self.1 + other.1, self.2 + other.2) 22 | } 23 | } 24 | 25 | impl Sub for Point3D { 26 | type Output = Self; 27 | 28 | fn sub(self, other: Self) -> Self { 29 | Self(self.0 - other.0, self.1 - other.1, self.2 - other.2) 30 | } 31 | } 32 | 33 | impl Sub for &Point3D { 34 | type Output = Point3D; 35 | 36 | fn sub(self, other: Self) -> Point3D { 37 | Point3D(self.0 - other.0, self.1 - other.1, self.2 - other.2) 38 | } 39 | } 40 | 41 | impl FromStr for Point3D { 42 | type Err = (); 43 | 44 | fn from_str(s: &str) -> Result { 45 | let mut parts = s.split(','); 46 | let x: i32 = parts.next().unwrap().parse().unwrap(); 47 | let y: i32 = parts.next().unwrap().parse().unwrap(); 48 | let z: i32 = parts.next().unwrap().parse().unwrap(); 49 | 50 | Ok(Point3D(x, y, z)) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /y2025/ex02/src/lib.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | parser::parse_input, 3 | utils::{is_id_invalid, is_id_invalid_p2}, 4 | }; 5 | mod parser; 6 | mod utils; 7 | 8 | pub fn part1(input: &str) -> u64 { 9 | let ranges = parse_input(&mut &*input).expect("Failed to parse input"); 10 | ranges 11 | .iter() 12 | .flat_map(|r| r.clone()) 13 | .filter(|id| is_id_invalid(*id)) 14 | .sum() 15 | } 16 | 17 | pub fn part2(input: &str) -> u64 { 18 | let ranges = parse_input(&mut &*input).expect("Failed to parse input"); 19 | ranges 20 | .iter() 21 | .flat_map(|r| r.clone()) 22 | .filter(|id| is_id_invalid_p2(*id)) 23 | .sum() 24 | } 25 | 26 | #[cfg(test)] 27 | mod tests { 28 | use super::*; 29 | const INPUT: &str = include_str!("../input.txt"); 30 | const EXAMPLE_INPUT: &str = "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"; 31 | 32 | #[test] 33 | fn test_part1_example() { 34 | assert_eq!(part1(EXAMPLE_INPUT), 1227775554); 35 | } 36 | 37 | #[test] 38 | fn test_part1() { 39 | assert_eq!(part1(INPUT), 30608905813); 40 | } 41 | 42 | #[test] 43 | fn test_part2_example() { 44 | assert_eq!(part2(EXAMPLE_INPUT), 4174379265); 45 | } 46 | 47 | #[test] 48 | fn test_part2() { 49 | assert_eq!(part2(INPUT), 31898925685); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /y2023/ex12/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::{parse_entry, CountCache}; 2 | 3 | mod models; 4 | 5 | pub fn part1(input: &str) -> usize { 6 | let cache = CountCache::new(); 7 | input 8 | .lines() 9 | .map(|line| { 10 | let (_, record) = parse_entry(line).unwrap(); 11 | record.count_solutions(&cache) 12 | }) 13 | .sum() 14 | } 15 | 16 | pub fn part2(input: &str) -> usize { 17 | let cache = CountCache::new(); 18 | input 19 | .lines() 20 | .map(|line| { 21 | let (_, record) = parse_entry(line).unwrap(); 22 | let record = record.unfold(5); 23 | record.count_solutions(&cache) 24 | }) 25 | .sum() 26 | } 27 | 28 | #[cfg(test)] 29 | mod tests { 30 | use super::*; 31 | const INPUT: &str = include_str!("../input.txt"); 32 | const EXAMPLE_INPUT: &str = "???.### 1,1,3 33 | .??..??...?##. 1,1,3 34 | ?#?#?#?#?#?#?#? 1,3,1,6 35 | ????.#...#... 4,1,1 36 | ????.######..#####. 1,6,5 37 | ?###???????? 3,2,1"; 38 | 39 | #[test] 40 | fn test_part1_example() { 41 | assert_eq!(part1(EXAMPLE_INPUT), 21); 42 | } 43 | 44 | #[test] 45 | fn test_part1() { 46 | assert_eq!(part1(INPUT), 7407); 47 | } 48 | 49 | #[test] 50 | fn test_part2_example() { 51 | assert_eq!(part2(EXAMPLE_INPUT), 525152); 52 | } 53 | 54 | #[test] 55 | fn test_part2() { 56 | assert_eq!(part2(INPUT), 30568243604962); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2023/ex13/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::Map; 2 | 3 | mod models; 4 | 5 | fn solve(input: &str, errors: usize) -> usize { 6 | input 7 | .split("\n\n") 8 | .map(|raw_map| { 9 | let map: Map = raw_map.parse().unwrap(); 10 | let horizontal_reflection = map.find_reflection(errors).unwrap_or(0); 11 | let vertical_reflection = map.transpose().find_reflection(errors).unwrap_or(0); 12 | 13 | vertical_reflection + horizontal_reflection * 100 14 | }) 15 | .sum() 16 | } 17 | 18 | pub fn part1(input: &str) -> usize { 19 | solve(input, 0) 20 | } 21 | 22 | pub fn part2(input: &str) -> usize { 23 | solve(input, 1) 24 | } 25 | 26 | #[cfg(test)] 27 | mod tests { 28 | use super::*; 29 | const INPUT: &str = include_str!("../input.txt"); 30 | const EXAMPLE_INPUT: &str = "#.##..##. 31 | ..#.##.#. 32 | ##......# 33 | ##......# 34 | ..#.##.#. 35 | ..##..##. 36 | #.#.##.#. 37 | 38 | #...##..# 39 | #....#..# 40 | ..##..### 41 | #####.##. 42 | #####.##. 43 | ..##..### 44 | #....#..#"; 45 | 46 | #[test] 47 | fn test_part1_example() { 48 | assert_eq!(part1(EXAMPLE_INPUT), 405); 49 | } 50 | 51 | #[test] 52 | fn test_part1() { 53 | assert_eq!(part1(INPUT), 30575); 54 | } 55 | 56 | #[test] 57 | fn test_part2_example() { 58 | assert_eq!(part2(EXAMPLE_INPUT), 400); 59 | } 60 | 61 | #[test] 62 | fn test_part2() { 63 | assert_eq!(part2(INPUT), 37478); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /y2022/ex11/input.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 57, 58 3 | Operation: new = old * 19 4 | Test: divisible by 7 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 66, 52, 59, 79, 94, 73 10 | Operation: new = old + 1 11 | Test: divisible by 19 12 | If true: throw to monkey 4 13 | If false: throw to monkey 6 14 | 15 | Monkey 2: 16 | Starting items: 80 17 | Operation: new = old + 6 18 | Test: divisible by 5 19 | If true: throw to monkey 7 20 | If false: throw to monkey 5 21 | 22 | Monkey 3: 23 | Starting items: 82, 81, 68, 66, 71, 83, 75, 97 24 | Operation: new = old + 5 25 | Test: divisible by 11 26 | If true: throw to monkey 5 27 | If false: throw to monkey 2 28 | 29 | Monkey 4: 30 | Starting items: 55, 52, 67, 70, 69, 94, 90 31 | Operation: new = old * old 32 | Test: divisible by 17 33 | If true: throw to monkey 0 34 | If false: throw to monkey 3 35 | 36 | Monkey 5: 37 | Starting items: 69, 85, 89, 91 38 | Operation: new = old + 7 39 | Test: divisible by 13 40 | If true: throw to monkey 1 41 | If false: throw to monkey 7 42 | 43 | Monkey 6: 44 | Starting items: 75, 53, 73, 52, 75 45 | Operation: new = old * 7 46 | Test: divisible by 2 47 | If true: throw to monkey 0 48 | If false: throw to monkey 4 49 | 50 | Monkey 7: 51 | Starting items: 94, 60, 79 52 | Operation: new = old + 2 53 | Test: divisible by 3 54 | If true: throw to monkey 1 55 | If false: throw to monkey 6 -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/debug_probes.md: -------------------------------------------------------------------------------- 1 | # Compatible CMSIS-DAP debug probes 2 | 3 | ## Raspberry Pi Pico 4 | 5 | You can use a second Pico as your debugger. 6 | 7 | - Download this file: https://github.com/majbthrd/DapperMime/releases/download/20210225/raspberry_pi_pico-DapperMime.uf2 8 | - Boot the Pico in bootloader mode by holding the bootset button while plugging it in 9 | - Open the drive RPI-RP2 when prompted 10 | - Copy raspberry_pi_pico-DapperMime.uf2 from Downloads into RPI-RP2 11 | - Connect the debug pins of your CMSIS-DAP Pico to the target one 12 | - Connect GP2 on the Probe to SWCLK on the Target 13 | - Connect GP3 on the Probe to SWDIO on the Target 14 | - Connect a ground line from the CMSIS-DAP Probe to the Target too 15 | 16 | ## WeAct MiniF4 17 | https://therealprof.github.io/blog/usb-c-pill-part1/ 18 | 19 | ## HS-Probe 20 | https://github.com/probe-rs/hs-probe 21 | 22 | ## ST-LINK v2 clone 23 | It's getting harder to source these with stm32f103's as time goes on, so you might be better off choosing a stm32f103 dev board 24 | 25 | Firmware: https://github.com/devanlai/dap42 26 | 27 | ## LPC-Link2 28 | https://www.nxp.com/design/microcontrollers-developer-resources/lpc-link2:OM13054 29 | 30 | ## MCU-Link 31 | https://www.nxp.com/part/MCU-LINK#/ 32 | 33 | ## DAPLink 34 | You can use DAPLink firmware with any of it's supported chips (LPC4322, LPC11U35, K20, K22, KL26). You'll need to use the 'develop' branch to use GCC to build it. You'll need to find a chip with the correct 35 | 36 | Firmware source: https://github.com/ARMmbed/DAPLink/tree/develop 37 | -------------------------------------------------------------------------------- /.github/workflows/post_to_pr.yaml: -------------------------------------------------------------------------------- 1 | name: Post To PR 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["Valgrind Benchmarks", "Cargo Benchmarks"] 6 | types: [completed] 7 | 8 | jobs: 9 | on-success: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.event.workflow_run.conclusion == 'success' }} 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Download artifact 16 | uses: dawidd6/action-download-artifact@v2 17 | with: 18 | github_token: ${{secrets.GITHUB_TOKEN}} 19 | workflow: ${{ github.event.workflow.id }} 20 | # Optional, will use specified workflow run 21 | # run_id: 1122334455 22 | # name: artifact_name 23 | 24 | - name: "Create the PR comment message" 25 | id: pr_comment 26 | run: | 27 | PID="$(cat pr-comment/pid.txt)" 28 | echo "::set-output name=pr_id::${PID}" 29 | PRCOMMENT="$(cat pr-comment/message.txt)" 30 | echo "::set-output name=pr_comment::${PRCOMMENT//$'\n'/%0A}" 31 | 32 | - name: "Post to PR" 33 | uses: malagolichiara/comment-on-pr@master 34 | env: 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 36 | with: 37 | pull_request_number: ${{ steps.pr_comment.outputs.pr_id }} 38 | check_for_duplicate_msg: true 39 | msg: ${{ steps.pr_comment.outputs.pr_comment }} 40 | 41 | # on-failure: 42 | # runs-on: ubuntu-latest 43 | # if: ${{ github.event.workflow_run.conclusion == 'failure' }} 44 | # steps: 45 | # ... 46 | -------------------------------------------------------------------------------- /y2020/ex03/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub fn part1(_input: &str) -> u32 { 2 | let lines: Vec> = _input 3 | .lines() 4 | .map(|s| s.chars().collect::>()) 5 | .collect(); 6 | let mut x = 0; 7 | let mut cnt = 0; 8 | for row in lines { 9 | let c = row.get(x % row.len()).unwrap(); 10 | x += 3; 11 | if *c == '#' { 12 | cnt += 1; 13 | } 14 | } 15 | cnt 16 | } 17 | 18 | pub fn part2(_input: &str) -> u32 { 19 | let lines: Vec> = _input 20 | .lines() 21 | .map(|s| s.chars().collect::>()) 22 | .collect(); 23 | let mut xs = vec![0; 5]; 24 | let ixs = vec![1, 3, 5, 7, 1]; 25 | let mut cnt = vec![0; 5]; 26 | for (j, row) in lines.iter().enumerate() { 27 | for i in 0..xs.len() { 28 | if i == 4 && j % 2 == 1 { 29 | // jump the odd row when is the last rule (y must increment by 2) 30 | continue; 31 | } 32 | let c = row.get(xs[i] % row.len()).unwrap(); 33 | if *c == '#' { 34 | cnt[i] += 1; 35 | } 36 | xs[i] += ixs[i]; 37 | } 38 | } 39 | cnt.iter().product() 40 | } 41 | 42 | #[cfg(test)] 43 | mod tests { 44 | use super::*; 45 | #[test] 46 | fn part_1() { 47 | let input = include_str!("../input.txt"); 48 | assert_eq!(part1(input), 299); 49 | } 50 | 51 | #[test] 52 | fn part_2() { 53 | let input = include_str!("../input.txt"); 54 | assert_eq!(part2(input), 3621285278); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug rp2040-project-template", 9 | "request": "launch", 10 | "type": "cortex-debug", 11 | "cwd": "${workspaceRoot}", 12 | "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/rp2040-project-template", 13 | "preLaunchTask": "Build binary", 14 | "servertype": "external", 15 | // "showDevDebugOutput": "both", 16 | "gdbPath": "gdb-multiarch", 17 | // Connect to an already running OpenOCD instance 18 | "gdbTarget": "localhost:3333", 19 | // If you have the Pico SDK installed, allows the 20 | // display of the RP2040 CPU registers in VS Code 21 | // "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", 22 | "runToEntry": true, 23 | "preLaunchCommands": [ 24 | // "monitor init", 25 | // "monitor reset init", 26 | // "monitor halt", 27 | // "delete breakpoints" 28 | ], 29 | // Work around for stopping at main on restart 30 | // "postRestartCommands": [ 31 | // "break main", 32 | // "continue" 33 | // ], 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /y2022/ex01/benches/bench_y2022ex01.rs: -------------------------------------------------------------------------------- 1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 2 | use y2022ex01::{ 3 | part1, part1_classic, part1_combinators, part2, part2_combinators_itertools, 4 | part2_combinators_no_sort, part2_combinators_no_sort_const, 5 | part2_combinators_no_sort_const_custom_iter, 6 | }; 7 | 8 | fn criterion_benchmark(c: &mut Criterion) { 9 | let input = include_str!("../input.txt"); 10 | c.bench_function("y2022ex01::part1", |b| b.iter(|| part1(black_box(input)))); 11 | c.bench_function("y2022ex01::part1_classic", |b| { 12 | b.iter(|| part1_classic(black_box(input))) 13 | }); 14 | c.bench_function("y2022ex01::part1_combinators", |b| { 15 | b.iter(|| part1_combinators(black_box(input))) 16 | }); 17 | c.bench_function("y2022ex01::part2", |b| b.iter(|| part2(black_box(input)))); 18 | c.bench_function("y2022ex01::part2_combinators_itertools", |b| { 19 | b.iter(|| part2_combinators_itertools(black_box(input))) 20 | }); 21 | c.bench_function("y2022ex01::part2_combinators_no_sort", |b| { 22 | b.iter(|| part2_combinators_no_sort(black_box(input))) 23 | }); 24 | c.bench_function("y2022ex01::part2_combinators_no_sort_const", |b| { 25 | b.iter(|| part2_combinators_no_sort_const(black_box(input))) 26 | }); 27 | c.bench_function( 28 | "y2022ex01::part2_combinators_no_sort_const_custom_iter", 29 | |b| b.iter(|| part2_combinators_no_sort_const_custom_iter(black_box(input))), 30 | ); 31 | } 32 | 33 | criterion_group!(benches, criterion_benchmark); 34 | criterion_main!(benches); 35 | -------------------------------------------------------------------------------- /y2023/ex21/src/models.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Display; 2 | 3 | pub type Position = (usize, usize); 4 | 5 | #[derive(Debug, Clone, Copy)] 6 | pub enum Tile { 7 | Plot, 8 | Rock, 9 | } 10 | 11 | #[derive(Debug, Clone)] 12 | pub struct Map { 13 | pub map: [[Tile; W]; H], 14 | pub start: Position, 15 | } 16 | 17 | impl Map { 18 | pub fn new(input: &str) -> Self { 19 | let mut map = [[Tile::Plot; W]; H]; 20 | let mut start = (0, 0); 21 | for (y, line) in input.lines().enumerate() { 22 | for (x, c) in line.chars().enumerate() { 23 | match c { 24 | '.' => map[y][x] = Tile::Plot, 25 | '#' => map[y][x] = Tile::Rock, 26 | 'S' => { 27 | map[y][x] = Tile::Plot; 28 | start = (x, y); 29 | } 30 | _ => panic!("Invalid character '{}' found at ({}, {})", c, x, y), 31 | }; 32 | } 33 | } 34 | Self { map, start } 35 | } 36 | } 37 | 38 | impl Display for Map { 39 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 40 | for line in self.map.iter() { 41 | for tile in line.iter() { 42 | match tile { 43 | Tile::Plot => write!(f, ".")?, 44 | Tile::Rock => write!(f, "#")?, 45 | } 46 | } 47 | writeln!(f)?; 48 | } 49 | Ok(()) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /y2022/ex08/src/cell_iter.rs: -------------------------------------------------------------------------------- 1 | pub(crate) struct CellIterator<'a, T> { 2 | grid: &'a Vec>, 3 | row: usize, 4 | max_row: usize, 5 | col: usize, 6 | max_col: usize, 7 | } 8 | 9 | impl<'a, T> CellIterator<'a, T> { 10 | pub fn new(grid: &'a Vec>) -> Self { 11 | Self { 12 | grid, 13 | row: 0, 14 | max_row: grid.len(), 15 | col: 0, 16 | max_col: grid.get(0).map(|row| row.len()).unwrap_or(0), 17 | } 18 | } 19 | } 20 | 21 | impl<'a, T> Iterator for CellIterator<'a, T> { 22 | type Item = (usize, usize, &'a T); 23 | 24 | fn next(&mut self) -> Option { 25 | if self.row >= self.max_row { 26 | return None; 27 | } 28 | 29 | let cell = &self.grid[self.row][self.col]; 30 | let col = self.col; 31 | let row = self.row; 32 | 33 | self.col += 1; 34 | if self.col >= self.max_col { 35 | self.col = 0; 36 | self.row += 1; 37 | } 38 | 39 | Some((row, col, cell)) 40 | } 41 | } 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | use super::*; 46 | 47 | #[test] 48 | fn test_iterator() { 49 | let grid = vec![vec![1, 2, 3], vec![4, 5, 6]]; 50 | let result: Vec<(usize, usize, &i32)> = CellIterator::new(&grid).collect(); 51 | assert_eq!( 52 | result, 53 | vec![ 54 | (0, 0, &1), 55 | (0, 1, &2), 56 | (0, 2, &3), 57 | (1, 0, &4), 58 | (1, 1, &5), 59 | (1, 2, &6) 60 | ] 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /y2020/ex25/src/lib.rs: -------------------------------------------------------------------------------- 1 | const MAGIC_NUMBER: usize = 20201227; 2 | const DEFAULT_SUBJECT_NUMBER: usize = 7; 3 | 4 | fn calculate_loop_size(n: usize) -> usize { 5 | let mut loop_size = 0; 6 | let mut acc = 1; 7 | loop { 8 | if acc == n { 9 | return loop_size; 10 | } 11 | 12 | acc *= DEFAULT_SUBJECT_NUMBER; 13 | acc %= MAGIC_NUMBER; 14 | 15 | loop_size += 1; 16 | } 17 | } 18 | 19 | fn transform(subject: usize, loop_size: usize) -> usize { 20 | let mut acc = 1; 21 | 22 | for _ in 0..loop_size { 23 | acc *= subject; 24 | acc %= MAGIC_NUMBER; 25 | } 26 | 27 | acc 28 | } 29 | 30 | pub fn part1(input: &str) -> usize { 31 | let mut lines = input.lines(); 32 | let card_pub_key: usize = lines.next().unwrap().parse().unwrap(); 33 | let door_pub_key: usize = lines.next().unwrap().parse().unwrap(); 34 | 35 | let card_loop_size = calculate_loop_size(card_pub_key); 36 | let door_loop_size = calculate_loop_size(door_pub_key); 37 | 38 | transform( 39 | transform(DEFAULT_SUBJECT_NUMBER, card_loop_size), 40 | door_loop_size, 41 | ) 42 | } 43 | 44 | #[cfg(test)] 45 | mod ex25_tests { 46 | use super::*; 47 | 48 | #[test] 49 | fn test_calculate_loop_size() { 50 | assert_eq!(calculate_loop_size(5764801), 8); 51 | assert_eq!(calculate_loop_size(17807724), 11); 52 | } 53 | 54 | #[test] 55 | fn test_transform() { 56 | assert_eq!(transform(17807724, 8), 14897079); 57 | assert_eq!(transform(5764801, 11), 14897079); 58 | } 59 | 60 | #[test] 61 | fn part_1() { 62 | let input = include_str!("../input.txt"); 63 | assert_eq!(part1(input), 9177528); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /y2022/ex07/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod fs; 2 | mod parser; 3 | use fs::*; 4 | use parser::*; 5 | 6 | pub fn part1(input: &str) -> usize { 7 | let fs: Fs = parse_input(input).collect(); 8 | 9 | fs.get_folders_size() 10 | .values() 11 | .copied() 12 | .filter(|s| *s < 100000) 13 | .sum() 14 | } 15 | 16 | pub fn part2(input: &str) -> usize { 17 | let fs: Fs = parse_input(input).collect(); 18 | 19 | let max_space = 70000000_usize; 20 | let needed_space = 30000000_usize; 21 | let used_space = fs.used_space(); 22 | let free_space = max_space - used_space; 23 | let space_to_free = needed_space - free_space; 24 | 25 | fs.get_folders_size() 26 | .values() 27 | .copied() 28 | .filter(|s| *s >= space_to_free) 29 | .min() 30 | .unwrap() 31 | } 32 | 33 | #[cfg(test)] 34 | mod tests { 35 | use super::*; 36 | const INPUT: &str = include_str!("../input.txt"); 37 | const TEST_INPUT: &str = "$ cd / 38 | $ ls 39 | dir a 40 | 14848514 b.txt 41 | 8504156 c.dat 42 | dir d 43 | $ cd a 44 | $ ls 45 | dir e 46 | 29116 f 47 | 2557 g 48 | 62596 h.lst 49 | $ cd e 50 | $ ls 51 | 584 i 52 | $ cd .. 53 | $ cd .. 54 | $ cd d 55 | $ ls 56 | 4060174 j 57 | 8033020 d.log 58 | 5626152 d.ext 59 | 7214296 k"; 60 | 61 | #[test] 62 | fn test_part1_example() { 63 | let result = part1(TEST_INPUT); 64 | assert_eq!(result, 95437); 65 | } 66 | 67 | #[test] 68 | fn test_part1() { 69 | assert_eq!(part1(INPUT), 1778099); 70 | } 71 | 72 | #[test] 73 | fn test_part2_example() { 74 | assert_eq!(part2(TEST_INPUT), 24933642); 75 | } 76 | 77 | #[test] 78 | fn test_part2() { 79 | assert_eq!(part2(INPUT), 1623571); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /y2020/ex23/src/cllist.rs: -------------------------------------------------------------------------------- 1 | use itertools::Itertools; 2 | 3 | #[derive(Debug)] 4 | pub struct CLList { 5 | data: Box<[usize]>, 6 | } 7 | 8 | impl CLList { 9 | pub fn from_iter(iter: impl Iterator + Clone, first: usize) -> Self { 10 | let mut data = vec![0; 1_000_001]; 11 | 12 | let mut last = 0; 13 | for (a, b) in iter.into_iter().tuple_windows() { 14 | data[a] = b; 15 | last = b; 16 | } 17 | data[last] = first; 18 | 19 | CLList { 20 | data: data.into_boxed_slice(), 21 | } 22 | } 23 | 24 | pub fn next(&self, i: usize) -> usize { 25 | self.data[i] 26 | } 27 | 28 | pub fn pop3_after(&mut self, i: usize) -> [usize; 3] { 29 | let one = self.next(i); 30 | let two = self.next(one); 31 | let three = self.next(two); 32 | 33 | self.data[i] = self.next(three); 34 | 35 | [one, two, three] 36 | } 37 | 38 | pub fn push3_after(&mut self, i: usize, elements: [usize; 3]) { 39 | let next_target = self.next(i); 40 | 41 | self.data[i] = elements[0]; 42 | self.data[elements[2]] = next_target; 43 | } 44 | } 45 | 46 | #[cfg(test)] 47 | mod tests { 48 | use super::*; 49 | 50 | #[test] 51 | fn test_constructor() { 52 | let data: [usize; 6] = [1, 2, 3, 4, 5, 6]; 53 | let mut list: CLList = CLList::from_iter(data.into_iter(), 1); 54 | assert_eq!(list.next(3), 4); 55 | assert_eq!(list.next(6), 1); 56 | 57 | assert_eq!(list.pop3_after(2), [3, 4, 5]); 58 | assert_eq!(list.next(2), 6); 59 | 60 | list.push3_after(1, [3, 4, 5]); 61 | assert_eq!(list.next(1), 3); 62 | assert_eq!(list.next(5), 2); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /y2022/ex10/input.txt: -------------------------------------------------------------------------------- 1 | addx 2 2 | addx 3 3 | addx 3 4 | addx -2 5 | addx 4 6 | noop 7 | addx 1 8 | addx 4 9 | addx 1 10 | noop 11 | addx 4 12 | addx 1 13 | noop 14 | addx 2 15 | addx 5 16 | addx -28 17 | addx 30 18 | noop 19 | addx 5 20 | addx 1 21 | noop 22 | addx -38 23 | noop 24 | noop 25 | noop 26 | noop 27 | addx 5 28 | addx 5 29 | addx 3 30 | addx 2 31 | addx -2 32 | addx 2 33 | noop 34 | noop 35 | addx -2 36 | addx 12 37 | noop 38 | addx 2 39 | addx 3 40 | noop 41 | addx 2 42 | addx -31 43 | addx 32 44 | addx 7 45 | noop 46 | addx -2 47 | addx -37 48 | addx 1 49 | addx 5 50 | addx 1 51 | noop 52 | addx 31 53 | addx -25 54 | addx -10 55 | addx 13 56 | noop 57 | noop 58 | addx 18 59 | addx -11 60 | addx 3 61 | noop 62 | noop 63 | addx 1 64 | addx 4 65 | addx -32 66 | addx 15 67 | addx 24 68 | addx -2 69 | noop 70 | addx -37 71 | noop 72 | noop 73 | noop 74 | addx 5 75 | addx 5 76 | addx 21 77 | addx -20 78 | noop 79 | addx 6 80 | addx 19 81 | addx -5 82 | addx -8 83 | addx -22 84 | addx 26 85 | addx -22 86 | addx 23 87 | addx 2 88 | noop 89 | noop 90 | noop 91 | addx 8 92 | addx -10 93 | addx -27 94 | addx 33 95 | addx -27 96 | noop 97 | addx 34 98 | addx -33 99 | addx 2 100 | addx 19 101 | addx -12 102 | addx 11 103 | addx -20 104 | addx 12 105 | addx 18 106 | addx -11 107 | addx -14 108 | addx 15 109 | addx 2 110 | noop 111 | addx 3 112 | addx 2 113 | noop 114 | noop 115 | noop 116 | addx -33 117 | noop 118 | addx 1 119 | addx 2 120 | noop 121 | addx 3 122 | addx 4 123 | noop 124 | addx 1 125 | addx 2 126 | noop 127 | noop 128 | addx 7 129 | addx 1 130 | noop 131 | addx 4 132 | addx -17 133 | addx 18 134 | addx 5 135 | addx -1 136 | addx 5 137 | addx 1 138 | noop 139 | noop 140 | noop 141 | noop -------------------------------------------------------------------------------- /y2020/ex01/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashSet; 2 | 3 | pub fn part1(values: Vec) -> u32 { 4 | let idx: HashSet = values.iter().cloned().collect(); 5 | for v in values { 6 | let complement = 2020 - v; 7 | if idx.contains(&complement) { 8 | return v * complement; 9 | } 10 | } 11 | panic!("Solution not found"); 12 | } 13 | 14 | pub fn part2(values: Vec) -> u32 { 15 | let idx: HashSet = values.iter().cloned().collect(); 16 | for (i, v) in values.iter().enumerate() { 17 | for k in values.iter().skip(i) { 18 | if v + k > 2020 { 19 | continue; 20 | } 21 | let complement = 2020 - (v + k); 22 | if idx.contains(&complement) { 23 | return complement * v * k; 24 | } 25 | } 26 | } 27 | panic!("Solution not found"); 28 | } 29 | 30 | #[cfg(test)] 31 | mod tests { 32 | use super::*; 33 | #[test] 34 | fn part_1() { 35 | let input = include_str!("../input.txt"); 36 | let values: Vec = input 37 | .lines() 38 | .map(|l| { 39 | l.parse::() 40 | .unwrap_or_else(|_| panic!("Cannot convert line '{:?}' to u32", l)) 41 | }) 42 | .collect(); 43 | assert_eq!(part1(values), 866436); 44 | } 45 | 46 | #[test] 47 | fn part_2() { 48 | let input = include_str!("../input.txt"); 49 | let values: Vec = input 50 | .lines() 51 | .map(|l| { 52 | l.parse::() 53 | .unwrap_or_else(|_| panic!("Cannot convert line '{:?}' to u32", l)) 54 | }) 55 | .collect(); 56 | assert_eq!(part2(values), 276650720); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /y2022/ex10/sample_input.txt: -------------------------------------------------------------------------------- 1 | addx 15 2 | addx -11 3 | addx 6 4 | addx -3 5 | addx 5 6 | addx -1 7 | addx -8 8 | addx 13 9 | addx 4 10 | noop 11 | addx -1 12 | addx 5 13 | addx -1 14 | addx 5 15 | addx -1 16 | addx 5 17 | addx -1 18 | addx 5 19 | addx -1 20 | addx -35 21 | addx 1 22 | addx 24 23 | addx -19 24 | addx 1 25 | addx 16 26 | addx -11 27 | noop 28 | noop 29 | addx 21 30 | addx -15 31 | noop 32 | noop 33 | addx -3 34 | addx 9 35 | addx 1 36 | addx -3 37 | addx 8 38 | addx 1 39 | addx 5 40 | noop 41 | noop 42 | noop 43 | noop 44 | noop 45 | addx -36 46 | noop 47 | addx 1 48 | addx 7 49 | noop 50 | noop 51 | noop 52 | addx 2 53 | addx 6 54 | noop 55 | noop 56 | noop 57 | noop 58 | noop 59 | addx 1 60 | noop 61 | noop 62 | addx 7 63 | addx 1 64 | noop 65 | addx -13 66 | addx 13 67 | addx 7 68 | noop 69 | addx 1 70 | addx -33 71 | noop 72 | noop 73 | noop 74 | addx 2 75 | noop 76 | noop 77 | noop 78 | addx 8 79 | noop 80 | addx -1 81 | addx 2 82 | addx 1 83 | noop 84 | addx 17 85 | addx -9 86 | addx 1 87 | addx 1 88 | addx -3 89 | addx 11 90 | noop 91 | noop 92 | addx 1 93 | noop 94 | addx 1 95 | noop 96 | noop 97 | addx -13 98 | addx -19 99 | addx 1 100 | addx 3 101 | addx 26 102 | addx -30 103 | addx 12 104 | addx -1 105 | addx 3 106 | addx 1 107 | noop 108 | noop 109 | noop 110 | addx -9 111 | addx 18 112 | addx 1 113 | addx 2 114 | noop 115 | noop 116 | addx 9 117 | noop 118 | noop 119 | noop 120 | addx -1 121 | addx 2 122 | addx -37 123 | addx 1 124 | addx 3 125 | noop 126 | addx 15 127 | addx -21 128 | addx 22 129 | addx -6 130 | addx 1 131 | noop 132 | addx 2 133 | addx 1 134 | noop 135 | addx -10 136 | noop 137 | noop 138 | addx 20 139 | addx 1 140 | addx 2 141 | addx 2 142 | addx -6 143 | addx -11 144 | noop 145 | noop 146 | noop -------------------------------------------------------------------------------- /y2023/ex07/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::BinaryHeap; 2 | 3 | use models_p2::HandWithBetP2; 4 | mod models; 5 | mod models_p2; 6 | 7 | pub fn part1(input: &str) -> u64 { 8 | let mut hands_heap = BinaryHeap::new(); 9 | for line in input.lines() { 10 | let (_, hand_with_bet) = models::parse_hand_with_bet(line).unwrap(); 11 | hands_heap.push(hand_with_bet); // reverse makes it a min heap 12 | } 13 | 14 | hands_heap 15 | .into_sorted_vec() 16 | .iter() 17 | .enumerate() 18 | .map(|(i, hand_with_bet)| (i + 1) as u64 * hand_with_bet.bet) 19 | .sum() 20 | } 21 | 22 | pub fn part2(input: &str) -> u64 { 23 | let mut hands_heap: BinaryHeap = BinaryHeap::new(); 24 | for line in input.lines() { 25 | let (_, hand_with_bet) = models::parse_hand_with_bet(line).unwrap(); 26 | hands_heap.push(hand_with_bet.into()); // reverse makes it a min heap 27 | } 28 | 29 | hands_heap 30 | .into_sorted_vec() 31 | .iter() 32 | .enumerate() 33 | .map(|(i, hand_with_bet)| (i + 1) as u64 * hand_with_bet.bet) 34 | .sum() 35 | } 36 | 37 | #[cfg(test)] 38 | mod tests { 39 | use super::*; 40 | const INPUT: &str = include_str!("../input.txt"); 41 | const EXAMPLE_INPUT: &str = "32T3K 765 42 | T55J5 684 43 | KK677 28 44 | KTJJT 220 45 | QQQJA 483"; 46 | 47 | #[test] 48 | fn test_part1_example() { 49 | assert_eq!(part1(EXAMPLE_INPUT), 6440); 50 | } 51 | 52 | #[test] 53 | fn test_part1() { 54 | assert_eq!(part1(INPUT), 248217452); 55 | } 56 | 57 | #[test] 58 | fn test_part2_example() { 59 | assert_eq!(part2(EXAMPLE_INPUT), 5905); 60 | } 61 | 62 | #[test] 63 | fn test_part2() { 64 | assert_eq!(part2(INPUT), 245576185); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /y2025/ex01/src/dial.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 2 | pub(crate) struct Dial { 3 | pub position: u8, 4 | } 5 | 6 | impl Dial { 7 | pub fn new() -> Self { 8 | Self { position: 50 } 9 | } 10 | 11 | pub fn turn_left(&mut self, steps: u16) -> u16 { 12 | let cycle = 100; 13 | 14 | // 1. Count full revolutions (each full spin hits 0 once) 15 | let full_wraps = steps / cycle; 16 | 17 | // 2. Check the remaining partial turn 18 | let remainder = steps % cycle; 19 | 20 | // We hit 0 if we step back enough to reach it. 21 | // If we are at 50, we need 50 steps to hit 0. 22 | // If we are at 0, stepping left goes to 99 (doesn't count). 23 | let extra_wrap = if self.position > 0 && remainder >= self.position as u16 { 24 | 1 25 | } else { 26 | 0 27 | }; 28 | 29 | // Update position using Rem_Euclid for safety with negative numbers 30 | self.position = ((self.position as i16 - steps as i16).rem_euclid(cycle as i16)) as u8; 31 | 32 | full_wraps + extra_wrap 33 | } 34 | 35 | // O(1) Time Complexity 36 | pub fn turn_right(&mut self, steps: u16) -> u16 { 37 | let cycle = 100; 38 | 39 | // 1. Count full revolutions 40 | let full_wraps = steps / cycle; 41 | 42 | // 2. Check the remaining partial turn 43 | let remainder = steps % cycle; 44 | 45 | // We hit 0 if current + remainder spills over 100 46 | let extra_wrap = if (self.position as u16 + remainder) >= cycle { 47 | 1 48 | } else { 49 | 0 50 | }; 51 | 52 | // Update position 53 | self.position = ((self.position as i16 + steps as i16).rem_euclid(cycle as i16)) as u8; 54 | 55 | full_wraps + extra_wrap 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /y2020/ex05/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashSet; 2 | 3 | fn seatid_to_int(input: &str) -> u16 { 4 | let bin_str = input 5 | .chars() 6 | .map(|c| match c { 7 | 'F' | 'L' => '0', 8 | 'B' | 'R' => '1', 9 | _ => panic!("Unexpected character"), 10 | }) 11 | .collect::(); 12 | u16::from_str_radix(&bin_str, 2).expect("Cannot convert bin_str to u16") 13 | } 14 | 15 | pub fn part1(input: &str) -> u16 { 16 | // The problem is basically asking us to convert a binary number to integer. 17 | // If we take an example input such as `FBFBBFFRLR` we can convert F and L to 0 and B and R to 1 and we get `0101100101`. 18 | // If we then get the integer representation of that binary we get the integer ID of a given seat. 19 | // This calculation is done in `seatid_to_int`, so we map every input line to that and then we take the max. 20 | let seat_ids = input.lines().map(seatid_to_int).collect::>(); 21 | *seat_ids.iter().max().expect("List of ids cannot be empty") 22 | } 23 | 24 | pub fn part2(input: &str) -> u16 { 25 | let seat_ids = input.lines().map(seatid_to_int).collect::>(); 26 | 27 | for current_seat in &seat_ids { 28 | let next_seat = current_seat + 1; 29 | let next_next_seat = &next_seat + 1; 30 | if !seat_ids.contains(&next_seat) && seat_ids.contains(&next_next_seat) { 31 | return next_seat; 32 | } 33 | } 34 | 35 | panic!("Couldn't find our seat!") 36 | } 37 | 38 | #[cfg(test)] 39 | mod tests { 40 | use super::*; 41 | 42 | #[test] 43 | fn part_1() { 44 | let input = include_str!("../input.txt"); 45 | assert_eq!(part1(input), 835); 46 | } 47 | 48 | #[test] 49 | fn part_2() { 50 | let input = include_str!("../input.txt"); 51 | assert_eq!(part2(input), 649); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /y2020/ex06/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashSet; 2 | 3 | pub fn part1(input: &str) -> usize { 4 | let mut answers = 0; 5 | 6 | let mut question_answers_set = HashSet::new(); 7 | for line in input.lines() { 8 | if line.is_empty() { 9 | answers += question_answers_set.len(); 10 | question_answers_set.clear(); 11 | } else { 12 | for c in line.chars() { 13 | question_answers_set.insert(c); 14 | } 15 | } 16 | } 17 | // This is for the last answers (in case there is no empty line after) 18 | answers += question_answers_set.len(); 19 | answers 20 | } 21 | 22 | pub fn part2(input: &str) -> usize { 23 | let mut answers = 0; 24 | // this is true only for the first line of a block of answers 25 | let mut is_first = true; 26 | 27 | let mut question_answers_set = HashSet::new(); 28 | for line in input.lines() { 29 | if line.is_empty() { 30 | answers += question_answers_set.len(); 31 | question_answers_set.clear(); 32 | is_first = true; 33 | } else if is_first { 34 | question_answers_set = line.chars().collect(); 35 | is_first = false; 36 | } else { 37 | question_answers_set = question_answers_set 38 | .intersection(&line.chars().collect()) 39 | .copied() 40 | .collect(); 41 | } 42 | } 43 | 44 | answers += question_answers_set.len(); 45 | answers 46 | } 47 | 48 | #[cfg(test)] 49 | mod tests { 50 | use super::*; 51 | 52 | #[test] 53 | fn part_1() { 54 | let input = include_str!("../input.txt"); 55 | assert_eq!(part1(input), 6726) 56 | } 57 | 58 | #[test] 59 | fn part_2() { 60 | let input = include_str!("../input.txt"); 61 | assert_eq!(part2(input), 3316) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /y2022/ex25/input.txt: -------------------------------------------------------------------------------- 1 | 1=-=2=-1000=0 2 | 11=001122 3 | 120- 4 | 1-0 5 | 202-0==-2- 6 | 2-1010=2-2=01 7 | 112=-2 8 | 2-0= 9 | 1-=2-=-1-0--0=1=0000 10 | 1=0=0--021-0 11 | 11000101=210 12 | 21-111=2112=2==- 13 | 111010-2 14 | 2=10=-101-=--0 15 | 2-=-2000012=0022= 16 | 1-=11-01--2100 17 | 1=2211-2-=== 18 | 2=--2-==-1 19 | 1=12---02=2 20 | 1==0=--11=01-1- 21 | 121-21021 22 | 12=1001=2=-=22 23 | 1=2-212=2-0211 24 | 20----11= 25 | 10=100=0=0 26 | 111 27 | 1=--011==2--212121= 28 | 2=-10=210200-2-=0 29 | 1=-122=001-1 30 | 2-0=0121=-0=0 31 | 2-=20--1-=21-22=1= 32 | 20011 33 | 12=1--=-0--10-0=1-= 34 | 2002=100=-00- 35 | 202 36 | 1=2==21- 37 | 1=221--01=00-10= 38 | 1--0-1= 39 | 2-==11=222--- 40 | 21-10-=22 41 | 1=--22-0- 42 | 2-0- 43 | 1-0=-2 44 | 20-02102 45 | 1=0=20----21=12=- 46 | 20=111-12=21101= 47 | 111=1=-2=0=--21 48 | 11- 49 | 10-1=01=- 50 | 1222-10 51 | 1=2-1 52 | 20 53 | 101==12-1-0 54 | 1-=22=--=22=1=22 55 | 1200-010-10=021 56 | 1=2-10=-02--=- 57 | 12-0=000=0 58 | 1==10=00===1-- 59 | 2-1=-=1===1=-0=--- 60 | 1=11=120 61 | 2===002010=-=0 62 | 1==00212=01-002=221 63 | 10020221===- 64 | 1--01=-=0-20-101-=- 65 | 112=101 66 | 10- 67 | 1220=1 68 | 2= 69 | 1=1120=--0 70 | 11-21200= 71 | 2==011-10-0==0=0= 72 | 12-=102 73 | 100-022 74 | 1=1 75 | 201-0--=- 76 | 2-02 77 | 21=11=00020 78 | 12=20- 79 | 1101=00-1 80 | 1=0=-11--=-010-==1 81 | 1-2-0=00=-=220=11- 82 | 2-2 83 | 12-2 84 | 12=10=2-= 85 | 20222110-10002 86 | 1002=0 87 | 12=11-=012 88 | 1== 89 | 1=00-01 90 | 110101222-020--111 91 | 2-0 92 | 1-12=1 93 | 222-10-12=00 94 | 11=1=1 95 | 10=2-00-121-2-=2 96 | 1---22-1-0=00-1220 97 | 2-=2210=-==2=010= 98 | 12201-111-220 99 | 2=122=022=22=12-1 100 | 211===2=020 101 | 121-2-0-=0==2=1 102 | 1-0221200-21100- 103 | 10 104 | 1-11 105 | 2===2=-2- 106 | 1-0-2021-21== 107 | 1==-00-=2-21===1200 108 | 22 109 | 1222=20=120=1- 110 | 11=120001012==01-1 111 | 2=-1--00 112 | 10==121--221 113 | 1=2100102=20012 114 | 2==1- 115 | 1- 116 | 10-2--0 -------------------------------------------------------------------------------- /y2022/ex14/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod cave; 2 | use cave::*; 3 | 4 | pub fn part1(input: &str) -> usize { 5 | let mut cave: Cave = input.parse().unwrap(); 6 | let abyss_line = cave.tiles.keys().map(|pos| pos.y).max().unwrap() + 1; 7 | let mut num_grains = 0; 8 | 9 | 'main_loop: loop { 10 | let mut grain_moves = cave.next_grain(); 11 | for pos in grain_moves.by_ref() { 12 | if pos.y > abyss_line { 13 | break 'main_loop; 14 | } 15 | } 16 | cave.tiles.insert(grain_moves.pos, Block::Sand); 17 | num_grains += 1; 18 | } 19 | 20 | num_grains 21 | } 22 | 23 | pub fn part2(input: &str) -> u64 { 24 | let mut cave: Cave = input.parse().unwrap(); 25 | let abyss_line = cave.tiles.keys().map(|pos| pos.y).max().unwrap() + 1; 26 | cave.floor_level = Some(abyss_line + 1); 27 | let mut num_grains = 0; 28 | 29 | loop { 30 | let mut grain_moves = cave.next_grain(); 31 | for _ in grain_moves.by_ref() { 32 | // exhausts the iterator 33 | } 34 | 35 | num_grains += 1; 36 | 37 | if grain_moves.pos == cave.sand_emitter { 38 | break; 39 | } 40 | 41 | cave.tiles.insert(grain_moves.pos, Block::Sand); 42 | } 43 | 44 | num_grains 45 | } 46 | 47 | #[cfg(test)] 48 | mod tests { 49 | use super::*; 50 | const INPUT: &str = include_str!("../input.txt"); 51 | 52 | #[test] 53 | fn test_part1_example() { 54 | let input = "498,4 -> 498,6 -> 496,6 55 | 503,4 -> 502,4 -> 502,9 -> 494,9"; 56 | assert_eq!(part1(input), 24); 57 | } 58 | 59 | #[test] 60 | fn test_part1() { 61 | assert_eq!(part1(INPUT), 913); 62 | } 63 | 64 | #[test] 65 | fn test_part2_example() { 66 | let input = "498,4 -> 498,6 -> 496,6 67 | 503,4 -> 502,4 -> 502,9 -> 494,9"; 68 | assert_eq!(part2(input), 93); 69 | } 70 | 71 | #[test] 72 | fn test_part2() { 73 | assert_eq!(part2(INPUT), 30762); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /y2022/ex03/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::str::FromStr; 2 | 3 | mod by3; 4 | 5 | fn priority(c: char) -> u64 { 6 | match c { 7 | 'a'..='z' => ((c as u32) - 96) as u64, 8 | 'A'..='Z' => ((c as u32) - 38) as u64, 9 | _ => panic!("Invalid char {c}"), 10 | } 11 | } 12 | 13 | fn find_badge(r1: Rucksack, r2: Rucksack, r3: Rucksack) -> char { 14 | for c in r1.0 { 15 | if r2.0.contains(&c) && r3.0.contains(&c) { 16 | return c; 17 | } 18 | } 19 | panic!("Cannot find badge"); 20 | } 21 | 22 | struct Rucksack(Vec); 23 | 24 | impl FromStr for Rucksack { 25 | type Err = (); 26 | 27 | fn from_str(s: &str) -> Result { 28 | Ok(Self(s.chars().collect())) 29 | } 30 | } 31 | 32 | impl Rucksack { 33 | fn compartments(&self) -> (&[char], &[char]) { 34 | let l = self.0.len(); 35 | (&(self.0[0..l / 2]), &(self.0[l / 2..l])) 36 | } 37 | 38 | fn common_item(&self) -> char { 39 | let (c_a, c_b) = self.compartments(); 40 | for c in c_a { 41 | if c_b.contains(c) { 42 | return *c; 43 | } 44 | } 45 | panic!("Rucksack does not have a common item") 46 | } 47 | } 48 | 49 | pub fn part1(input: &str) -> u64 { 50 | input 51 | .lines() 52 | .map(|l| { 53 | let r: Rucksack = l.parse().unwrap(); 54 | priority(r.common_item()) 55 | }) 56 | .sum() 57 | } 58 | 59 | pub fn part2(input: &str) -> u64 { 60 | by3::By3Iter::new(input.lines().map(|l| l.parse::().unwrap())) 61 | .map(|(r1, r2, r3)| find_badge(r1, r2, r3)) 62 | .map(priority) 63 | .sum() 64 | } 65 | 66 | #[cfg(test)] 67 | mod tests { 68 | use super::*; 69 | const INPUT: &str = include_str!("../input.txt"); 70 | 71 | #[test] 72 | fn test_part1() { 73 | assert_eq!(part1(INPUT), 7811); 74 | } 75 | 76 | #[test] 77 | fn test_part2() { 78 | assert_eq!(part2(INPUT), 2639); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /y2024/ex02/src/lib.rs: -------------------------------------------------------------------------------- 1 | fn parse_line(line: &str) -> Vec { 2 | line.split_whitespace() 3 | .map(|s| s.parse().unwrap()) 4 | .collect() 5 | } 6 | 7 | fn is_safe(reports: &[u32]) -> bool { 8 | let is_ascending = reports.windows(2).all(|w| w[0] <= w[1]); 9 | let is_descending = reports.windows(2).all(|w| w[0] >= w[1]); 10 | if !is_ascending && !is_descending { 11 | return false; 12 | } 13 | 14 | for w in reports.windows(2) { 15 | let a = w[0]; 16 | let b = w[1]; 17 | let diff = a.abs_diff(b); 18 | if !(1..=3).contains(&diff) { 19 | return false; 20 | } 21 | } 22 | 23 | true 24 | } 25 | 26 | fn is_safe_with_dampening(reports: &[u32]) -> bool { 27 | is_safe(reports) 28 | || (0..reports.len()).any(|i| { 29 | let mut reports_no_i = reports.to_vec(); 30 | reports_no_i.remove(i); 31 | is_safe(&reports_no_i) 32 | }) 33 | } 34 | 35 | pub fn part1(input: &str) -> usize { 36 | input.lines().map(parse_line).filter(|r| is_safe(r)).count() 37 | } 38 | 39 | pub fn part2(input: &str) -> usize { 40 | input 41 | .lines() 42 | .map(parse_line) 43 | .filter(|r| { 44 | println!("{:?}: {:?}", r, is_safe_with_dampening(r)); 45 | is_safe_with_dampening(r) 46 | }) 47 | .count() 48 | } 49 | 50 | #[cfg(test)] 51 | mod tests { 52 | use super::*; 53 | const INPUT: &str = include_str!("../input.txt"); 54 | const EXAMPLE_INPUT: &str = "7 6 4 2 1 55 | 1 2 7 8 9 56 | 9 7 6 2 1 57 | 1 3 2 4 5 58 | 8 6 4 4 1 59 | 1 3 6 7 9"; 60 | 61 | #[test] 62 | fn test_part1_example() { 63 | assert_eq!(part1(EXAMPLE_INPUT), 2); 64 | } 65 | 66 | #[test] 67 | fn test_part1() { 68 | assert_eq!(part1(INPUT), 371); 69 | } 70 | 71 | #[test] 72 | fn test_part2_example() { 73 | assert_eq!(part2(EXAMPLE_INPUT), 4); 74 | } 75 | 76 | #[test] 77 | fn test_part2() { 78 | assert_eq!(part2(INPUT), 426); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /y2020/ex01/input.txt: -------------------------------------------------------------------------------- 1 | 1567 2 | 1223 3 | 1758 4 | 1842 5 | 1933 6 | 1898 7 | 1409 8 | 1058 9 | 1533 10 | 1417 11 | 1032 12 | 1634 13 | 1477 14 | 1394 15 | 1888 16 | 1972 17 | 1237 18 | 1390 19 | 1677 20 | 1546 21 | 1302 22 | 1070 23 | 1369 24 | 1455 25 | 1065 26 | 1924 27 | 1593 28 | 1131 29 | 1064 30 | 1346 31 | 1914 32 | 1129 33 | 1830 34 | 1450 35 | 1278 36 | 1740 37 | 1809 38 | 1176 39 | 1734 40 | 1102 41 | 1807 42 | 1982 43 | 1603 44 | 1736 45 | 2008 46 | 1980 47 | 1905 48 | 1633 49 | 1732 50 | 1350 51 | 1865 52 | 1988 53 | 1805 54 | 1998 55 | 1152 56 | 1046 57 | 1870 58 | 1557 59 | 1789 60 | 1766 61 | 1945 62 | 1359 63 | 1002 64 | 1126 65 | 1719 66 | 1497 67 | 1296 68 | 1560 69 | 1936 70 | 1929 71 | 1464 72 | 2005 73 | 1281 74 | 618 75 | 1257 76 | 1107 77 | 1632 78 | 1688 79 | 1964 80 | 1803 81 | 1360 82 | 1384 83 | 1889 84 | 1411 85 | 1328 86 | 1452 87 | 1868 88 | 1515 89 | 1586 90 | 1631 91 | 1618 92 | 1087 93 | 1710 94 | 1094 95 | 1774 96 | 1295 97 | 1700 98 | 1636 99 | 1230 100 | 1421 101 | 1910 102 | 1522 103 | 1366 104 | 1144 105 | 1757 106 | 1493 107 | 1316 108 | 1103 109 | 687 110 | 1371 111 | 1720 112 | 1155 113 | 1559 114 | 1900 115 | 989 116 | 1367 117 | 1999 118 | 1066 119 | 1773 120 | 1787 121 | 1402 122 | 1047 123 | 1806 124 | 1956 125 | 1219 126 | 1555 127 | 1307 128 | 1419 129 | 1706 130 | 1884 131 | 1109 132 | 1181 133 | 2010 134 | 1298 135 | 1730 136 | 1078 137 | 1848 138 | 1398 139 | 1687 140 | 2007 141 | 1550 142 | 1664 143 | 1225 144 | 1079 145 | 1698 146 | 350 147 | 1222 148 | 1377 149 | 1977 150 | 1510 151 | 1571 152 | 1630 153 | 1029 154 | 1379 155 | 1942 156 | 1949 157 | 1249 158 | 1829 159 | 1297 160 | 1530 161 | 1607 162 | 1324 163 | 1069 164 | 1476 165 | 928 166 | 1039 167 | 1855 168 | 1644 169 | 1454 170 | 1310 171 | 1172 172 | 547 173 | 1034 174 | 1878 175 | 1479 176 | 1457 177 | 1319 178 | 1810 179 | 1759 180 | 1439 181 | 1851 182 | 545 183 | 1470 184 | 2003 185 | 1908 186 | 1564 187 | 1491 188 | 1174 189 | 1301 190 | 1689 191 | 1276 192 | 1781 193 | 1392 194 | 1499 195 | 1962 196 | 1653 197 | 1823 198 | 1381 199 | 1827 200 | 1974 -------------------------------------------------------------------------------- /y2021/ex23/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod amphipod; 2 | pub(crate) mod burrow; 3 | pub(crate) mod command; 4 | pub(crate) mod hole; 5 | 6 | use std::collections::{HashMap, VecDeque}; 7 | 8 | use burrow::Burrow; 9 | 10 | fn solve(burrow: Burrow) -> usize { 11 | let mut min_cost = usize::MAX; 12 | 13 | let mut states: VecDeque> = VecDeque::from([burrow]); 14 | let mut seen_states: HashMap, usize> = HashMap::new(); 15 | 16 | while let Some(state) = states.pop_back() { 17 | if state.is_final() { 18 | if state.cost < min_cost { 19 | min_cost = state.cost; 20 | } 21 | continue; 22 | } 23 | 24 | for command in state.moves() { 25 | let new_state = state.apply(&command); 26 | 27 | if new_state.cost >= min_cost { 28 | continue; 29 | } 30 | 31 | if let Some(seen_cost) = seen_states.get(&new_state) { 32 | if new_state.cost >= *seen_cost { 33 | continue; 34 | } 35 | } 36 | 37 | let seen_cost = new_state.cost; 38 | states.push_back(new_state.clone()); 39 | seen_states.insert(new_state, seen_cost); 40 | } 41 | } 42 | 43 | min_cost 44 | } 45 | 46 | pub fn part1(input: &str) -> usize { 47 | let burrow = input.parse::>().unwrap(); 48 | solve(burrow) 49 | } 50 | 51 | pub fn part2(input: &str) -> usize { 52 | let mut lines: Vec<&str> = input.lines().collect(); 53 | lines.insert(3, " #D#C#B#A#"); 54 | lines.insert(4, " #D#B#A#C#"); 55 | 56 | let new_input = lines.join("\n"); 57 | let burrow = new_input.parse::>().unwrap(); 58 | 59 | solve(burrow) 60 | } 61 | 62 | #[cfg(test)] 63 | mod tests { 64 | use super::*; 65 | const INPUT: &str = include_str!("../input.txt"); 66 | 67 | #[test] 68 | fn test_part1() { 69 | assert_eq!(part1(INPUT), 18195); 70 | } 71 | 72 | #[test] 73 | fn test_part2() { 74 | assert_eq!(part2(INPUT), 50265); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /y2022/ex04/src/lib.rs: -------------------------------------------------------------------------------- 1 | use nom::sequence::separated_pair; 2 | use nom::{character::complete::digit1, combinator::map_res, IResult}; 3 | use std::ops::RangeInclusive; 4 | use std::str::FromStr; 5 | 6 | fn parse_range(input: &str) -> IResult<&str, RangeInclusive> { 7 | let mut parser = separated_pair( 8 | map_res(digit1, u32::from_str), 9 | nom::character::complete::char('-'), 10 | map_res(digit1, u32::from_str), 11 | ); 12 | let (input, (min, max)) = parser(input)?; 13 | Ok((input, min..=max)) 14 | } 15 | 16 | fn parse_line(input: &str) -> IResult<&str, (RangeInclusive, RangeInclusive)> { 17 | let (input, first) = parse_range(input)?; 18 | let (input, _) = nom::character::complete::char(',')(input)?; 19 | let (input, second) = parse_range(input)?; 20 | Ok((input, (first, second))) 21 | } 22 | 23 | fn parse_input( 24 | input: &str, 25 | ) -> impl Iterator, RangeInclusive)> + '_ { 26 | input.lines().map(|line| parse_line(line).unwrap().1) 27 | } 28 | 29 | fn range_contains(range1: &RangeInclusive, range2: &RangeInclusive) -> bool { 30 | range1.contains(range2.start()) && range1.contains(range2.end()) 31 | } 32 | 33 | fn range_overlap(range1: &RangeInclusive, range2: &RangeInclusive) -> bool { 34 | range1.contains(range2.start()) || range2.contains(range1.start()) 35 | } 36 | 37 | pub fn part1(input: &str) -> usize { 38 | parse_input(input) 39 | .filter(|(range1, range2)| range_contains(range1, range2) || range_contains(range2, range1)) 40 | .count() 41 | } 42 | 43 | pub fn part2(input: &str) -> usize { 44 | parse_input(input) 45 | .filter(|(range1, range2)| range_overlap(range1, range2) || range_contains(range2, range1)) 46 | .count() 47 | } 48 | 49 | #[cfg(test)] 50 | mod tests { 51 | use super::*; 52 | const INPUT: &str = include_str!("../input.txt"); 53 | 54 | #[test] 55 | fn test_part1() { 56 | assert_eq!(part1(INPUT), 547); 57 | } 58 | 59 | #[test] 60 | fn test_part2() { 61 | assert_eq!(part2(INPUT), 843); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /y2024/ex01/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::{BTreeMap, BinaryHeap}; 2 | 3 | fn parse_line(line: &str) -> (usize, usize) { 4 | let mut parts = line.split_whitespace(); 5 | let left: usize = parts.next().unwrap().parse().unwrap(); 6 | let right: usize = parts.next().unwrap().parse().unwrap(); 7 | (left, right) 8 | } 9 | 10 | pub fn part1(input: &str) -> usize { 11 | let mut left_heap = BinaryHeap::new(); 12 | let mut right_heap = BinaryHeap::new(); 13 | 14 | input.lines().map(parse_line).for_each(|(left, right)| { 15 | left_heap.push(left); 16 | right_heap.push(right); 17 | }); 18 | 19 | let left_sorted = left_heap.into_sorted_vec(); 20 | let right_sorted = right_heap.into_sorted_vec(); 21 | 22 | left_sorted 23 | .iter() 24 | .zip(right_sorted.iter()) 25 | .map(|(left, right)| left.abs_diff(*right)) 26 | .sum() 27 | } 28 | 29 | pub fn part2(input: &str) -> usize { 30 | let mut left_list = Vec::new(); 31 | let mut right_list_counts = BTreeMap::new(); 32 | 33 | input.lines().map(parse_line).for_each(|(left, right)| { 34 | left_list.push(left); 35 | let entry = right_list_counts.entry(right).or_insert(0); 36 | *entry += 1; 37 | }); 38 | 39 | left_list 40 | .iter() 41 | .map(|l| { 42 | let frequency = right_list_counts.get(l).unwrap_or(&0); 43 | l * frequency 44 | }) 45 | .sum() 46 | } 47 | 48 | #[cfg(test)] 49 | mod tests { 50 | use super::*; 51 | const INPUT: &str = include_str!("../input.txt"); 52 | 53 | const EXAMPLE_INPUT: &str = "3 4 54 | 4 3 55 | 2 5 56 | 1 3 57 | 3 9 58 | 3 3"; 59 | 60 | #[test] 61 | fn test_part1_example() { 62 | assert_eq!(part1(EXAMPLE_INPUT), 11); 63 | } 64 | 65 | #[test] 66 | fn test_part1() { 67 | assert_eq!(part1(INPUT), 2113135); 68 | } 69 | 70 | #[test] 71 | fn test_part2_example() { 72 | assert_eq!(part2(EXAMPLE_INPUT), 31); 73 | } 74 | 75 | #[test] 76 | fn test_part2() { 77 | assert_eq!(part2(INPUT), 19097157); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /y2025/ex01/src/lib.rs: -------------------------------------------------------------------------------- 1 | use crate::dial::Dial; 2 | 3 | mod dial; 4 | mod parser; 5 | 6 | pub fn part1(input: &str) -> usize { 7 | let mut dial = Dial::new(); 8 | let mut times_dial_at_0 = 0; 9 | let operations = input.lines().enumerate().map(|(i, line)| { 10 | parser::parse_dial_op(&mut &*line) 11 | .expect(format!("Failed to parse line {}", i + 1).as_ref()) 12 | }); 13 | for op in operations { 14 | match op { 15 | parser::DialOp::TurnLeft(steps) => dial.turn_left(steps), 16 | parser::DialOp::TurnRight(steps) => dial.turn_right(steps), 17 | }; 18 | if dial.position == 0 { 19 | times_dial_at_0 += 1; 20 | } 21 | } 22 | times_dial_at_0 23 | } 24 | 25 | pub fn part2(input: &str) -> u32 { 26 | let mut dial = Dial::new(); 27 | let mut times_dial_at_0 = 0; 28 | let operations = input.lines().enumerate().map(|(i, line)| { 29 | parser::parse_dial_op(&mut &*line) 30 | .expect(format!("Failed to parse line {}", i + 1).as_ref()) 31 | }); 32 | for op in operations { 33 | let wraps = match op { 34 | parser::DialOp::TurnLeft(steps) => dial.turn_left(steps), 35 | parser::DialOp::TurnRight(steps) => dial.turn_right(steps), 36 | }; 37 | times_dial_at_0 += wraps as u32; 38 | } 39 | times_dial_at_0 40 | } 41 | 42 | #[cfg(test)] 43 | mod tests { 44 | use super::*; 45 | const INPUT: &str = include_str!("../input.txt"); 46 | 47 | #[test] 48 | fn test_part1_example() { 49 | let input = "L68 50 | L30 51 | R48 52 | L5 53 | R60 54 | L55 55 | L1 56 | L99 57 | R14 58 | L82"; 59 | assert_eq!(part1(input), 3); 60 | } 61 | 62 | #[test] 63 | fn test_part1() { 64 | assert_eq!(part1(INPUT), 1123); 65 | } 66 | 67 | #[test] 68 | fn test_part2_example() { 69 | let input = "L68 70 | L30 71 | R48 72 | L5 73 | R60 74 | L55 75 | L1 76 | L99 77 | R14 78 | L82"; 79 | assert_eq!(part2(input), 6); 80 | } 81 | 82 | #[test] 83 | fn test_part2() { 84 | assert_eq!(part2(INPUT), 6695); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /y2020/ex02/src/lib.rs: -------------------------------------------------------------------------------- 1 | use regex::Regex; 2 | 3 | struct Line { 4 | min: u32, 5 | max: u32, 6 | char: char, 7 | password: String, 8 | } 9 | 10 | fn parse_line(line: &str) -> Line { 11 | let re = Regex::new(r"^(\d+)-(\d+)\s([a-zA-Z]):\s([a-zA-Z]+)$").unwrap(); 12 | let capture = re.captures(line).unwrap(); 13 | 14 | Line { 15 | min: capture[1].parse().unwrap(), 16 | max: capture[2].parse().unwrap(), 17 | char: capture[3].parse().unwrap(), 18 | password: capture[4].parse().unwrap(), 19 | } 20 | } 21 | 22 | fn validate_line(line: &Line) -> bool { 23 | let occurences = line.password.matches(line.char).count() as u32; 24 | 25 | occurences >= line.min && occurences <= line.max 26 | } 27 | 28 | fn validate_line2(line: &Line) -> bool { 29 | let start_index = (line.min - 1) as usize; 30 | let end_index = (line.max - 1) as usize; 31 | (line.password.chars().nth(start_index).unwrap() == line.char) 32 | ^ (line.password.chars().nth(end_index).unwrap() == line.char) 33 | } 34 | 35 | pub fn part1(input: &str) -> u32 { 36 | input.lines().map(parse_line).filter(validate_line).count() as u32 37 | 38 | // let mut valid_count = 0; 39 | // for line in &lines { 40 | // let valid = validate_line(parse_line(line)); 41 | // if valid { 42 | // valid_count += 1; 43 | // } 44 | // } 45 | // valid_count 46 | 47 | // let mut valid_count = 0; 48 | // for line in &lines { 49 | // match validate_line(&parse_line(line)) { 50 | // true => valid_count += 1, 51 | // false => (), 52 | // } 53 | // } 54 | // valid_count 55 | } 56 | 57 | pub fn part2(input: &str) -> u32 { 58 | input.lines().map(parse_line).filter(validate_line2).count() as u32 59 | } 60 | 61 | #[cfg(test)] 62 | mod tests { 63 | use super::*; 64 | #[test] 65 | fn part_1() { 66 | let input = include_str!("../input.txt"); 67 | assert_eq!(part1(input), 454); 68 | } 69 | 70 | #[test] 71 | fn part_2() { 72 | let input = include_str!("../input.txt"); 73 | assert_eq!(part2(input), 649); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /y2023/ex14/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::Map; 2 | 3 | mod models; 4 | 5 | pub fn part1(input: &str) -> usize { 6 | let mut map: Map = input.parse().unwrap(); 7 | map.tilt_north(); 8 | map.total_load() 9 | } 10 | 11 | pub fn part2(input: &str) -> usize { 12 | let mut map: Map = input.parse().unwrap(); 13 | // from observing the data it seems that after a few cycles (depending on the input) 14 | // the total load stabilises and keeps rotating between a set of fixed values. 15 | // 16 | // idea: 17 | // - we do 100 cycles to let the system stabilise 18 | // - we take the load value (starting load value) 19 | // - we collect a repeating sequence of load values until we find a duplicate of the starting load value 20 | // - we take the difference between the two indices and we have the cycle length 21 | // - we take the remainder of (1_000_000_000 - 100) / cycle_length 22 | // - we take the load value from the repeating sequence at that index 23 | for _ in 0..100 { 24 | map.cycle(); 25 | } 26 | let starting_load = map.total_load(); 27 | let mut repeating_loads = vec![starting_load]; 28 | loop { 29 | map.cycle(); 30 | let new_load = map.total_load(); 31 | if new_load == starting_load { 32 | break; 33 | } else { 34 | repeating_loads.push(new_load); 35 | } 36 | } 37 | let cycle_length = repeating_loads.len(); 38 | let remainder = (1_000_000_000 - 100) % cycle_length; 39 | repeating_loads[remainder] 40 | } 41 | 42 | #[cfg(test)] 43 | mod tests { 44 | use super::*; 45 | const INPUT: &str = include_str!("../input.txt"); 46 | const EXAMPLE_INPUT: &str = "O....#.... 47 | O.OO#....# 48 | .....##... 49 | OO.#O....O 50 | .O.....O#. 51 | O.#..O.#.# 52 | ..O..#O..O 53 | .......O.. 54 | #....###.. 55 | #OO..#...."; 56 | 57 | #[test] 58 | fn test_part1() { 59 | assert_eq!(part1(INPUT), 109661); 60 | } 61 | 62 | #[test] 63 | fn test_part2_example() { 64 | assert_eq!(part2(EXAMPLE_INPUT), 64); 65 | } 66 | 67 | #[test] 68 | fn test_part2() { 69 | assert_eq!(part2(INPUT), 90176); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | exclude = ["rpi-pico/rp2040-full", "rpi-pico/rp2040-minimal"] 4 | members = [ 5 | "y2020/ex01", 6 | "y2020/ex02", 7 | "y2020/ex03", 8 | "y2020/ex04", 9 | "y2020/ex05", 10 | "y2020/ex06", 11 | "y2020/ex07", 12 | "y2020/ex08", 13 | "y2020/ex09", 14 | "y2020/ex10", 15 | "y2020/ex11", 16 | "y2020/ex12", 17 | "y2020/ex13", 18 | "y2020/ex14", 19 | "y2020/ex15", 20 | "y2020/ex16", 21 | "y2020/ex17", 22 | "y2020/ex18", 23 | "y2020/ex19", 24 | "y2020/ex20", 25 | "y2020/ex21", 26 | "y2020/ex22", 27 | "y2020/ex23", 28 | "y2020/ex24", 29 | "y2020/ex25", 30 | "y2021/ex01", 31 | "y2021/ex02", 32 | "y2021/ex03", 33 | "y2021/ex04", 34 | "y2021/ex05", 35 | "y2021/ex06", 36 | "y2021/ex07", 37 | "y2021/ex08", 38 | "y2021/ex09", 39 | "y2021/ex10", 40 | "y2021/ex11", 41 | "y2021/ex12", 42 | "y2021/ex13", 43 | "y2021/ex14", 44 | "y2021/ex15", 45 | "y2021/ex16", 46 | "y2021/ex17", 47 | "y2021/ex18", 48 | "y2021/ex19", 49 | "y2021/ex20", 50 | "y2021/ex21", 51 | "y2021/ex22", 52 | "y2021/ex23", 53 | "y2021/ex24", 54 | "y2021/ex25", 55 | "y2022/ex01", 56 | "y2022/ex02", 57 | "y2022/ex03", 58 | "y2022/ex04", 59 | "y2022/ex05", 60 | "y2022/ex06", 61 | "y2022/ex07", 62 | "y2022/ex08", 63 | "y2022/ex09", 64 | "y2022/ex10", 65 | "y2022/ex11", 66 | "y2022/ex12", 67 | "y2022/ex13", 68 | "y2022/ex14", 69 | "y2022/ex15", 70 | "y2022/ex25", 71 | "y2023/ex01", 72 | "y2023/ex02", 73 | "y2023/ex03", 74 | "y2023/ex04", 75 | "y2023/ex05", 76 | "y2023/ex06", 77 | "y2023/ex07", 78 | "y2023/ex08", 79 | "y2023/ex09", 80 | "y2023/ex10", 81 | "y2023/ex11", 82 | "y2023/ex12", 83 | "y2023/ex13", 84 | "y2023/ex14", 85 | "y2023/ex15", 86 | "y2023/ex16", 87 | "y2023/ex19", 88 | "y2023/ex21", 89 | "y2024/ex01", 90 | "y2024/ex02", 91 | "y2024/ex03", 92 | "y2024/ex04", 93 | "y2025/ex01", 94 | "y2025/ex02", 95 | ] 96 | 97 | [profile.bench] 98 | debug = true 99 | -------------------------------------------------------------------------------- /rpi-pico/rp2040-full/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["the rp-rs team"] 3 | edition = "2018" 4 | readme = "README.md" 5 | name = "rp2040-project-template" 6 | version = "0.1.0" 7 | resolver = "2" 8 | 9 | [dependencies] 10 | cortex-m = "0.7.3" 11 | cortex-m-rt = "0.7.0" 12 | embedded-hal = { version = "0.2.5", features=["unproven"] } 13 | embedded-time = "0.12.0" 14 | 15 | defmt = "0.3.0" 16 | defmt-rtt = "0.3.0" 17 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } 18 | 19 | # We're using a Pico by default on this template 20 | rp-pico = "0.2.0" 21 | 22 | # but you can use any BSP. Uncomment this to use the pro_micro_rp2040 BSP instead 23 | # sparkfun-pro-micro-rp2040 = "0.1.0" 24 | 25 | # If you're not going to use a Board Support Package you'll need these: 26 | # rp2040-hal = { version="0.3.0", features=["rt"] } 27 | # rp2040-boot2 = "0.2.0" 28 | 29 | # y2021ex06 = { git = "https://github.com/lmammino/rust-advent" } 30 | y2021ex06 = { path = "../../y2021/ex06" } 31 | 32 | [[bin]] 33 | name = "rp2040-full" 34 | path = "src/main.rs" 35 | 36 | # cargo build/run 37 | [profile.dev] 38 | codegen-units = 1 39 | debug = 2 40 | debug-assertions = true 41 | incremental = false 42 | opt-level = 0 43 | overflow-checks = true 44 | 45 | # cargo build/run --release 46 | [profile.release] 47 | codegen-units = 1 48 | debug = 2 49 | debug-assertions = false 50 | incremental = false 51 | lto = 'fat' 52 | opt-level = 3 53 | overflow-checks = false 54 | 55 | # do not optimize proc-macro crates = faster builds from scratch 56 | [profile.dev.build-override] 57 | codegen-units = 8 58 | debug = false 59 | debug-assertions = false 60 | opt-level = 0 61 | overflow-checks = false 62 | 63 | [profile.release.build-override] 64 | codegen-units = 8 65 | debug = false 66 | debug-assertions = false 67 | opt-level = 0 68 | overflow-checks = false 69 | 70 | # cargo test 71 | [profile.test] 72 | codegen-units = 1 73 | debug = 2 74 | debug-assertions = true 75 | incremental = false 76 | opt-level = 3 77 | overflow-checks = true 78 | 79 | # cargo test --release 80 | [profile.bench] 81 | codegen-units = 1 82 | debug = 2 83 | debug-assertions = false 84 | incremental = false 85 | lto = 'fat' 86 | opt-level = 3 87 | -------------------------------------------------------------------------------- /y2023/ex15/src/lib.rs: -------------------------------------------------------------------------------- 1 | use models::{parse_command, Boxes}; 2 | 3 | use crate::models::{CommandOperation, Lens}; 4 | 5 | mod models; 6 | 7 | fn hash(s: &str) -> u64 { 8 | let mut h = 0; 9 | for c in s.chars() { 10 | let ascii_value = c as u64; 11 | h += ascii_value; 12 | h *= 17; 13 | h %= 256; 14 | } 15 | h 16 | } 17 | 18 | pub fn part1(input: &str) -> u64 { 19 | input.split(',').map(hash).sum() 20 | } 21 | 22 | pub fn part2(input: &str) -> u64 { 23 | let mut boxes = Boxes::new(); 24 | input.split(',').for_each(|s| { 25 | let (_, command) = parse_command(s).unwrap(); 26 | let box_id = hash(command.label) as usize; 27 | let box_ = boxes.get_mut(box_id).unwrap(); 28 | let same_label_idx = box_ 29 | .lenses 30 | .iter() 31 | .position(|lens| lens.name == command.label); 32 | match command.command { 33 | CommandOperation::Add(focal_length) => { 34 | let lens = Lens::new(command.label, focal_length as u64); 35 | if let Some(idx) = same_label_idx { 36 | // replace the lens if it exists 37 | box_.lenses[idx] = lens; 38 | } else { 39 | // append it otherwise 40 | box_.lenses.push(lens); 41 | } 42 | } 43 | CommandOperation::Remove => { 44 | if let Some(idx) = same_label_idx { 45 | box_.lenses.remove(idx); 46 | } 47 | } 48 | } 49 | }); 50 | 51 | boxes.focusing_power() 52 | } 53 | 54 | #[cfg(test)] 55 | mod tests { 56 | use super::*; 57 | const INPUT: &str = include_str!("../input.txt"); 58 | const INPUT_EXAMPLE: &str = "rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7"; 59 | 60 | #[test] 61 | fn test_part1() { 62 | assert_eq!(part1(INPUT), 519603); 63 | } 64 | 65 | #[test] 66 | fn test_part2_example() { 67 | assert_eq!(part2(INPUT_EXAMPLE), 145); 68 | } 69 | 70 | #[test] 71 | fn test_part2() { 72 | assert_eq!(part2(INPUT), 244342); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /y2021/ex19/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod point3d; 2 | mod scanner; 3 | use std::collections::HashSet; 4 | use point3d::*; 5 | use scanner::*; 6 | 7 | fn process_scanners (mut unknown_scanners: Vec) -> Vec { 8 | let mut first_scanner = unknown_scanners.remove(0); 9 | first_scanner.position = Some(Point3D(0,0,0)); 10 | let mut known_scanners: Vec = vec![first_scanner]; 11 | 12 | while !unknown_scanners.is_empty() { 13 | let known_scanner_length = known_scanners.len(); 14 | for i in 0..known_scanner_length { 15 | for j in (0..unknown_scanners.len()).rev() { 16 | if let Some(matched_scanner) = known_scanners[i].matches(&unknown_scanners[j]) { 17 | known_scanners.push(matched_scanner); 18 | unknown_scanners.remove(j); 19 | } 20 | } 21 | } 22 | } 23 | 24 | known_scanners 25 | } 26 | 27 | pub fn part1(input: &str) -> usize { 28 | let unknown_scanners = scanners_from_input(input); 29 | let known_scanners = process_scanners(unknown_scanners); 30 | 31 | let points: HashSet = known_scanners.iter().flat_map(|s| s.beacons.clone()).collect(); 32 | points.len() 33 | } 34 | 35 | pub fn part2(input: &str) -> i32 { 36 | let unknown_scanners = scanners_from_input(input); 37 | let known_scanners = process_scanners(unknown_scanners); 38 | 39 | let mut max_distance = 0; 40 | for s1 in &known_scanners { 41 | for s2 in &known_scanners { 42 | let pos1 = s1.position.unwrap(); 43 | let pos2 = s2.position.unwrap(); 44 | let distance = (pos1.0 - pos2.0).abs() + (pos1.1 - pos2.1).abs() + (pos1.2 - pos2.2).abs(); 45 | 46 | max_distance = distance.max(max_distance); 47 | } 48 | } 49 | 50 | 51 | max_distance 52 | } 53 | 54 | #[cfg(test)] 55 | mod tests { 56 | use super::*; 57 | 58 | #[test] 59 | fn test_part1() { 60 | let input = include_str!("../input.txt"); 61 | assert_eq!(part1(input), 414); 62 | } 63 | 64 | #[test] 65 | fn test_part2() { 66 | let input = include_str!("../input.txt"); 67 | assert_eq!(part2(input), 13000); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /y2020/ex15/src/lib.rs: -------------------------------------------------------------------------------- 1 | fn game(input: &str) -> usize { 2 | let start_vals: Vec = input 3 | .split(',') 4 | .map(|x| x.parse().expect("Invalid input")) 5 | .collect(); 6 | 7 | let mut occurrence = vec![0_usize; N].into_boxed_slice(); 8 | 9 | for (turn, n) in start_vals.iter().take(start_vals.len() - 1).enumerate() { 10 | occurrence[*n] = turn + 1; 11 | } 12 | 13 | let mut next = *start_vals.last().unwrap(); 14 | let mut new_next; 15 | for turn in start_vals.len()..N { 16 | let last_seen = occurrence.get(next).unwrap(); 17 | if *last_seen != 0 { 18 | new_next = turn - last_seen; 19 | } else { 20 | new_next = 0; 21 | } 22 | occurrence[next] = turn; 23 | next = new_next; 24 | } 25 | 26 | next 27 | } 28 | 29 | pub fn part1(input: &str) -> usize { 30 | game::<2020>(input) 31 | } 32 | 33 | pub fn part2(input: &str) -> usize { 34 | game::<30_000_000>(input) 35 | } 36 | 37 | #[cfg(test)] 38 | mod tests { 39 | use super::*; 40 | 41 | #[test] 42 | fn examples() { 43 | let expectations_2020 = [ 44 | ("1,3,2", 1), 45 | ("2,1,3", 10), 46 | ("1,2,3", 27), 47 | ("2,3,1", 78), 48 | ("3,2,1", 438), 49 | ("3,1,2", 1836), 50 | ]; 51 | 52 | let expectations_30_000_000 = [ 53 | ("0,3,6", 175594), 54 | ("1,3,2", 2578), 55 | ("2,1,3", 3544142), 56 | ("1,2,3", 261214), 57 | ("2,3,1", 6895259), 58 | ("3,2,1", 18), 59 | ("3,1,2", 362), 60 | ]; 61 | 62 | for (input, output) in expectations_2020.iter() { 63 | assert_eq!(game::<2020>(input), *output); 64 | } 65 | 66 | for (input, output) in expectations_30_000_000.iter() { 67 | assert_eq!(game::<30_000_000>(input), *output); 68 | } 69 | } 70 | 71 | #[test] 72 | fn part_1() { 73 | let input = include_str!("../input.txt"); 74 | assert_eq!(part1(input), 232); 75 | } 76 | 77 | #[test] 78 | fn part_2() { 79 | let input = include_str!("../input.txt"); 80 | assert_eq!(part2(input), 18929178); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /y2020/ex01/README.md: -------------------------------------------------------------------------------- 1 | # Day 1: Report Repair 2 | 3 | [Check it out on adventofcode.com](https://adventofcode.com/2020/day/1) 4 | 5 | 6 | ## Part One 7 | 8 | After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you. 9 | 10 | The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room. 11 | 12 | To save your vacation, you need to get all fifty stars by December 25th. 13 | 14 | Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! 15 | 16 | Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up. 17 | 18 | Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together. 19 | 20 | For example, suppose your expense report contained the following: 21 | 22 | ``` 23 | 1721 24 | 979 25 | 366 26 | 299 27 | 675 28 | 1456 29 | ``` 30 | 31 | In this list, the two entries that sum to `2020` are `1721` and `299`. Multiplying them together produces `1721 * 299 = 514579`, so the correct answer is `514579`. 32 | 33 | Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together? 34 | 35 | Your puzzle answer was `866436`. 36 | 37 | ## Part Two 38 | 39 | The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria. 40 | 41 | Using the above example again, the three entries that sum to `2020` are `979`, `366`, and `675`. Multiplying them together produces the answer, `241861950`. 42 | 43 | In your expense report, what is the product of the three entries that sum to 2020? 44 | 45 | Your puzzle answer was `276650720`. 46 | -------------------------------------------------------------------------------- /y2022/ex11/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod expr; 2 | mod monkey; 3 | mod parser; 4 | use monkey::*; 5 | use parser::*; 6 | use std::collections::HashMap; 7 | 8 | fn solve(input: &str, worry_reduction: u64, turns: usize) -> u64 { 9 | let mut monkeys: Vec = parse_input(input).collect(); 10 | let mut inspections: HashMap = HashMap::new(); 11 | let max_multiplier: u64 = monkeys.iter().map(|m| m.test_divisible_by).product(); 12 | 13 | for _round in 0..turns { 14 | for monkey_id in 0..monkeys.len() { 15 | for _ in 0..monkeys[monkey_id].items.len() { 16 | let monkey = monkeys.get_mut(monkey_id).unwrap(); 17 | let worry = monkey.items.pop_front().unwrap(); 18 | 19 | let new_worry = 20 | (monkey.operation.eval(worry, worry) % max_multiplier) / worry_reduction; 21 | 22 | let throw_to_monkey = if new_worry % monkey.test_divisible_by == 0 { 23 | monkey.if_true 24 | } else { 25 | monkey.if_false 26 | }; 27 | 28 | let other_monkey = monkeys.get_mut(throw_to_monkey as usize).unwrap(); 29 | other_monkey.items.push_back(new_worry); 30 | 31 | let entry = inspections.entry(monkey_id).or_default(); 32 | *entry += 1; 33 | } 34 | } 35 | } 36 | 37 | // multiple top 2 inspections 38 | let mut result: Vec<(usize, u64)> = inspections.into_iter().collect(); 39 | result.sort_by_key(|(_, v)| *v); 40 | result.iter().rev().take(2).map(|(_, v)| *v).product() 41 | } 42 | 43 | pub fn part1(input: &str) -> u64 { 44 | solve(input, 3, 20) 45 | } 46 | 47 | pub fn part2(input: &str) -> u64 { 48 | solve(input, 1, 10_000) 49 | } 50 | 51 | #[cfg(test)] 52 | mod tests { 53 | use super::*; 54 | const INPUT: &str = include_str!("../input.txt"); 55 | const EXAMPLE_INPUT: &str = include_str!("../input_example.txt"); 56 | 57 | #[test] 58 | fn test_part1_example() { 59 | assert_eq!(part1(EXAMPLE_INPUT), 10605); 60 | } 61 | 62 | #[test] 63 | fn test_part1() { 64 | assert_eq!(part1(INPUT), 50830); 65 | } 66 | 67 | #[test] 68 | fn test_part2() { 69 | assert_eq!(part2(INPUT), 14399640002); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /y2020/ex09/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::collections::{HashSet, VecDeque}; 2 | 3 | fn check(value: &u64, set: &HashSet) -> bool { 4 | for a in set { 5 | if a > value { 6 | continue; 7 | } 8 | let b = value - a; 9 | if set.contains(&b) { 10 | return true; 11 | } 12 | } 13 | false 14 | } 15 | 16 | pub fn part1(input: &str) -> u64 { 17 | let mut values = input.lines().map(|l| { 18 | l.parse::() 19 | .unwrap_or_else(|_| panic!("Cannot convert line '{:?}' to u64", l)) 20 | }); 21 | 22 | let mut idx: HashSet = HashSet::new(); 23 | let mut queue: VecDeque = VecDeque::new(); 24 | 25 | for _ in 0..25 { 26 | let next_value = values.next().expect("no enougth data to start"); 27 | idx.insert(next_value); 28 | queue.push_back(next_value); 29 | } 30 | 31 | for value in values { 32 | if !check(&value, &idx) { 33 | return value; 34 | } 35 | let remove = queue.pop_front().unwrap(); 36 | queue.push_back(value); 37 | idx.remove(&remove); 38 | idx.insert(value); 39 | } 40 | 41 | 0 42 | } 43 | 44 | pub fn part2(input: &str) -> u64 { 45 | let to_find = part1(input); 46 | let values: Vec = input 47 | .lines() 48 | .map(|l| { 49 | l.parse::() 50 | .unwrap_or_else(|_| panic!("Cannot convert line '{:?}' to u64", l)) 51 | }) 52 | .collect(); 53 | for window in 2..values.len() { 54 | for start in 0..(values.len() - window) { 55 | let segment = &values[start..start + window]; 56 | let sum: u64 = segment.iter().sum(); 57 | if to_find == sum { 58 | let min = segment.iter().min().unwrap(); 59 | let max = segment.iter().max().unwrap(); 60 | return min + max; 61 | } 62 | } 63 | } 64 | 0 65 | } 66 | 67 | #[cfg(test)] 68 | mod tests { 69 | use super::*; 70 | #[test] 71 | fn part_1() { 72 | let input = include_str!("../input.txt"); 73 | assert_eq!(part1(input), 1492208709); 74 | } 75 | 76 | #[test] 77 | fn part_2() { 78 | let input = include_str!("../input.txt"); 79 | assert_eq!(part2(input), 238243506); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /y2025/ex02/src/utils.rs: -------------------------------------------------------------------------------- 1 | pub(crate) fn is_id_invalid(id: u64) -> bool { 2 | let digits: Vec = id 3 | .to_string() 4 | .chars() 5 | .map(|c| c.to_digit(10).unwrap() as u8) 6 | .collect(); 7 | 8 | digits.len() % 2 == 0 && digits[0..digits.len() / 2] == digits[digits.len() / 2..] 9 | } 10 | 11 | pub(crate) fn is_id_invalid_p2(id: u64) -> bool { 12 | let digits: Vec = id 13 | .to_string() 14 | .chars() 15 | .map(|c| c.to_digit(10).unwrap() as u8) 16 | .collect(); 17 | 18 | let len = digits.len(); 19 | if len > 1 { 20 | for i in 1..len { 21 | if len % i == 0 { 22 | // needs to split the string in i-sized chunks 23 | let chunks = digits.chunks(i); 24 | let first_chunk = chunks.clone().next().unwrap(); 25 | let different_chunk = chunks.skip(1).find(|chunk| *chunk != first_chunk); 26 | if different_chunk.is_none() { 27 | return true; 28 | } 29 | } 30 | } 31 | } 32 | false 33 | } 34 | 35 | #[cfg(test)] 36 | mod tests { 37 | use super::*; 38 | 39 | #[test] 40 | fn test_is_id_invalid() { 41 | assert!(is_id_invalid(11)); 42 | assert!(is_id_invalid(22)); 43 | assert!(is_id_invalid(99)); 44 | assert!(is_id_invalid(1010)); 45 | assert!(is_id_invalid(1188511885)); 46 | assert!(is_id_invalid(222222)); 47 | assert!(is_id_invalid(446446)); 48 | assert!(is_id_invalid(38593859)); 49 | } 50 | 51 | #[test] 52 | fn test_is_id_invalid_p2() { 53 | assert!(is_id_invalid_p2(11)); 54 | assert!(is_id_invalid_p2(22)); 55 | assert!(is_id_invalid_p2(99)); 56 | assert!(is_id_invalid_p2(111)); 57 | assert!(is_id_invalid_p2(999)); 58 | assert!(is_id_invalid_p2(1010)); 59 | assert!(is_id_invalid_p2(1188511885)); 60 | assert!(is_id_invalid_p2(222222)); 61 | assert!(is_id_invalid_p2(446446)); 62 | assert!(is_id_invalid_p2(38593859)); 63 | assert!(is_id_invalid_p2(565656)); 64 | assert!(is_id_invalid_p2(824824824)); 65 | assert!(is_id_invalid_p2(2121212121)); 66 | assert!(!is_id_invalid_p2(112)); 67 | assert!(!is_id_invalid_p2(1123)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /y2022/ex08/src/map.rs: -------------------------------------------------------------------------------- 1 | use crate::{cell_iter::CellIterator, dir_iter::Dir, dir_iter::DirIterator}; 2 | use std::{ops::Deref, str::FromStr}; 3 | 4 | #[derive(Debug)] 5 | pub(crate) struct Map { 6 | grid: Vec>, 7 | width: usize, 8 | height: usize, 9 | } 10 | 11 | impl FromStr for Map { 12 | type Err = (); 13 | 14 | fn from_str(s: &str) -> Result { 15 | let grid: Vec> = s 16 | .lines() 17 | .map(|line| { 18 | line.chars() 19 | .map(|c| c.to_digit(10).unwrap() as u8) 20 | .collect() 21 | }) 22 | .collect(); 23 | 24 | Ok(Map { 25 | height: grid.len(), 26 | width: grid.get(0).map(|l| l.len()).unwrap_or(0), 27 | grid, 28 | }) 29 | } 30 | } 31 | 32 | impl Deref for Map { 33 | type Target = Vec>; 34 | 35 | fn deref(&self) -> &Self::Target { 36 | &self.grid 37 | } 38 | } 39 | 40 | impl Map { 41 | pub fn iter_cells(&self) -> CellIterator<'_, u8> { 42 | CellIterator::new(&self.grid) 43 | } 44 | 45 | pub fn iters_from_cell(&self, row: usize, col: usize) -> [DirIterator<'_, u8>; 4] { 46 | [ 47 | DirIterator::new(&self.grid, row, col, Dir::Up), 48 | DirIterator::new(&self.grid, row, col, Dir::Right), 49 | DirIterator::new(&self.grid, row, col, Dir::Down), 50 | DirIterator::new(&self.grid, row, col, Dir::Left), 51 | ] 52 | } 53 | 54 | pub fn all_outer_lines_of_sight(&self) -> Vec> { 55 | let mut res = Vec::new(); 56 | // top-down 57 | for col in 0..self.height { 58 | res.push(DirIterator::new(&self.grid, 0, col, Dir::Down)); 59 | } 60 | 61 | // right-left 62 | for row in 0..self.width { 63 | res.push(DirIterator::new(&self.grid, row, self.width - 1, Dir::Left)); 64 | } 65 | 66 | // down-up 67 | for col in (0..self.width).rev() { 68 | res.push(DirIterator::new(&self.grid, self.height - 1, col, Dir::Up)); 69 | } 70 | 71 | // left-right 72 | for row in (0..self.height).rev() { 73 | res.push(DirIterator::new(&self.grid, row, 0, Dir::Right)); 74 | } 75 | 76 | res 77 | } 78 | } 79 | --------------------------------------------------------------------------------