Compare commits

...

19 Commits

Author SHA1 Message Date
71db768227 Day 12 2025-12-13 15:51:59 +00:00
26d64ba4c9 Day 11 - Cleanup 2025-12-12 00:23:51 +00:00
9ef7abed94 Day 11 2025-12-12 00:17:07 +00:00
8bf230ff8f Day 10 2025-12-11 23:23:48 +00:00
f5bb2869d3 Day 9 - Cleanup 2025-12-09 22:17:22 +00:00
ed9f009bec Day 9 - General sol 2025-12-09 22:07:25 +00:00
31fa002b1b Day 9 2025-12-09 20:31:55 +00:00
fe3aa98c22 Day 8 - Cleanup 2025-12-08 20:03:25 +00:00
0445bde6c1 Day 8 2025-12-08 19:55:52 +00:00
57690eb2b8 Day 7 - Cleanup 2025-12-07 09:21:12 +00:00
7725299b31 Day 7 2025-12-07 09:07:21 +00:00
6ea12e5a8b Day 6 - Some cleanup 2025-12-06 09:17:19 +00:00
9a450ba973 Day 6 2025-12-06 08:48:07 +00:00
904fb64445 Day 5 - Played arround with iterators 2025-12-05 22:36:56 +00:00
71954ac209 Day 5 2025-12-05 18:36:10 +00:00
8c41171fa9 Day 4 - Cleanup 2025-12-04 18:49:36 +00:00
1cced06ddd Day 4 2025-12-04 18:44:18 +00:00
d10657a1d3 Day 3 - cleanup 2025-12-03 22:42:39 +00:00
2eddcb15e7 Day 3 2025-12-03 21:33:37 +00:00
36 changed files with 7728 additions and 0 deletions

52
.zed/debug.json Normal file
View File

@@ -0,0 +1,52 @@
// Project-local debug tasks
//
// For more documentation on how to configure debug tasks,
// see: https://zed.dev/docs/debugger
[
{
"adapter": "CodeLLDB",
"label": "cargo run -p aoc",
"build": {
"label": "cargo run -p aoc",
"command": "cargo",
"args": ["build", "--package", "aoc"],
"env": {
"RUSTC_TOOLCHAIN": "/home/sylv/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu",
},
"cwd": "/home/sylv/Documents/my-repos/aoc",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"reveal_target": "dock",
"hide": "never",
"tags": [],
"shell": "system",
"show_summary": false,
"show_command": false,
},
"sourceLanguages": ["rust"],
},
{
"adapter": "CodeLLDB",
"label": "cargo run --bin day7",
"build": {
"label": "cargo run --bin day7",
"command": "cargo",
"args": ["build", "--bin", "day7"],
"env": {
"RUSTC_TOOLCHAIN": "/home/sylv/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu",
},
"cwd": "/home/sylv/Documents/my-repos/aoc",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"reveal_target": "dock",
"hide": "never",
"tags": [],
"shell": "system",
"show_summary": false,
"show_command": false,
},
"sourceLanguages": ["rust"],
},
]

124
Cargo.lock generated
View File

@@ -13,4 +13,128 @@ name = "aoc"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"rand",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "getrandom"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "syn"
version = "2.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "zerocopy"
version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
dependencies = [
"proc-macro2",
"quote",
"syn",
] ]

View File

@@ -11,5 +11,46 @@ path = "src/day1/main.rs"
name = "day2" name = "day2"
path = "src/day2/main.rs" path = "src/day2/main.rs"
[[bin]]
name = "day3"
path = "src/day3/main.rs"
[[bin]]
name = "day4"
path = "src/day4/main.rs"
[[bin]]
name = "day5"
path = "src/day5/main.rs"
[[bin]]
name = "day6"
path = "src/day6/main.rs"
[[bin]]
name = "day7"
path = "src/day7/main.rs"
[[bin]]
name = "day8"
path = "src/day8/main.rs"
[[bin]]
name = "day9"
path = "src/day9/main.rs"
[[bin]]
name = "day10"
path = "src/day10/main.rs"
[[bin]]
name = "day11"
path = "src/day11/main.rs"
[[bin]]
name = "day12"
path = "src/day12/main.rs"
[dependencies] [dependencies]
anyhow = "1.0.100" anyhow = "1.0.100"
rand = "0.8"

22
a Normal file
View File

@@ -0,0 +1,22 @@
Found Valid ans 0
Could not Find valid answer 1
Could not Find valid answer 2
sol1: 1

189
src/day10/act.txt Normal file
View File

@@ -0,0 +1,189 @@
[.##.##] (4,5) (0,5) (2,3) (1,3,5) (0,3,5) (0,2,3,5) (0,1,4) (0,2,4,5) {198,181,22,50,173,65}
[#...##..#] (0,1,3,6,7) (0,1,4,6,7) (0,1,5,6,7,8) (0,1,3,5,7,8) (2,5) (1,4,8) (1,4,5,7,8) (3,5) (1,3,4,8) (0,2,3,4,5,7,8) (0,1,4,5,6,7,8) {38,59,4,35,41,34,31,46,43}
[.#.#.###.] (0,3,4,8) (2,4) (0,1,2,5,8) (3,4,5,6,7,8) (0,1,2,3,6,7) (1,3,5,6,7) (0,1,4,8) (0,1,3,4,7) (0,2,3) {64,47,42,52,33,35,16,20,43}
[....#] (2) (0,1,3,4) (1) (2,3,4) (1,2,3) {16,26,13,28,24}
[#..##] (3,4) (1,2,4) (0) (1,3,4) (2,3) {0,20,38,33,31}
[####.#.] (1,2,3,4,5) (0,1,2,3,4,5) (4,5) (4,5,6) (0,2,6) (0,2) (1,3,6) (0,1,2,3,5) (0,2,5) {227,70,247,70,53,75,201}
[#...###.] (1,4,7) (0,1,3,4,5,7) (0,5,6) (1,2,4,6,7) (2,3,4,5,6) (3,5) {18,27,19,35,41,35,19,27}
[#.###] (3,4) (0,1,2,4) (0,3,4) (0,2,3) (0) (1,4) (1,3) {46,23,25,58,54}
[.#.#] (0,1,2) (1,3) {9,18,9,9}
[##..##.#.] (0,1,2,3,4,7,8) (8) (0,4) (0,1,3,5,6,8) (1,3,4,5,6,7,8) (1,6) (0,2,5,7) (0,2,4) (3,4,7) (0,1,2,4,5,8) (1,3,7,8) {47,58,37,38,44,46,28,40,54}
[...#] (0,1,2) (0,3) (1,3) (3) (2,3) {12,22,9,40}
[.....#.#..] (0,1,2,3,4,6,8) (0,2,3,6,8,9) (0,2) (1,3,4,5) (0,1,2,3,4,5,6,8,9) (3) (1,3,4,6,7,8,9) (0,3,4,7,8,9) (1,5,6) (1,2,4,5,7,8,9) (2,3,4,5,7,8) (3,4,5,8) {61,66,74,87,77,53,62,59,93,68}
[.#..#] (1) (1,2) (0,1,2,3) (0,1,4) (1,3) (1,3,4) {18,69,35,36,13}
[.....#] (0,1,2,3,4,5) (1,2,3,4,5) (3,5) (0,1,2,4,5) {114,120,120,20,120,130}
[#.#.##.] (1,2,4,5) (1,5) (0,1) (3,4,5,6) (0,1,3,4,6) (1,2,3,4,5,6) (0,2,3,5) (0,1,2,5,6) {37,39,16,33,26,30,23}
[.####.####] (0,3) (2,4,6,8,9) (4,5) (0,2,3,4,5,6,9) (0,1,4,6,7,8) (0,1,2,3,5,6,7,8,9) (0,1,2,4,5,6,8,9) (1,6,7,8) (5) (8) (4,5,6,7,8) (5,7,8,9) (1,3,4,5,8) {56,62,21,50,55,57,57,49,257,21}
[....#.] (1,3,4,5) (0,1,2) (2,3,4,5) (0,1,2,4) {17,27,27,20,28,20}
[..##] (0,3) (0,2) (2,3) (1,2) {17,9,31,27}
[..###] (2,3) (0,1,4) (0,1,3) (1,3,4) (1,2,3,4) {7,12,18,30,5}
[#.##] (1,3) (0,2,3) {6,10,6,16}
[.####] (1,2,3,4) (0,2,4) (0,1,3) {18,20,10,20,10}
[####.] (0,1,2,3) (1,2,3) (1,2,4) {1,172,172,7,165}
[#.....####] (2,4,5,6,7,8) (0,2,3,4,6) (0,1,2,3,6,8,9) (0,1,2,3,4,6,8,9) (0,1,2,4,8,9) (0,1,3,4,5) (3,6,7) (0,2,6,7) (0,4) (0,2,3,4,5,6,7,9) {239,210,239,72,227,26,84,34,214,202}
[#.#.] (0,2,3) (1) (0,3) (0) (1,2) {132,14,126,116}
[###.##.#.] (1,3,6,8) (1,2,3,4,7,8) (4,7) (0,1,2,3,5,6,7) (0,2,4,6,8) (0,1,2,3,7,8) (3,5) (4,5,6) (0,1,2,3,8) (2,3,4,5,6,7,8) {17,116,121,127,148,31,33,132,122}
[.#..] (0,2) (0,1,3) (0) (2,3) (0,3) {34,12,30,33}
[...#.] (0,1) (3) (0,2,4) (0,2,3,4) {217,10,207,210,207}
[....#..##] (0,4) (0,2,4,8) (0,1,3,4,6,7,8) (0,1,3,6,7) (1,2,3,5,8) (1,2,3,4,5,7,8) (1,3,4,5,6,7,8) (2,3,8) (1,2,3,4,6,7,8) (0,1,2,3,4,8) (0,1,2,3,5) {63,89,91,105,88,49,35,55,98}
[#.###...] (0,4) (0,2,3,4,6) (1,2,4,5,6) (0,2,3,4) (5,6) (1,7) (7) (3,4,6) {12,36,31,22,41,32,45,26}
[.##..#.] (0,4,5,6) (0,1,2,3,4,6) (1,4) (0,2,3,4,5) (5) (0,2,4,5) {142,13,27,15,143,140,127}
[########.] (0,1,3,4,5,6) (3,5,7) (3,4,5,6,8) (1,5,7) (0,5,8) (0,1,3,4,6,7) (2) (2,3,4,6,7,8) {34,32,15,50,46,54,46,29,34}
[..#.#.#.] (0,3,4,5,7) (0,1,2,3,4,6,7) (0,2,3,7) (0,1,3,4) (0,4) (0,1,2,4) (4,6) (0,1,2,3,4,6) (2,3,4,6) (0,1,2,4,5,6,7) {77,56,57,60,187,25,156,44}
[.#..#] (2,3,4) (1,2) (2,3) (4) (1,3,4) (3,4) (0,2) {5,19,22,50,54}
[..#..] (0,1,2,4) (1,2) (0,3) (1,2,4) (1,2,3) (1,3,4) {36,67,50,40,41}
[#.#.#.] (0,2,4,5) (0,4) (0,1,4) (1,3) (0,2,4) (0,5) (2,4) {56,9,26,4,41,24}
[.##.##..] (7) (0,1,2,4) (0,2,3,7) (0,1,2,3,5) (2,7) (1,2,3,5,6,7) (2,3,4,5,6) (0,2,4,6) (0,3,6,7) {69,33,75,56,32,33,46,50}
[.###.] (0,2,4) (0,1,2) (1,2,3) (2,3,4) {18,23,35,17,12}
[..##..#] (0,5) (0,3,4) (0,1,2) (0,1,4,5,6) (1,6) {53,48,19,13,28,21,29}
[##.#] (1) (0,3) (2) {164,20,14,164}
[###.] (0,1,2) (1,2,3) {11,186,186,175}
[##....#] (0,1,2,4) (0,1,3,5) (0,1,2,6) (0,1,3,4) (0,3,6) (0,4,5) (0,1,2,4,5) {188,168,153,25,44,33,137}
[.#####.#] (0,2,7) (0,1,2,3,5,7) (0,1,3,5,6) (0,1,2,3,5,6,7) (0,3,4,5,7) (0,1,5) (1,2,4,5,6,7) (1,3,4,6,7) {56,76,55,44,30,71,47,66}
[#.#...##..] (0,1,2,4,5,6,8,9) (0,2,3,4,5,6,8,9) (0,1,5,8) (0,3,6,7,8,9) (0,6,7,9) (5,6) (0,2,3,7,9) (1,2,3,4,5,9) (2,4,8) {77,19,62,52,46,43,67,51,62,78}
[..#.] (0,1) (0,3) (2) {24,17,11,7}
[##.#] (0,2) (1,2) (0,3) (2) (1,3) (0,1) {42,36,37,19}
[.#####..##] (0,7,8) (0,1,2,3,5,7,8,9) (1,6) (2,6,8) (4,5) (1,3,4,6) (0,1,2,4,7,8,9) (4,5,6,8) (0,9) (6,7,8) (1,3,5) {23,38,23,21,42,23,52,21,41,21}
[#...] (0,1) (0,2,3) (0,3) (2,3) (1) (1,2) {221,21,203,217}
[.#.###] (0,1,2,4,5) (0,2,3,5) (0,1,4,5) (1,2,3,4,5) {154,32,156,152,32,169}
[..#.##] (2,3,4,5) (0,1,4) (0,1,2,3,5) (4) (3,5) (2,3) (0,1,2,4,5) {20,20,25,25,30,29}
[.#####.#.] (0,2,3,4,6,8) (0,1,3,4,5,6) (0,1,2,4,5,7) (2,5) (1,2,3,4,7) (0,1,2,4,5,8) (0,1,2,3,5,6,7) (0,2,3,4,7) (0,6,8) (1,8) {52,47,57,27,31,43,34,30,41}
[##.#.] (1,4) (0,1,3) (3) (0,4) (0,3,4) (2,4) {27,29,13,27,39}
[#..###....] (0,3,4,5,6,7,9) (0,3,4,5,6,7,8,9) (0,3,6,8,9) (0,1,5,6,7,9) (0,2,3,6,7,8,9) (4,6) (0,1,3,4,5,8,9) (0,8) {90,30,7,61,49,51,80,45,69,78}
[##..###] (0,1,3,4) (1,2,5,6) (2,3,5,6) (1,5) (1,3,4,5) (0,4) (2) {31,51,35,36,34,48,26}
[.###.####.] (1,2,3,4,5,7) (0,1,2,4,6,7,9) (1,2,3,4,5,6,8,9) (1,2,3,6,7,9) (1,3,5,6,8) (5,6) (0,2,5,6,7,9) (0,5,7,8) (1,2,3,4,7,8,9) {27,74,89,70,52,70,71,82,39,72}
[###.....#.] (6,8) (3,4,5,7,9) (1,2,7) (0,1,2,4,7,8,9) (1,4,7,9) (0,2) (2,4,5,9) (1,3,9) (5,8) (0,2,4,5,7,9) (1,2,3,4,5,7,9) (2,4,5,7,9) (3,4,7,8,9) {28,34,37,37,74,45,9,72,55,77}
[.###.] (1,4) (0,1,3) (1,2,3) {3,11,2,5,6}
[##....#.] (2,3,4,6) (1,2,5,7) (1,4,7) (0,2,3,4,5,7) (1,2,3,5,6) (2,3,4,5,6,7) (0,2,3,5,6) (0,2) (2,6,7) (1,4,6,7) {27,177,232,72,72,184,90,203}
[###.###..] (3,4,7) (0,1,2,3,4,5,8) (4,6) (0,3,4,5,7,8) (0,1,2,3,5,6,7) (0,1,2,4,6,7,8) (0,8) (1,2,7) {261,233,233,245,246,234,41,70,241}
[#..#..#] (0,1,2,5,6) (2,3,4) (0,1,2,3,5,6) (1,2,3,5) (0,1,2,3,4) {159,162,179,178,166,13,10}
[...#.#...] (0,3,4,5) (1,5,7,8) (4,6) (0,2,3,4,6,7,8) (2,4,8) (0,1,2,3,4,5,7,8) (3,5) {29,8,43,29,61,14,28,24,44}
[##..###.#] (0,1,2,4,5,6,8) (3,4,5,6,7) (0,3,6,8) (5,6) (2,3) (0,2,3,4,5,6) (0,1,2,3,4,5,6,8) (0,1,2,3,5,7) (2,8) (0,2,3,4,5,6,7,8) {61,34,222,204,64,74,71,25,53}
[##.#] (0,1,3) (0,2) {178,168,10,168}
[#..##] (0,2,4) (0,3) (0,1,3,4) (0,1,3) (0,1,2,3) {27,22,6,23,23}
[###.#.] (1,2,4) (2,3,4) (3,4) (0,3) (0,2,5) (1,2) {23,11,45,31,26,18}
[..##.###..] (4,5,7) (0,1,2,3,4,6,7,8,9) (0,1,2,3,4,5) (2,3,5,6,7) (1,2,3,8,9) (0,1,2,3,4,5,8,9) (0,5,6) (0,1,2,3,4,5,7,8) {21,38,42,42,35,39,4,21,21,18}
[.##.] (0,1) (0,3) (0,2) (1,2) {42,4,21,19}
[...###.] (1,2,3,5) (1,3,4,6) (0,1,2,5,6) (1,2,3,5,6) (0,1,6) (2,4) (1,2,5) (3,4,5) {23,47,28,30,11,38,34}
[#...#] (2,3,4) (1,2,4) (0,1,3) (0) (2,3) {3,5,16,11,9}
[.#.#..#] (0,1,4) (1,2,3,6) (4) (1,2,3,4,5) (0,2,3,5) (3,4,5) (2,4,5,6) (2,4) {23,38,67,37,80,43,28}
[.##.#] (0,1,2) (0,2) (0,2,3,4) (2) (2,4) {29,13,47,0,12}
[#.#..#.] (3,4,5,6) (4,6) (0,1,2,4,5,6) (0,1,2,3,5) (1,3,4,5,6) {14,26,14,28,30,28,30}
[#...#...] (0,1,2,3,4,5,6) (0,1,4,5,6,7) (0,1,2,3,6,7) (0,3,4,5,6,7) (2,5) (0,2,3,5,7) (0,3,4,5,6) (5,7) (1,7) {85,41,45,72,58,99,68,84}
[.#..##..##] (2,3,5,6,7,8,9) (2,3,5,7,9) (2,3,4,5,8) (0,1,2,3,4,5,6,7) (0,5,7,8) (2,3,4,5,7) (1,4,6,9) (6,8) {21,5,51,51,19,69,22,56,48,36}
[#.##.##.#] (3,8) (0,3,4,5,6,7,8) (1,4,8) (0,2,4,5,6,7,8) (0,1,2,3,5,6,7,8) (0,1,2,4,5,6,8) (0,1,3,4,5,6) (0,1,2,3,4,7,8) {258,240,240,50,246,245,245,57,254}
[.#.##...] (0,3,4,5,6,7) (3,6) (1,5,7) (0,2,3,5) (3,4,5,7) (0,2,4,7) {18,8,12,26,22,22,18,30}
[####..##..] (0,2,3,5,7,8,9) (1,3,4,7,8) (1,2,3,6,7,8,9) (1,7) (0,3,4,5,8,9) (2,3,4,5,6,7,8,9) (0,2,3,5,6,7,8,9) (2,5,8) (1,5,9) {38,43,72,83,48,90,40,65,101,89}
[.#.#.#] (0,1,4,5) (3,4,5) (0,1,2,4,5) (1,2,3,5) (1,2,3,4) (1,2,3,4,5) {20,54,49,48,62,59}
[#.##] (1,2) (0,1,3) (0,2,3) {23,28,35,23}
[#.##.#..##] (4,5,7) (0,2,3,4,7) (1,2,3,4,5,6,8) (1,2,3,5,6,8,9) (2,7) (0,1,5) (1) (1,2,5,6,7,8) (1,4,5,7,8,9) (0,3,6,7,9) (0,1,4,5,8) (0,4,6,9) {49,72,49,37,89,72,50,67,56,46}
[...#.] (1,2,3,4) (2,3) (0,2,3,4) (1,3,4) {20,25,177,184,45}
[#...##] (0,2,4,5) (0,4,5) (0,1,2,4) (4,5) (0,1,3,5) (0,1) (3,4,5) (2,4) {48,28,10,28,40,57}
[##.#...##.] (0,4,8) (0,1,4,6) (3,5,7) (1,5,8,9) (4,5,8) (1,2,3,5,7,8,9) (2,5) (1,3,9) (0,1,2,8) (0,2,6,7) (2,3,4,5) {215,41,227,39,64,85,195,207,68,30}
[.##.##] (0,1,3,4,5) (0,1,4,5) (0,2,3) (0,1,2,3,4) {25,20,19,24,20,6}
[##...##.] (1,3,4,5,6,7) (0,1,2,3,4,5,6,7) (1,2,4,5,7) (0,1,2,6) (1,2,3,6) (1,2,3,4,7) {8,50,33,30,43,41,30,43}
[##..] (0,2) (0,1) (0,3) (3) (1,3) {11,20,4,30}
[...#] (0,1,2) (0,2) (0,2,3) {32,10,32,12}
[#####.] (0,2,5) (3) (1,2,3,4) (0,1,2,3,4) (0,3,4,5) {13,167,170,186,168,4}
[###..#.#] (4,7) (0,1,7) (1,3,4,5,6,7) (2,4) (0,3,4,5,6) (1,2,4,7) (2,5,7) (0,1,2,7) (2,4,6) {24,128,164,20,181,33,39,160}
[....#..##] (2,4,6) (0,1,6,7,8) (0,2,4,5,7,8) (1,2,3,4,5,6,8) (2,5,6,7,8) (2,3,4,5,6,8) (1,3,4,5,6,7,8) {14,24,61,32,47,61,54,34,63}
[.####.#.] (0,1,2,4,5,6) (1,2,4,5) (0,2,3,6) (1,2,3,5,6,7) (0,2,6,7) (1,6,7) (2,3,5) (1,4,5) (1,2,3,4,6) {40,140,66,30,28,42,157,130}
[###..##.##] (3,4,6,8,9) (0,5) (0,1,3,6,7,8,9) (4,8,9) (1,2,3,4,5,7,9) (1,2,3,4,6,7,8,9) (0,3,5,6) (4,6,7,9) (1,2,3,4,5,6,7,8) (0,1,2,5,6) (1,3,5) {6,33,21,42,42,26,30,30,32,39}
[###.###.] (5) (1,4) (3,5) (0,4,5,7) (0,1,2,4,5,7) (1,5,6) (0,4,5,6,7) (0,1,2,4) {27,31,9,5,45,46,12,19}
[###..#.###] (0,2,6,9) (1,4,5) (0,5) (0,1,4,6,7,8,9) (2,3,4,6,8,9) (0,5,7,9) (0,3) (1,2,4,7,8,9) (3,8) (3,5,8,9) {42,38,33,19,43,12,37,40,55,57}
[..##...##.] (5,7) (0,4,6,7) (0,6) (1,2,4,7,9) (0,3,4,6,7,8,9) (0,2,3,5,6,8) (0,1,2) (1,3,5,8,9) (0,1,2,3,5,9) (1,2,4,5,6,7,9) (0,2,3,4,7,8,9) {169,64,189,161,44,178,146,60,149,62}
[###...#.#.] (0,1,2,3,4,7,8) (0,1,3,9) (1,2,5,6,8,9) (0,1,4,5,7,9) (1,2,7,8) (5,6) (3,6,7,8,9) (5,6,8) (2,3,6,7,8) {32,50,39,49,13,45,62,48,62,50}
[##.##] (1,2,4) (2,3,4) (3) (0,1,4) {2,21,39,172,41}
[.####.###.] (1,3,8,9) (0,2,3,4,7,9) (1,3) (2,3,4,5,7) (0,5,6,8) (0,1,4,8,9) (0,3,4,8) (1,2,4,5,6,7) (1,2,3,4,6,7,8,9) {55,56,38,56,69,31,32,38,67,54}
[..##..#.] (0,1,3,4,5,6,7) (1,2,4,5,6,7) (3) (0,3,5,6) (0,1,2,3,4,5,7) (0,4,5) {39,36,30,46,43,50,24,36}
[####..#.#] (1,3,4,7,8) (1,2,4,7,8) (0,2,4,5,7) (2,3,5,7,8) (6,8) (0,1,2,4,5,7,8) (0,2,4,5,6) (0,1,3,4,5,7) (0,4,7) (0,1,2,3,4,6,8) {46,41,63,31,72,54,218,60,246}
[....#.#.] (0,1,2,4,6,7) (1,2,4,5,7) (0,1,3,4,5,7) (2,5,7) (0,1,2,4,5,6,7) (0,4,5) {57,61,60,20,62,64,36,80}
[#..###] (0,1,2,5) (1,5) (0,1,2,3,4) (1,2,3,4) (0,5) (0,2,3,5) {51,54,37,18,17,53}
[.#.#.#..] (0,2,3,4,5,7) (0,2,4,5,7) (0,1,5,7) (0,1,2,3,5,6) (1,4,7) (5,6) (3,4,5,7) {43,16,37,33,40,73,28,46}
[.#..] (0,1,3) (0,2,3) (1) {21,20,11,21}
[.....#.###] (0,1,2,4,6,7,9) (0,5) (2,4,5,6,8,9) (2,9) (1,4,5,6,7,8,9) (3,4) (0,3,4,6,7,8,9) (0,1,3,4,5,6,7,8) (0,1,3,9) (2,4,5,6,7,9) {43,40,47,26,64,44,57,47,35,82}
[...#.#.#.] (1,2,3,4,7) (1,4,6,7) (0,1,2,5,6,8) (0,1,2,3,7,8) (0,1,2,3,4,6,8) (1,3,4,5,6) (0,1,3,8) (7,8) (3,5,7) (2,3,4,5,6,7,8) {34,61,47,70,40,42,34,58,45}
[##.#..#] (1,2,3,6) (2,5) (0,5) (0,1,3,4,5) (0,1,3,6) (1,4,5,6) {8,143,11,7,136,148,143}
[......###] (0,1,2,3,4,8) (2,3,5,6,7,8) (0,1,3,4,6,7,8) (1,3,4,5,6,7,8) (4,5,7) (0,1,3,4,7,8) (2,4,7) (0,1,4,6,7,8) {46,51,23,43,79,21,34,74,53}
[######] (0,4,5) (0,1,2,3,5) (4) (0,1) (0,2,3) (1,3,4,5) (2,4,5) {31,15,24,18,30,22}
[#...#] (1,4) (2,3,4) (0,2,3) {17,10,29,29,22}
[##.#.#...] (2,3,4,8) (1,2,3,4,5,7,8) (0,3,4,5,6,8) (1,2,3,5,6,7) (1,4,5) (0,1,4,5,6,7,8) (0,1,2,3,6,7,8) (3,5,6) (0,5,6,7) (1,3,4,6,7,8) (0,1,2,3,5,7) {23,75,53,85,70,78,51,62,54}
[.##.###] (2,3,6) (1,2,3,5) (2,3) (0,4,5,6) (1,2) (0,3,4,5,6) (1,3,4,5) {13,23,19,38,28,32,23}
[.####.#] (3) (1,5,6) (0,1,2,3,6) (0,1,4,5,6) (1,4,5) {28,40,19,20,19,21,30}
[.#.#.#] (0,2,4) (0,1,2,5) (4) (0,2,3,5) (0,1,2,3) (1,2,4) (0,1,4,5) (1) {44,44,53,20,186,19}
[###..] (0,3,4) (0,1,4) (0,1,2) (1,3,4) (2) {35,27,30,28,28}
[#.###.###.] (1,2,3,4,5,6,7,9) (0,3,4,6,8) (2,4,7,9) (0,2,5,9) (0,3,7,8) (1,2,3,4,5,6,8,9) (1,8) (0,2,3,5,6,7,8,9) (1,3) (0,1,3,6,7) (0,5,7,8,9) (1,2,3,5,7,8) (1,2,3,4,5,6,8) {46,62,75,70,45,86,54,54,78,75}
[#...##.###] (2,3,5,7) (0,2,3,4,5,6,8,9) (2,3,6,9) (1,5) (2,5,8) (0,1,3,4,5,7,8) (0,1,2,4,6,7,8,9) (0,3,4,5,7,8,9) (0,5,6) (3,4,5,6,7,8,9) (0,1,4,5,6,8,9) (0,1,2,4,5,6,9) (0,2,3,4,5,6) {94,33,68,71,79,111,84,36,63,79}
[###.###..] (1,2,3,6,7,8) (0,2,3,4,5,7,8) (2,6,7) (5,7) (4,6,7) (2,3,4) (1,2,3,4,5,6,7) (0,4,8) {13,4,26,15,31,6,20,22,13}
[#...#] (2,3) (0,1,2,4) (0,4) (0,2,4) (1,2) {24,30,46,14,24}
[..#..#.##.] (1,8) (1,6,7,9) (0,3,8) (0,1,2,4,5,8) (0,4,6,9) (1,2,3,5,6,7,8,9) (0,1,2,3,5,6,9) (4,5) (1,3,7,8) {30,35,13,19,30,27,27,17,29,27}
[....#.##.] (0,2,3,5,6,7,8) (1,3,4) (2,3,6,7,8) (1,2,3,5,6,8) (1,2,3,4,6,7,8) (2,5,7,8) (3,8) (0,5,6,7,8) (0,1,3,4,5,7) {23,43,58,84,28,39,57,56,72}
[###.#.] (0,2) (0,2,3,4,5) (3,5) (0,1,2,4) (2,3,4,5) {31,14,31,28,24,28}
[#.#......] (0,1,2,4,5,8) (0,1,2,3,4,5,6,8) (2,3) (0,1,3,7) (0,4,6,8) (4,5) (0,1,3,4,7,8) {75,61,23,47,64,30,23,38,57}
[#..####..#] (0,1,2,3,5,6,7,9) (6,7,8,9) (1,3,5) (0,6) (0,1,5,8,9) (2,6,7,8) (0,2,3,4,6,7,8,9) (0,1,4,5,7,8) (2,3,5,6,7,8,9) (0,2,3,4,5,7,8,9) (1,3,4,6,7,8) (0,4,5,8,9) (0,1,2,5,6,7,8) {97,72,75,76,50,94,83,89,97,82}
[#.##..] (0,3) (1,2,4,5) (1,2,3,5) (0,4) (0,2,5) (0,1,3,4,5) (0,1,5) (1,2,3,4) {47,64,63,47,47,67}
[#..##] (3) (1,3) (2) (0,2,3) (0,1) (0,1,2) (0,1,4) {6,10,126,21,3}
[###..###.#] (0,3) (3,4,9) (0,2,6,7,9) (4,6,7,8,9) (3,9) (2,3,5,9) (1,4) (1,2,4,6,7,9) (1,3,4,6,7) (0,4,5,6,7,9) {48,37,27,224,87,24,70,70,12,237}
[..##......] (0,2,5,6,9) (0,2,3,4,5,6,8,9) (0,1,4,5,7,8) (0,2,3,5,6,7,8) (1,7) (0,1,2,3,4,6,7,8) (0,1,3,4,6,7,8,9) (5,7,8,9) (0,1,3,4,5,6,7,9) (2,3,4,5,6,8,9) (0,1,3,7,8,9) (2,4,7) {230,50,217,218,66,218,212,244,232,60}
[###.#.#] (2,5) (2,4) (1,2,4,5) (0,1,4,5,6) (0,3,5,6) (2) (0,3) (1,4,5,6) {25,19,54,19,35,51,28}
[#.###.] (1,2) (0,1,2,5) (1) (0,1,2,4,5) (2,3,4,5) {30,56,47,11,28,41}
[###.#.#.#.] (2,5,6,7,8) (0,1,3,6,9) (0,3) (0,1,9) (3,7,8) (1,2,3,7) (0,1,5,6,7,8) (3,5,7,8) (1,3,5,9) (0,2,3,4,5,6,7,9) (3,5,7,8,9) (1,2,3,7,8) {46,79,165,112,17,173,148,206,171,61}
[.#...] (0,1,4) (0,2,3) (0,1,3) (1,2) (1,3,4) (3,4) {34,43,19,64,36}
[###.#..] (0,5) (0,1,2,4,6) (0,3,4,5) (0,1,3,4,5) (0,3,5) (0,2,3,4,6) (0,1,2,6) (0,3,4,5,6) {239,18,187,224,225,52,205}
[..#...#] (1,4,5,6) (0,1,2,3,4,6) (2,6) (0,4,6) (0,4) (0,3,4,5,6) (1,2,5) {46,17,13,25,53,32,50}
[......#.] (1,4,5,6) (2,4) (1,2,7) (0,2,5,6,7) (2,5) (0,1,2,4,5,7) (3,6) (0,1,2,6,7) (0,6,7) (1,2,6,7) {23,41,50,0,9,15,36,50}
[..#....#] (0,3,4,5,6,7) (0,1,2,3,4,7) (3,6,7) (0,6,7) (2,4,5,6) (0,1,2,3,7) (0,1,2,5,6) {43,22,28,35,30,19,30,44}
[#.##.] (2) (0,2,3,4) (0,2) (0,2,3) (0,4) (1,3,4) {145,4,147,141,7}
[.##......#] (0,1,2,3,4,5,7,9) (3,7,9) (0,1,3,4,6,7,9) (0,2,4,8,9) (0,1,3,4,6,9) (0,2,8,9) (2,3,5,7,9) (1,3,5,6,7,9) (0,2,3,5,6,7) (1,2,6,9) {81,36,81,64,49,43,45,46,33,84}
[##...###.] (0,4,6,7) (0,1,2,3,5,8) (1,2,4,5,7,8) (1,3,4,5,7) (1,5) (0,1,5,6,7) (3,6) (0,1,3,5,6,7,8) (1,2,5,6,7) (3,4) (2) {22,51,40,24,41,51,42,54,24}
[..#.] (3) (0,1,2) (2,3) (1,2,3) {1,147,149,165}
[..##.#.#] (0,1,3,4,5,6,7) (2,5,6) (3,4) (0,1,4,5) (4,6) (1,2,3,4,6,7) {7,22,28,23,37,20,39,17}
[...#...#] (0,2,4,5) (0,2,3,5,6,7) (0,2,4,5,7) (4,7) (0,3,6) (2) (0,1,2,5,6,7) (0,3,5,6,7) (0,1,2,4,5) (1,2,5,7) {60,35,77,16,36,71,35,64}
[..#..#.] (0,1,5) (3,4,6) (1,3,4,6) (0,2,6) (0,3,5,6) (1,2,3,4) (0,6) (1,4,6) {39,50,13,31,45,20,57}
[..#...] (0,1,2,5) (0,4,5) (1,3,4,5) (1,4) (0,1,3) (1,2,3,4,5) {122,58,22,36,148,144}
[#.##...] (3,4) (2,5) (0,2,3,4,5) (1,2,3,4) (0,1,2,4,5) (0,6) {41,7,28,21,28,28,14}
[.##....##] (1,4) (0,1,2,3,8) (0,1,2,3,4) (2,3,4,6,7,8) (0,1,3,4,5,6,8) (7,8) (0,2,5,6,8) (1,2,3,4,5,6,7,8) (4,6,7) {32,35,48,39,60,11,39,43,41}
[#.##] (1,2,3) (3) (2,3) (2) (0,2,3) (1) {14,168,60,51}
[...##...#] (0,1,2,3,5,6,7,8) (0,4,5,7) (3,4,8) (0,2,4,5,6) (1,2,3,5,7,8) (0,1,2) (0,3,5) (1,3,5,6,7,8) (1,3,5,7,8) (0,1,2,4,5,6,7,8) {68,55,43,52,30,68,29,52,45}
[#..##] (0,3,4) (1,4) (1,2,4) (1,2) (0,1) (0,4) {28,31,18,8,18}
[#.##...##] (0,2,3,4,5,7,8) (2,3,4,5,6,7,8) (0,1,2,4,5,7,8) (0,6,7,8) (0,1,3,8) (1,6,8) (2,8) {42,23,170,46,28,28,34,41,205}
[###.#..#] (0,5,7) (1,4,5,6) (0,1,2,3,5,6,7) (1,3) (1,2,6,7) (0,3,5,6) (0,5,6,7) {33,49,31,28,7,40,44,47}
[...##] (0,2,4) (1,3,4) (2,3,4) (1,3) (3,4) (0,2) (0) {49,13,31,17,19}
[.##...#.] (0,1,2,3,4,5,7) (0,2,3,4,6,7) (0,1,2,4,5,6,7) (1,2,4,5,6) (0,1,3,5,7) (0,1,2,4,6,7) (4,5) {76,63,60,52,67,53,43,76}
[....##...#] (3,6) (0,1,2,4,5,6,7,8,9) (0,1,2,3,4,7,8) (2,3,4,5,7) (2) (3,5,6) (3,4,5,6,9) (0,2,4,5,6,8,9) (0,3,4,9) (0,2,3,4,5,6) (0,4,6,7,8,9) (2,3,6,8) {60,13,70,71,64,47,84,28,47,39}
[..##.] (4) (0,1,4) (1,2,4) (0,3,4) (2) (0,2) {32,35,43,4,49}
[.#...#] (0,3,4,5) (0,2,5) (0,2,4,5) (0,1,3,4) (2,3) (1) (0,2) {62,23,43,29,30,33}
[##...#####] (2,3,4,6,7,8) (9) (1,2,8,9) (0,4,9) (0,1,2,3,4,5,6,9) (1,3,4,5,6,7,9) (0,7) (1,8) (0,1,3,4,6,7,8) (0,2,5,9) (0,1,5,6,7,8,9) (7,8) {183,182,41,175,177,32,183,180,177,54}
[##.#] (0,1,2) (1,2,3) (2,3) (1) (0,2) {18,26,29,11}
[#..##.#] (3,4,5) (4,6) (3) (1,2,3,4,6) (1,3,4,5,6) (0,2,4,6) (0,1,5,6) (1,2,3,4,5,6) (1) {10,47,23,42,51,31,53}
[...#.] (1,4) (1,3,4) (0,1,3) (1,3) (2,3) (3,4) (4) {11,36,2,44,198}
[#.#.] (0,2) (1,2,3) {20,156,176,156}
[#....] (0,1,3,4) (0,1,2,3) (1,2,3) {28,29,15,29,14}
[###...] (0,4) (1,2,4) (1,5) (0,1,2,3) {12,38,26,11,16,12}
[..###.] (0,1,3,4) (0,2) (4,5) (2) (0,1,2,4) (1,3,5) (0,1,2,4,5) {32,26,38,3,36,19}
[..#..#.] (0,1,3,5,6) (3,4,5) (0,4) (1,3,5) (0,1,4,5,6) (2,5) (2,3,4,5,6) {39,44,26,48,45,78,51}
[#...] (1,3) (2,3) (0,3) (0,1,2) {11,15,7,24}
[##.####] (1,2,4,5) (0,1,2,3,5) (2,3,6) (3,4) (0,1,3,4,6) {27,42,41,207,196,35,13}
[...#...#] (0,2,3,4,6) (1,2,3,7) (6,7) (2,5) (0,2,4,5,6,7) (0,1,2,3,4,5) (3) (0,1,3,7) (3,6) {44,27,31,58,24,10,33,36}
[####...##] (4,5,6,7,8) (0,2,5,6,7,8) (0,1,3,4,6) (3,8) (2,3,4,6,7) (2,4,6,7,8) (0,1,2,3,4,6,7,8) (0,4,7,8) {33,22,51,43,64,23,75,63,56}
[.##..#] (0,2,3) (2,3,4) (2,4,5) (0,1,4) (1,5) (5) (0,1,2,3,4) (1,2,5) {33,43,47,32,40,33}
[.##.#..#..] (1,2) (0,1,2,3,5,7,8) (3,7,9) (0,1,2,4,5,6,8) (2,7) (0,1,2,3,4,6,7,8,9) (0,1,2,6,7,9) (4,6) (0,1,5) (0,1,3,4,5,7,8,9) {46,66,57,39,35,42,17,58,37,31}
[##.#] (0) (0,1,3) (1,3) (1,2) (2,3) (0,1,2) {21,35,28,39}
[####..#.#] (0,1,2,3,4,5,7) (4,5) (6,7,8) (1,2,3,4,5,6,8) (0,3,4,6,7,8) (0,2,4,5,8) (0,1,2,3,5,6,8) (3,7,8) (0,2,4,5,7) {48,37,47,62,67,59,62,52,67}
[.#.##.#] (3,5) (5,6) (0,1,2,3,5,6) (2,3) (0) (1,4,5,6) (1,2,4,6) (0,1,3,5) (4) {33,62,31,42,41,72,61}
[.#####] (1,2) (0,2,4) (3,5) (4) (0,2,5) (3,4,5) (0,1,3,5) (3) {32,7,25,202,32,200}
[..#.] (0,1) (0,3) (2) (0,2) (1,2) {35,39,37,6}
[##.#..] (0,2,3,4) (0,2,5) (0,2) (3,5) (0,5) (0,1,2,4) (1) (4,5) {30,21,21,7,18,30}
[.....#.] (1,4,5) (0,1,3) (1,4) (0,1,2,3,4,6) (1,2,6) (2,4,5,6) {193,235,212,193,228,32,212}
[.#..#..##] (2,7) (0,5) (0,1,7) (0,1,3,7) (4,8) (1,2,3,4,5,6,8) (0,1,2,3,4,5,6,8) (1,2,3,5,6,8) (1,7) {193,203,52,54,38,54,38,179,45}
[#..#.#] (3,5) (0,1,2,3,5) (2,4) (0,3,5) (0,1,5) {11,6,9,22,9,28}
[.#.#.##] (0,1) (0,2,3,5,6) (0,2,3,5) (0,1,2,3,5) (0,2,4,5,6) (4,5,6) (1,2) (4,5) {39,25,40,28,4,32,20}
[....##.#..] (0,2,3,4,5,6,7,8,9) (0,3,4,6,7,8,9) (6,7) (1,5) (0,2,3,9) (2,8,9) (1,6,9) (0,1,3,5,6,7,8) {50,39,35,50,17,39,64,47,42,52}
[####.##.] (0,1,2,4) (1,3,5,6) (2) (1,3,6) (0,1,3,7) (0,2,5,6) (0,2,7) (4,7) {49,37,38,21,18,1,7,34}
[.##.###.] (2,4,5,7) (4,5,6,7) (1,3) (0,1,2,7) (0,1,3,4,6,7) (2,5,6,7) (1,2,4,5,6) {20,49,64,12,41,50,34,52}
[.#....] (2) (1,2,3,5) (0,2,3,4,5) (1,3,5) (2,3,4) (1) {14,32,178,172,153,33}
[.####...] (0,1,2,4,6,7) (0,2,3,4,6,7) (1,2,3,6,7) (0,4,5,6,7) (0,1,2,3,5,6,7) (1,2,3,5,6,7) {48,40,58,46,46,33,74,74}
[.#.###.] (0,2,3,4,5,6) (1,2,4,5) (6) (0,1,3,4) (1,2,6) (2,3) (0,5,6) (3,4,6) (1,3,4,5,6) {35,33,58,55,52,40,189}
[#..####.] (1,3,4,5,6,7) (0,1,3,4) (2,4,6) (1,2,3,4,5,7) (0,1,3,4,6,7) (0,3,5,7) (0,1,4,7) {30,55,16,43,62,29,26,44}
[#.#.#..#.#] (0,1,2,3,4,5,7) (3,5) (0,1,2,4,6,7,8,9) (1,2,3,7,8,9) (0,1,6,9) (2,3,4,5,6,9) (1,2,4,9) (5,7) (0,2,8,9) {45,150,171,151,28,42,38,147,150,183}
[..##] (0,2,3) (0,3) (1,2,3) (0,1,3) {202,19,15,213}

1002
src/day10/main.rs Normal file

File diff suppressed because it is too large Load Diff

3
src/day10/test.txt Normal file
View File

@@ -0,0 +1,3 @@
[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7}
[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2}
[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}

604
src/day11/act.txt Normal file
View File

@@ -0,0 +1,604 @@
zmg: vew ynx rdv kzq
fho: drg
qtg: bcp kzq
nbp: fkn
oaa: ulw zyf
fyy: dwh vjr cdg miw
rwj: kkt hdz irr ovu
qoy: rao eev wzh wkc
jzz: glp pwf fwp
aqu: swy txo nqu mla
yws: zxh fft
rdd: zbw cqw
hoo: bfn amg vyd dod ovp kii
bnz: vdk
shw: gzx
iep: zbw
mxl: udq owi yhh rrk
izl: tfr
oku: pvp
omu: pvq tsj hfl
xwc: bdu tuz tkz
tjf: rek vil
uak: bko
idt: yrr
que: yyb aqu cfl
tmg: eev
ybn: hfe qou xrk
dgj: jbz you fhk hoo
hfl: fmn gzw sug
mix: gzx
cwn: fhk you jbz
rek: dfy ued zya nnk
sug: utp btl lzb hor ndl uuw kyi zqd jdq cfs nvd acs pyx pbm eqc ome
lan: kkt ovu irr
miy: uub gyg yol tua
dev: out
ykn: fea rlv how ksp
yom: fhk
tcl: fnb
nnk: hdz kkt
wau: rtw vuk aoe
amz: nxs vku
nqy: fdp wyk
bdj: hit ytb tcl
bgd: uru mhm
zdl: fps pmc maa frp
wrv: sug cjl gzw fmn
feh: irc ojk
efc: out
zst: rta knd
nqi: gyt pwv
snz: out
fea: wqv hse rqw
tqh: fea
hho: isx whl yiz
tkz: zkq
omh: uuu
dxu: dwh vjr sfc cdg miw
wzh: zbx tjd
iyj: bgw mug
naw: hhm pkw hwn
qdf: tjr
vku: kez abg qmx
udf: ulz
mhj: tmg ffw qoy flj nyf ybn que fxt rua rys vyu cri aoh nuf fik jsk wmy epz
uuy: sug
roi: out
abz: isx yiz
cvr: isx yiz whl
xrw: fwp pwf fnk glp
rta: yug thh
lyu: efc yxj iof hgu kpd
qwv: fkn gzx lzk
aum: yrx ubo
uuu: fmn gzw cjl sug
hjd: hbs
epr: maa frp pmc srx fps
sav: dst
rng: qou xrk
jue: rdd cze
wzl: out
nwn: gyt cwn
flj: aqu yyb
cdj: kxf daa
zln: nxs owg vku
pmu: kwh pql
tqw: lzk jhf gzx fkn
txo: nfb eez prz wkl
bko: gzx fkn jhf lzk
cym: plo
ovp: plo imv ums sjv
sjv: vre qtg
uzz: irr
nxs: kez aum qmx
hwe: cqb abv
lak: weu rtq
gvt: iyd
bcm: frp fps
pli: mug pfl pxs
gxw: jyz
nrb: sem pmu kcm teh
ffw: cfl
teh: pql vnb kwh
zdh: pvn
ome: byz lql
jnl: mdt ajt yzg nvq lfk aco yws kpp wff vxd nrb evs tjx cdj zdl kml ipx kkf vaw xjv
yxj: out
lof: sug gzw
hwn: you hoo
eva: jiq dny jky yom
rgs: qke abv cqb
fxt: tlz qtc
fft: mbr uuu
xjw: rtq
fnp: fnb ctz jnl wpq zvu
dcw: out
rms: pym lyu
nwy: wxb bko qkz shw gvo
wpq: aco nrb zdl epr mdt
lpf: jho
tzo: wkm yns ndo
kii: yag gel
oty: dmu
cjl: vkl ndl eqc hor pbm hki nvd lzb btl utp jdq zqd qlt
kdw: evf dxu
inn: jnl zvu wpq ctz
idv: yol uub gyg
epz: yyb
ovu: zst kdw czw xrw alk hkm kha sor gct ytl wvx ixw edo qmw vvm qdf jzz eat
gel: bdu
oic: rms
arh: cvo wkq toa vdh
bgw: yoo
grv: wkm
duj: emk
tog: sem kcm teh
srx: omu otm qpk
pdv: rek asl vil
cvj: pdi
utp: pdv ugr jho
ufz: sug fmn gzw
vvm: eem
imv: ses zmg vre
uzk: oty nlq
pwv: jbz
xhr: jti ufz uls
xwa: cxv xjw qbx lak
kbb: jnl zvu fnb
chx: jhf
nxn: fxt wmy que jsk rng oxu flj tmg ybn
kkt: alk hkm bfb zst kdw xrw czw tnr ixw edo vvm qmw jzz eat qdf kha sor gct lsg ytl
vqb: fmn gzw
ytb: zvu fnb
pmm: hhm
evs: fho vyk
far: iep kir axy cze
hkt: zev uga
fwp: cdu pdk szr oaa
lfk: vyk dqg
hkv: shw wxb gvo
rgv: ctz fnb jnl zvu wpq
plo: vre ses zmg
qmw: tjr hmb
ari: kxu
xrk: bdj gfq
jyz: rwj ryf
jho: asl rek
irm: you hoo
hit: jnl ctz fnb
yug: xfk trd ffe
edo: tjr hmb ibe
qiu: fdp wyk
glp: szr pdk cdu
ohw: ary
ytl: evf
aaf: tcl rgv
eqc: zkb mxl zke
aco: frp srx pmc
eem: ari jvj
wkc: ubu zbx
jdq: byz tue
udq: ovu irr ybz kkt hdz
vyd: hlf sur rpe ntd
kez: yrx szz ubo
gvn: wpq jnl fnb ctz
wvx: fyy dxu
cvo: out
nev: uls tqy ufz jti
ipx: sem
gqb: izl
vfz: wkm yns ndo
sor: buf
lsg: knd
uuw: mxl zkb
ufu: bqi ssr yag
qmj: pwv
ruw: vuk fnp aoe
zya: ybz irr
tuz: bnz oai
rdv: sjc bew
tyc: znl
dfy: irr ovu kkt
wkm: irm dgj yqu
kyi: jho pdv tjf
pyx: zke
rrk: ovu irr hdz
mhm: cxv xjw qbx
ynx: vdf arh
zxh: uuu
zot: uuy kvl
pkw: jbz hoo
dqg: bww vqb kvl
axb: vyi
ajt: dzl haw nii hkt
wyk: pvn fnu myf
geg: out
ntd: uzk ggo
bgt: zdh
xfk: zih
qoq: xiw woi dcw geg smh
yzg: pmu teh sem
rqe: jti ufz tqy
ybz: czw xrw bfb hkm lsg kha gct edo qdf jzz eat qmw
zkq: vkn vdk ufm
vyu: ruw boq wau
cdg: uak
rlv: oic hse
ugr: rek
myf: fhk you hoo
bso: jcg mvt aji yny
ozr: kkt hdz irr ovu
uub: zvu jnl fnb ctz
czw: fwp
pmc: omu qpk usl
prz: kbb urb
vaw: zxh fft zrw
cph: out
inh: ble
dmu: woi dcw
emk: nqs dac
rao: zbx
ipm: pdk
kcm: kwh
wxb: gzx
jbq: hvb rys rua fxt nyf ybn yrj tmg ffw qoy flj epz jsk nuf vyu cri
ary: oty nlq iyd
ypy: vis jsp qmj nqi nwn
isx: deb naw pmm
wmy: hfe
shb: hhm hwn xik
znl: qit zpr ryf
cze: sby
xiw: out
dny: hoo
kxu: fkn jhf
cre: auy
wzq: gzx lzk
pym: iof hgu efc yxj
wby: jcg
aik: ojk gvn irc
wra: vyi jcg aji
xuq: hoo
ffe: wzq
qmx: dwf
ana: ulz cut
qbx: weu rtq
qlt: rez sbk cre hjd
bew: wkq cvo roi vdh toa
vdh: out
xbo: xln
szz: usg qtz
toa: out
jbz: cxl vyd cym elv ufu sfh
zkb: lan udq
kxf: nev rqe
cxl: imv ums
ral: lak
jsp: cwn
cwr: jhf
pfl: yoo yrg
xln: out
jky: jbz hoo fhk you
sur: jem gvt
rxy: out
jcg: nbp chx tsb mix
btl: pny jue
bqi: tuz
rys: rao eev wzh zkn wkc
pny: cze iep axy rdd
tue: gxw cxu
zke: lan owi
cqw: kkt ovu
vmw: lyu
gab: cut emk
smh: out
kvl: sug fmn gzw
vjv: zpr ryf rwj qit
uru: cxv xjw
ksp: hse wqv
sfc: eky uak nwy hkv
hhm: hoo fhk jbz
fdp: pvn hfc myf
gvc: jbz
asl: dfy zya
fnk: oaa
mfs: yat
vuk: ctz fnb zvu wpq jnl
maa: oku omu
cza: yny
nvd: far pny
qkz: jhf gzx
sbk: hbs hut
rpe: jem ggo
elv: gel xwc bqi yag
qlg: bgw
tnr: hmb
yrg: you fhk hoo
mbi: lzk fkn
pdf: ksp fea how rlv lvc
frp: qpk
owg: aum kez
utj: sug gzw
bfb: ipm glp pwf fwp
byz: gxw cxu
buf: jvj hrd yrr ari
hrk: kpd efc yxj
trd: qwv wzq
hor: hsv far pny jue
tgh: wzq zih
szr: zyf
zev: sav vkg uhr
irr: wvx gct kha lsg vvm jzz eat ixw edo xrw kdw czw tnr zst hkm
fps: oku
yrx: xbo usg qyt qtz
vnb: utj vqm
zyf: fkn jhf lzk
lzk: udf duj tzo haa pfh uwc
axy: cqw zbw
sfh: hlf rpe sur
oai: ufm
ojk: zvu wpq ctz fnb
vxd: dqg zot
mvm: fmn
yiz: fdk
fdk: pkw hwn xik
tsb: fkn gzx
nuf: wau boq
gyg: wpq zvu jnl
jvz: wyk zdh
boq: aoe fnp vuk rtw
ckx: out
ffm: cjw pdi
jti: fmn cjl
eaq: lzk
hhy: ovu ybz hdz
urb: fnb ctz
yrj: ruw wau
lql: trg tyc
you: qsz bqf tqh zln kii bgd pth
lca: ypy tfr rwd
ble: bgt nqy
sby: ybz hdz kkt ovu
war: tqy
nii: aub zev hmp
fnb: zdl nvq tjx tog ljh vaw ipx
vkn: snz rxy cph
iof: out
cfl: swy nqu mla
cqb: nqy qiu
swy: nfb lhi eez prz wkl
jiq: you hoo jbz
lni: wkq cvo toa roi vdh
uhr: dst rjv
nfb: inn kbb urb
afj: xjw cxv jrw qbx lak
usl: pvq
pxn: zvu ctz
dod: rpe ntd ohw
gzw: lzb lpf utp jum vkl uuw ndl hki qlt kyi cfs jdq pbm eqc acs nvd pyx
hki: tue byz
tua: ctz wpq zvu
hmp: ocz
tve: kud yug
qpk: tsj pvp pvq
iyd: prb dmu
jrw: rtq kwa
ndl: jho tjf
hdz: vvm hkm alk tnr sor zst
evf: cdg miw
nbl: ozr
ibe: wby bso axb wra
coy: nwn nqi qmj vis
kha: eem idt
irc: fnb ctz jnl wpq zvu
cfs: zke zkb mxl
kzq: arh vdf
gct: rta
mbr: gzw fmn sug
cdu: zyf tqw
vkg: mvm
nqu: wkl prz eez lhi
pql: utj lof bhd
pvq: fmn gzw sug cjl
zpr: kkt ybz irr
qsz: ums sjv
dwh: eky nwy ozt hkv
cjw: out
fjn: pym hrk
zih: fkn gzx jhf
eez: inn
ulz: nqs eva dac
ufm: ckx snz cph
whl: fdk naw deb shb
hsv: iep axy kir cze
qyt: dzo
rtq: gbo ffm cvj
cyf: yat
ssr: tkz
yol: wpq
yny: tsb mix
ubu: idv miy
cxv: kwa rtq weu
hmb: cza wby
brs: out
deb: pkw
bhd: gzw fmn cjl
ewj: vku
abg: ubo szz dwf yrx
prb: xiw geg
jvj: eaq dlc
qit: ybz hdz ovu irr
vkl: tal tue
tjd: miy
eev: tjd ubu zbx
usg: wzl dzo xln
miw: hkv uak nwy
ulw: lzk jhf
yag: bdu tkz tuz
weu: gbo mkb ffm
hkm: knd
mdt: zrw fft omh
aji: chx tsb mix mbi
trg: vjv nbl
eky: gvo
ubo: qyt
abv: bgt qiu
pwf: cdu pdk szr oaa
jem: iyd nlq
csr: yol uub gyg
yyb: nqu txo
zrw: wrv mbr
qou: gfq aaf bdj
kpp: daa
sem: vnb kwh
hvb: qou
uwc: ulz
mkb: pdi dev
amg: afj xwa uru ral mhm
pth: afj xwa mhm
how: wqv rqw
dwf: qtz usg qyt
jum: zkb zke
woi: out
yat: tfr coy ypy
pvn: jbz hoo
alk: tve knd rta
sjc: wkq roi toa
ryf: kkt ovu
vjr: nwy uak ozt hkv
abw: gyh cri vyu rng jsk fik nuf wmy ybn nyf tmg yrj ffw flj qoy oxu rys hvb que rua fxt
ums: zmg ses
fhk: amg cxl ewj amz pdf cym tqh sfh zln ykn
gbo: icr
tfr: jsp
fmn: pyx acs nvd ome eqc cfs jdq zqd kyi qlt hki ndl hor utp jum lpf btl lzb
gfq: hit pxn tcl
ndo: yqu irm
hgu: out
yhh: ybz hdz ovu irr
otm: pvp hfl
qla: isx yiz
dzo: out
wqv: vmw fjn rms
bww: gzw sug cjl
qtz: xln wzl
tjr: bso wra axb cza
hbs: uzz
yrr: cwr
gyt: you hoo
wff: daa
bfn: ohw sur rpe
yoo: fhk hoo jbz
ixw: fnk
dzl: zev hmp
tqy: fmn
zkn: tjd zbx
cri: aik feh qtc
daa: xhr
lvc: hse rqw
cxu: znl vjv
vqm: fmn sug
nqs: jiq jky
rjv: sug cjl fmn gzw
kir: sby zbw
kml: dqg
qke: qiu jvz nqy
svr: nxn mhj ybx abw jbq
pbm: rez sbk
haw: uga aub hmp zev
drg: gzw
eat: evf
kpd: out
pdg: ovu kkt hdz ybz
hlf: uzk ggo ary
tjx: teh kcm sem
ses: rdv kzq vew ynx bcp
oxu: boq ruw
zbw: irr
ozt: bko qkz wxb
vre: rdv ynx bcp
aub: vkg uhr
tmp: xhr war rqe
pdi: out
hse: fjn
gyh: qtc feh
nlq: dmu qoq
zvu: tjx cdj zdl kml ipx kkf vaw bcm epr ljh ajt nvq lfk aco yws kpp wff vxd nrb evs
rez: hbs auy hut
hfc: hoo fhk jbz
nyf: wzh rao
tal: trg
uga: vkg ocz
dac: jiq jky gvc dny
ued: ovu
thh: ffe tgh xfk
icr: out
rua: hfe xrk
bdu: oai bnz
kkf: hkt haw nyp dzl
rwd: vis nqi nwn
aoe: zvu jnl ctz
kwh: bhd lof vqm utj
dlc: fkn gzx jhf
vyk: kvl vqb bww
vyi: chx
hfe: gfq
xik: hoo fhk you jbz
tsj: cjl sug
vdk: ckx brs cph
dst: sug cjl fmn gzw
vil: dfy ued
ljh: tmp
ggo: oty nlq
aoh: boq ruw
hrd: dlc
yqu: jbz fhk you hoo
vdf: vdh wkq cvo
nvq: haw hkt dzl
gvo: lzk
mug: xuq
ctz: yws kpp yzg mdt lfk nrb wff vxd zdl kml cdj ljh tog ipx bcm
rtw: fnb ctz wpq
uls: gzw fmn sug
vew: sjc
knd: thh kud
pdk: tqw ulw
owi: hdz ybz
qtc: gvn ojk
fkn: hho udf vfz cyf wiy uwc inh iyj qlg grv mfs pfh qla abz pli cvr
pvp: sug
lhi: urb
nyp: uga aub
mvt: mix mbi tsb
ybx: nyf aoh flj yrj rys rng epz rua wmy
auy: pdg hhy
vis: gyt cwn
mla: nfb wkl prz lhi
hut: uzz pdg
jsk: wkc wzh eev rao
fik: cfl
bqf: fea rlv how ksp lvc
acs: tjf ugr jho
tlz: ojk
fnu: hoo
cut: dac
lzb: cre
wiy: pxs mug
pxs: yoo
jhf: haa uwc iyj wiy duj cyf udf gqb cvr ana pli tzo abz qla hwe qlg gab grv
zqd: sbk
ocz: dst
kud: trd ffe
yns: yqu dgj
gzx: vfz rgs gab gqb qlg udf inh ana iyj duj wiy
pfh: lca yat
xjv: kxf
haa: yiz
kwa: gbo ffm mkb cvj zcl
zbx: csr idv
bcp: bew lni vdf
rqw: vmw fjn rms
zcl: dev pdi cjw
wkl: kbb
wkq: out

124
src/day11/main.rs Normal file
View File

@@ -0,0 +1,124 @@
use anyhow::Result;
use std::{
collections::{HashMap, HashSet},
fs,
};
fn sol1() -> Result<()> {
let text = fs::read_to_string("src/day11/act.txt")?;
let graph = text
.split("\n")
.filter(|a| a.len() > 0)
.fold(HashMap::new(), |mut g, m| {
let mut split = m.split(":");
let node = split.next().unwrap();
let outs = split
.next()
.unwrap()
.trim()
.split(" ")
.fold(HashSet::new(), |mut s, a| {
s.insert(a);
s
});
g.insert(node, outs);
g
});
fn count_paths(t: &str, visited: &HashSet<&str>, g: &HashMap<&str, HashSet<&str>>) -> usize {
let mut visited = visited.clone();
visited.insert(t);
let mut sum = 0;
for i in g.get(t).unwrap() {
if visited.contains(i) {
continue;
}
if *i == "out" {
sum += 1;
continue;
}
sum += count_paths(i, &visited, g);
}
return sum;
}
println!("sol1: {}", count_paths("you", &HashSet::new(), &graph));
Ok(())
}
fn sol2() -> Result<()> {
let text = fs::read_to_string("src/day11/act.txt")?;
let graph = text
.split("\n")
.filter(|a| a.len() > 0)
.fold(HashMap::new(), |mut g, m| {
let mut split = m.split(":");
let node = split.next().unwrap();
let outs = split
.next()
.unwrap()
.trim()
.split(" ")
.fold(HashSet::new(), |mut s, a| {
s.insert(a);
s
});
g.insert(node, outs);
g
});
let mut node_hit: HashMap<&str, usize> = HashMap::new();
let mut node_hit1: HashMap<&str, usize> = HashMap::new();
let mut node_hit2: HashMap<&str, usize> = HashMap::new();
fn count_paths<'a, 'b>(
t: &'a str,
end: &'a str,
visited: &HashSet<&str>,
g: &'a HashMap<&'a str, HashSet<&'a str>>,
hit: &'b mut HashMap<&'a str, usize>,
) -> usize {
let mut visited = visited.clone();
visited.insert(t);
let mut sum = 0;
if let Some(n) = g.get(t) {
for i in n {
if visited.contains(i) {
continue;
}
if *i == end {
sum += 1;
continue;
}
if let Some(c) = hit.get(i) {
sum += c;
} else {
sum += count_paths(i, end, &visited, g, hit);
}
}
}
hit.insert(t, sum);
return sum;
}
// after some testing there is not path from out -> dac or out -> fft or out -> src
// our fft -> dac
// so the result is just svr -> fft * fft -> dac * dac -> out
println!(
"sol2: {}",
count_paths("svr", "fft", &HashSet::new(), &graph, &mut node_hit)
* count_paths("fft", "dac", &HashSet::new(), &graph, &mut node_hit1)
* count_paths("dac", "out", &HashSet::new(), &graph, &mut node_hit2)
);
Ok(())
}
fn main() -> Result<()> {
sol1()?;
sol2()
}

10
src/day11/test.txt Normal file
View File

@@ -0,0 +1,10 @@
aaa: you hhh
you: bbb ccc
bbb: ddd eee
ccc: ddd eee fff
ddd: ggg
eee: out
fff: out
ggg: out
hhh: ccc fff iii
iii: out

13
src/day11/test2.txt Normal file
View File

@@ -0,0 +1,13 @@
svr: aaa bbb
aaa: fft
fft: ccc
bbb: tty
tty: ccc
ccc: ddd eee
ddd: hub
hub: fff
eee: dac
dac: fff
fff: ggg hhh
ggg: out
hhh: out

1030
src/day12/act.txt Normal file

File diff suppressed because it is too large Load Diff

448
src/day12/main.rs Normal file
View File

@@ -0,0 +1,448 @@
use anyhow::Result;
use std::{
collections::{HashMap, HashSet},
fmt::Debug,
fs,
};
#[derive(Debug)]
struct Area {
width: u64,
height: u64,
reqs: Vec<usize>,
hash: HashMap<usize, usize>,
}
impl Into<Area> for &str {
fn into(self) -> Area {
let mut niter = self.split(":");
let mut positer = niter.next().unwrap().split("x");
let width: u64 = positer.next().unwrap().parse().unwrap();
let height: u64 = positer.next().unwrap().parse().unwrap();
let (reqs, hash) = niter.next().unwrap().trim().split(" ").enumerate().fold(
(Vec::new(), HashMap::new()),
|(mut v, mut h), (i, to_num)| {
h.insert(i, to_num.parse().unwrap());
for _ in 0..to_num.parse().unwrap() {
v.push(i);
}
(v, h)
},
);
Area {
width,
height,
reqs,
hash,
}
}
}
fn try_all_vars(
area: &Area,
shapes: &HashMap<usize, Vec<StrictShape>>,
list_of_reqs: Vec<usize>,
cur_shape: StrictShape,
) -> bool {
if list_of_reqs.len() == 0 {
return true;
}
let mut reqs = list_of_reqs.clone().into_iter();
let cur_idx = reqs.next().unwrap();
let reqs: Vec<usize> = reqs.collect();
// TODO check if the current shape fits in the box
// We don't have to loop because if we can not fit the first
// we will never be able to fit any way
for s in shapes.get(&cur_idx).unwrap().iter() {
let possibles = cur_shape.try_to_attach_all(area, &s);
for p in possibles {
if try_all_vars(area, shapes, reqs.clone(), p) {
return true;
}
}
}
false
}
impl Area {
fn valid(&self, shapes: &HashMap<usize, Vec<StrictShape>>) -> bool {
let mut reqs = self.reqs.clone().into_iter();
let cur_idx = reqs.next().unwrap();
let reqs: Vec<usize> = reqs.collect();
// TODO check if the current shape fits in the box
// We don't have to loop because if we can not fit the first
// we will never be able to fit any way
// also we only need to test one here and this one "sets" the orientaion of the world
if try_all_vars(
self,
shapes,
reqs.clone(),
shapes.get(&cur_idx).unwrap().iter().next().unwrap().clone(),
) {
return true;
}
false
}
}
#[derive(Eq, PartialEq, Clone, Hash)]
struct Shape {
lines: Vec<Vec<bool>>,
}
#[derive(Eq, PartialEq, Clone, Hash)]
// It can not rotate or flip but it's faster for comparions
struct StrictShape {
lines: Vec<u64>,
width: i64,
}
const ALL_ONES: u64 = 0b1111111111111111111111111111111111111111111111111111111111111111;
impl StrictShape {
fn get_attach_poins(&self) -> Vec<(i64, i64)> {
let mut attach_points = Vec::new();
for (y, line) in self.lines.iter().enumerate() {
let mut line = *line ^ ALL_ONES;
while line != 0 {
let i = line.trailing_zeros();
line ^= 1 << i;
if 64 - i < self.width as u32 {
attach_points.push((y as i64, 64 - i as i64));
}
}
}
attach_points
}
fn get_size(&self) -> (i64, i64) {
(self.lines.len() as i64, self.width)
}
fn try_to_attach(&self, to_attach: &StrictShape, y: i64, x: i64) -> Option<StrictShape> {
// Calculate the matrix
let (s_h, s_w) = self.get_size();
let (a_h, a_w) = to_attach.get_size();
let height = if y < 0 {
(y.abs() + s_h).max(a_h + y)
} else {
s_h.max(a_h + y)
};
let width = if x < 0 {
(x.abs() + s_w).max(a_w + x)
} else {
s_w.max(a_w + x)
};
let mut lines = Vec::new();
// i_<> is the offset into the to_attach shape it can go out of bounds on the positive side
// o_<> is the offset into the self shape it can go out of bound both sides
for i_y in 0..height {
let self_y = i_y + y.min(0);
let to_y = i_y - y.max(0);
if (self_y < 0 || self_y >= s_h) && (to_y < 0 || to_y >= a_h) {
lines.push(0);
} else if self_y < 0 || self_y >= s_h {
lines.push(to_attach.lines[to_y as usize] >> x.max(0));
} else if to_y < 0 || to_y >= a_h {
lines.push(self.lines[self_y as usize] >> x.min(0).abs());
} else {
let a_line = to_attach.lines[to_y as usize] >> x.max(0);
let self_line = self.lines[self_y as usize] >> x.min(0).abs();
// There is an itersection
if a_line & self_line > 0 {
return None;
}
lines.push(a_line | self_line);
}
}
Some(StrictShape { lines, width })
}
fn try_to_attach_all(&self, area: &Area, to_attach: &StrictShape) -> Vec<StrictShape> {
// println!(
// "Trying to attach {:?} \n{:?}\n with \n{:?}\n",
// area, self, to_attach
// );
let (s_y, s_x) = self.get_size();
let (a_y, a_x) = to_attach.get_size();
let min_x = (-(a_x as i64)).max(-(area.width as i64 - s_x));
let max_x = (s_x + a_x).min(area.width as i64 - a_x as i64);
let min_y = (-(a_y as i64)).max(-(area.height as i64 - s_y));
let max_y = (s_y + a_y).min(area.height as i64 - a_y as i64);
if min_x > max_x || min_y > max_y {
//println!("Could never attach");
return Vec::new();
}
// println!("found bounds {} {} -> {} {}", min_y, min_x, max_y, max_x);
// Try edges
let mut new_possible_shapes = Vec::new();
for y in min_y..0 {
for x in min_x..=max_x {
if let Some(merged) = self.try_to_attach(to_attach, y, x) {
// println!("Found shape {y} {x} {merged:?} ");
new_possible_shapes.push(merged);
} else {
// println!("Could not find shape {y} {x}");
}
}
}
for y in s_y..=max_y {
for x in min_x..max_x {
if let Some(merged) = self.try_to_attach(to_attach, y, x) {
// println!("Found shape {y} {x} {merged:?} ");
new_possible_shapes.push(merged);
} else {
// println!("Could not find shape {y} {x}");
}
}
}
for y in 0..=(s_y).min(max_y) {
for x in min_x..0 {
if let Some(merged) = self.try_to_attach(to_attach, y, x) {
// println!("Found shape {y} {x} {merged:?} ");
new_possible_shapes.push(merged);
} else {
// println!("Could not find shape {y} {x}");
}
}
for x in s_x..max_x {
if let Some(merged) = self.try_to_attach(to_attach, y, x) {
// println!("Found shape {y} {x} {merged:?} ");
new_possible_shapes.push(merged);
} else {
// println!("Could not find shape {y} {x}");
}
}
}
let r_y = min_y..=max_y;
let r_x = min_x..=max_x;
for (p_y, p_x) in self.get_attach_poins() {
// println!("in {p_y} {p_x}");
if r_y.contains(&p_y) && r_x.contains(&p_x) {
if let Some(merged) = self.try_to_attach(to_attach, p_y, p_x) {
// println!("Found shape {p_y} {p_x}{merged:?}");
new_possible_shapes.push(merged);
} else {
// println!("Could not find shape {p_y} {p_x}");
}
}
}
new_possible_shapes.sort_by(|a, b| {
(a.width * a.lines.len() as i64).cmp(&(b.width * b.lines.len() as i64))
});
// if new_possible_shapes > 0 {
// println!("Best shape {:?}", new_possible_shapes[0]);
// }
new_possible_shapes
}
}
impl Debug for StrictShape {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\n")?;
for line in self.lines.iter() {
let line = format!("{line:064b}");
let line = line[0..(self.width as usize)]
.to_string()
.replace("0", ".")
.replace("1", "#");
write!(f, "{}\n", line)?;
}
write!(f, "")
}
}
impl Shape {
fn new() -> Shape {
Shape { lines: Vec::new() }
}
fn add_line(&mut self, text: &str) {
let mut line = Vec::new();
for c in text.chars() {
match c {
'#' => line.push(true),
'.' => line.push(false),
c => panic!("Not sure what to do {}", c),
}
}
self.lines.push(line);
}
fn rotate_right(&self) -> Self {
let mut lines = Vec::new();
let height = self.lines.len();
assert!(height > 0, "Something is wrong {:?}", self);
let width = self.lines[0].len();
for x in (0..width).rev() {
let mut new_line = Vec::new();
for y in 0..height {
new_line.push(self.lines[y][x]);
}
lines.push(new_line);
}
Self { lines }
}
fn flip(&self) -> Self {
let mut lines = Vec::new();
let height = self.lines.len();
let width = self.lines[0].len();
for y in (0..height).rev() {
let mut new_line = Vec::new();
for x in (0..width).rev() {
new_line.push(self.lines[y][x]);
}
lines.push(new_line);
}
Self { lines }
}
fn to_strict(self) -> StrictShape {
let mut lines = Vec::new();
for line in self.lines.iter() {
let mut n_line = 0;
for (i, c) in line.iter().enumerate() {
n_line = n_line | (*c as u64) << 63 - i;
}
lines.push(n_line);
}
StrictShape {
lines,
width: self.lines[0].len() as i64,
}
}
fn get_varients(self) -> Vec<StrictShape> {
let mut shapes_list = HashSet::new();
let shape1 = self.rotate_right();
let shape2 = shape1.rotate_right();
let shape3 = shape2.rotate_right();
shapes_list.insert(shape1.to_strict());
shapes_list.insert(shape2.to_strict());
shapes_list.insert(shape3.to_strict());
let fliped = self.flip();
let shape1 = fliped.rotate_right();
let shape2 = shape1.rotate_right();
let shape3 = shape2.rotate_right();
shapes_list.insert(self.to_strict());
shapes_list.insert(fliped.to_strict());
shapes_list.insert(shape1.to_strict());
shapes_list.insert(shape2.to_strict());
shapes_list.insert(shape3.to_strict());
shapes_list.into_iter().collect()
}
}
impl Debug for Shape {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\n")?;
for line in self.lines.iter() {
for c in line {
write!(f, "{}", if *c { "#" } else { "." })?;
}
write!(f, "\n")?;
}
write!(f, "")
}
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day12/act.txt")?;
let mut areas: Vec<Area> = Vec::new();
let mut shapes = HashMap::new();
let mut cur_shape = Shape::new();
for line in text.split("\n") {
if line == "" {
continue;
} else if line.contains("x") {
if cur_shape.lines.len() != 0 {
let vars = cur_shape.get_varients();
println!("Shape: {:?} {}", vars[0], vars.len());
shapes.insert(shapes.values().len(), vars);
cur_shape = Shape::new();
}
areas.push(line.into());
} else if line.contains(":") {
if cur_shape.lines.len() == 0 {
continue;
}
let vars = cur_shape.get_varients();
println!("Shape: {:?} {}", vars[0], vars.len());
shapes.insert(shapes.values().len(), vars);
cur_shape = Shape::new();
} else {
cur_shape.add_line(line);
}
}
let mut valid = 0;
for a in areas.iter() {
let mut count_of_1 = *a.hash.get(&1).unwrap();
let by_6 = count_of_1 / 6;
let left_over = count_of_1 % 6;
let mut area = a.width / 3 * a.height / 3;
if (a.width / 12 * a.height / 3) as usize > by_6
|| (a.width / 3 * a.height / 12) as usize > by_6
{
count_of_1 = left_over;
area -= (by_6 * 4) as u64;
}
let mut sum: u64 = 0;
for (i, v) in a.hash.iter() {
if *i == 1 {
sum += count_of_1 as u64;
} else {
sum += *v as u64;
}
}
if area >= sum {
valid += 1;
}
}
println!("sol1: {}", valid);
panic!("mad");
// We know that 3 only nicly packs with itself
let mut valid = 0;
for (i, a) in areas.iter().enumerate() {
if a.valid(&shapes) {
println!("Found Valid ans {i}\n\n\n\n\n\n");
valid += 1;
} else {
println!("Could not Find valid answer {i}\n\n\n\n\n\n");
}
}
println!("sol1: {}", valid);
Ok(())
}

33
src/day12/test.txt Normal file
View File

@@ -0,0 +1,33 @@
0:
###
##.
##.
1:
###
##.
.##
2:
.##
###
##.
3:
##.
###
##.
4:
###
#..
###
5:
###
.#.
###
4x4: 0 0 0 0 2 0
12x5: 1 0 1 0 2 2
12x5: 1 0 1 0 3 2

200
src/day3/day3-act.txt Normal file
View File

@@ -0,0 +1,200 @@
5373475263753258336423442254746263332334232217334431337464342726873125223932312363675175435324343745
5227321232617242424121783222444222475363212213321222132342222214234323243221324313544235426312222464
3634436825685764742673853355632449738648385234337738184436553468422227828633727443633344773725185424
6432363334534333332354533472355353543343324163334233844337333342523232333332323233345446433333333334
5253554747343627435239322411734624434454225333553633234482362555534336563442345333244536133542313453
2423525253342142354114242512322351422142111441453432113525242233541455144333444411525411412425356789
7457548947854345576964379783795564264476647666477495455786784535589395464575557455353546464866378696
8244225522942222455827286961533232252542523662528531275155742425423847432441487283274525627926222233
4155252354352542254435215252335232342233423222543534353512513132412342532425457251545454232235135313
4423314332342532422332434234432246241732233223256372333321225333255313321224222333123214312443112333
2243124441333416324326343442132333644263318824332443233252442433944231334363327323244632362234474345
7225167272477267928472436779877542926368456795236385736382637574254135783791379333499853212725973429
4336327865534476413441444393634373746633742333356335325428345354533445944341534489445433534342569446
5333333393382562632333554333342313747333446235364325737333234333233333843183333233953338335325333833
3624865646626545644364556713446546665261396965466627166574467565535669563969466646462666564745345562
6221227322256241683221668262231324222655256183543222526522122523221218222222212532443222232622322223
2452521237635585782525697567644363438664442242442255742544599222566549434347144254222622472527414436
8234533332523134832436442333453483476573331224333332833653345421423371363336125243433332345375233333
2225612311261421262232322232332123222294222322432423224231312112132252666223722126321232212121223224
2222133432223231622321112232326626243535235762442262445454555323247243712242222526514246255231322454
4434537433323532333334222133374766137255323633334673255339442711433332336416575435397384735763864393
2222113222121422132226233424248224222221222246221536222223422242222424244222122223221122132322332262
2126745366172773533825822336432646752366466184737516945626478683745266264466764526297743451493763475
6524211621282337434328621223212837142122621132322424221414222222321222223222237231343222732354143221
3433355533334123343373513433425535323233363344235134355335223373526533262335336331134325712333363245
2533626254536454454555644555457355445346545454535615544656567632546554525633235544373422563545645355
3454643254353423424435514244363635324446564334364152341615434553443537436523242475423244273334143413
9242223232222322134224432432231225222222233122224525243212442222324454345222263251222521332222422324
3523333373323324142433234333133432333343433344334433342331333233353332334431533343322433233334332233
7537856255759447856455653756577635358356868778778863767846664758558758648745346768765698843566866556
6768784746718464575476236766759786577778565794585776789876793635492775548564496777765693569664657773
3432225223512285125322443323535123263124931245414214935215212445316432234222122241221226514532324112
1122223222222225221323222221222223222222222212222522211222242321212112222222221231312223222222212232
1432632134342333242333433132333342233323221422334322353223331342132333233321121233323232232323332232
1363732334223221224462216126234223221232332623612232434223222215223242242432223223361422312222232426
5423222323473222323121324522231222222425322322322333131232222328221222321214232212122293222135333422
2355153332232924312333123621535224232121932225211512532313124222224415242231117221222621322122542222
3218236333634655335474644325845966525327852474633886338525549626385334478556445765673935473635423578
1243422631343111222443444322423442451543243465434224442324422454443234322122642342222447614146443424
3336642522238232252394122224112322262244238132422821255197223633329233222332152314226326423222421222
2142232222122223222223322322212211111222222222222222222622211222122112222122222221522212222222223222
2588747622425361325237363372322232576247242632253463622144463832662255563267344947776248445776864422
3213223222422313222341332422231322222123422232222252326123241331322428142124232222232244553332324323
2222122322123212224321243322222241234312221132133222222324311232222662223322231212922232242544232212
4233423234313332223433434424122334342313332343323332432333323333352231333333233243321333223123333333
2222123221272222242422162222534324322221641323221221321241232221223233428222141473211321423422631384
4334737733328254273273142134576325738543444423567745244653233555734525332752643254363565241525447265
3425233312433222312825344593123293437462824632733343323323434532333325333753333112337332323123653235
4222122122253222222221322421233212222322342242222222216122231423211232122142223236221122222221141123
3227256222222343333322512315235363443246825423822231233332358664332123277143633222522243232435362325
3241221212322322523621222332241224222524122222222312222232242212423223245212235232224122212212224122
5355833485933335465436549346535863336653823645535535542566365536833334333563522393553363312543358434
6162756366644554425422275355241462363242754877653635358246115435462282622674455364564396464662437558
4444243323344451353413432363433343434342524533313363453434234333341324333235333413544333235347424433
2433234333234334414443444221432424422236314523383524443234234544215333363454216447364331243235436254
2236112221123722542222223222231122232125121412222232326221232222222222222151222242223222221121223222
4424534213234421522122223214213223321146513232223145231232221232332424222234113223223462222321462222
1122222222294252453223223231535341123232222232223232251522622264212225211421232222222223132622212312
3443543363433464424226355413442442556346534334345333334333434311324533243235393323344534535924332355
3353443334233633234463345334433433334533138316534673135534334326656433532724332348928344457442357434
4256552622525454442522524522121312634544525252356432432515441345542324823551155342363825255344559245
3333323234442332433233253623333333363313233334343333323323533134343333336433334323133431331333323431
2322221362253122222632223224224354226222422722372222222522234222142123222222522222226242221212317222
3324343333523323322353325321432221242342242333333223421213123222232124443143253333243534343432422333
1353336356365245843433353233377533645375433346322535333752443634733383573534337163332364314426413624
4243431413122123238521322223225221472422272212222254623627222213433322222252124241524229226373211312
2323333333331223122122233223332532312233222231223212313223333231322232223531222222212142232322223332
1122222223211221322232222222222112221221222212222222222222212222222122222222322222222221222222122242
8756544345445365556328423537634534554853325555322947433473495557557546455534585535553554414456584574
3552342425232423324326252273293123232533426331393172253444465422252122231635232339235622223463664441
4434435545223322434233423425543623425444444434432444334435434234342243443343444443544343435353424353
5123223333323925428366223235322333213433232345344452423334213221242422234241322123832424534311143323
3421311323223223332356332212334328223333221236336333322352231362629521232352224362533232423216223132
9981675468833574376334846376964753584697463463356753444579315765783984943281146657755695757366534323
7742448223643654444423424582974573653283448857637437424334329563425338363422827332584486422361474433
4749437177764663678746475758734775656365376555355256684717575245881535885174835767767582458475864665
2222222133233121213223192212222622221323222312121222321423222123212222522232122222322222122122222132
9684528883423637783797677426188958357869529866557787524773425982487636956367546567898779867624834568
5327634662323337244322334362435245245434655332435217211246227274422232324454522225953243343672153242
2221232313222241214322222223232344412241433234212233244142212242122225123222222222222311221331212122
3323325233325324233221333333333333622234342433443232333333141338233533334313423433522334353333332333
1344556542236269262633377233423637477488332322552832623226626623224435638232324367953556338661254616
3354337335144535336453134445543432444636543634635654632645435435434253633476723465435515623333756431
6451342452443639334343945345485645623344445323958444333734774462563354334444745554354453353642341444
1543324635243553563238266524533247453553125452451157452243525135372521234435575562412365373654353625
2133325132462523522337223113313323232212344322243323223212422526234122222321324121221222222232231322
5234333333373343336343331232322625126333233333333262333333123333333233332324333343343431433341335313
2321321213322322333112223231132343236412222552452532222322114226432322232261432312142333744233544331
2212222322321213222124312422122222222151221211222224221222222122422121223122131222232221223121222221
7785674666567455843167769544534495688646445955473484257645966455776855584638153539727457669645867795
6232255234535553922649553554436673326234554342344353421222525354532865235235356732354546343323432445
7445295274438425555433751434486433246333244544475444443954365436666446157224554467355744427254237696
2222222332252222226112323314142431222227528222324221242143932232135223223242422922123112522131242241
2125342622352313213231312122222332222121232221233323312332213222222222322233122222222223232232332344
2231422222322122222212223121233452134225211223232222222311113231123323242123222222334322132222222322
1451132222613121235222243223412222222292223122322241232426442131321263222223232232232722312322635322
2223412282223324322332242344434242213221442232332122232222662222322332242222412533222133242222143222
2223229223322224243221222122222224112224222322222221222425236222142224222422232221132322222122311125
3522125454535313634658325643757246348476747524635551583655656384263245644355486553335545522664444336
2222132222223323332132232132312223272182323151222221122212422213222283222122373222123332112132222232
2522212231232222252112232222312167525312212122132452425129322223222252125611225242241612652222212312
1227423422323124121222123332222222222444122232212433435522412312193732523234421221222223221212121434
9246389235432525532983447349364944653383172583235543154873327294253522122535399738484333222554554242
4252427394953359297344523434543455396354353415564414997345244365336414654542459355355345242323399345
2243312264428215324252464334222423553224521328222224421421222344254332478432448234233445492422353422
6236822322342445551442222331227324425352344341446133226293232114234342322454232224443323243442413446
3456524546454424644445625454263556486363643322525432514465344464556726234656646345624575462545543654
2222324113284344262142222242322242226212342213224222222212233223123324212223322442525131152222123122
1346654677664226694244765535636534561523658967224333636543786634864543354594343166365587624423625558
2377235466265872245627636654435666547546332355462531655745722122514754754431745355254565724377143254
5439433234315344373252333253334224434222333333333333321433343444534363543224432344433333334344333322
7233612233312364134733443623624342422231332314434534222634333232232422233324144242442222324323332233
2424211141111421112121124232311221213111114441243442111421312131442444343243141333343224331213456789
2122222112122234322312232222132312322333332222223223412212252222332322233122322223222342222223122323
3522322232338334436331224323633332221243362322238225248357332322422221422321243142422232623313322112
5414444374645843483754542435255831432556442462135523456354355155524362535224352455334561425215435422
6223223225222212443234112162223233257241625632221232362223233312221242124114122321712621222212262222
2442433324245324243443344353442223544444533343544444442522244459354422214414425244663444344412424334
2332352423323342332422444332333423232332453332533333413123234224321333333232339343328313213423433333
2212253331244424242144152332342362334425234124324222123124344522423342322252423342244446433233223224
3453545455444525558145546463344394535655745353344544355443313353534433455435453542421363433342445674
8756535247554533235953566633515436556888426554441254545422552559318556143887555565458344843356545336
5521823882453441579147869666432552224284649275334622849893844167775656366549414455664665428462862793
7333222333311258124333333461373213323363643433334332143433333352333333333322363334333335333323536373
1353225243331522255254451545531522522453445447222247514235544524662411573725425545324255331344585442
4274832373492433853748534458333247746333376664228388776847343442636446433486655352568435532484429564
8232233334382737353363374333344337238644333354333249354742833353655433674153663223234444433384533324
2222221333222221232212221122222223222133124231222223333235223135223225123221122222212232131122231211
4132243123123413422242162333232222322332312412222443243232224442221321223263232234443122122223221342
2222138231221122221212124212623923222722225382372221423422125227642223422222223222313221212216221236
2932123323334243122223233122422232332311312232243321333242211322332422333336222424332332621312243122
4331333333443334444334343132245424432443323423323434233322531433433343223433343333433324443322333344
3523334333427622439383231345536345243338433345443234343953322654223133332473263433337316432345322951
3222431252327226351223224522232214353224224121222233343252431124323411723542355213212321234211212172
3124512222221222329222432342121122232232423212232262212134222222226122421232222422322222221122226222
9217344343385675435625379634874887323345383338248644443646538124478969276327643137695337975931719333
7137553544654525631345674551563575611772176652657272324415343261354717727764315367464462311266162489
2121535275225423351351332243525426723224533535614282253325233132635512352333323543431334344231223132
4242222263723111323322422223222451222222413242251223212232222242122222222121221251122212224331512222
2112352352531135151422212314132317225142121262222321232342122122312214142232232428172236232235123323
6126524423533554223255644422424652224536626362333253447444645652531656644244542164232443566675544656
3252547156446467266233742546425647766424242334521543476475324213646266423642426656264626224252645726
5744529753678684543677753764775568767564324735552244247261654685273864864538555553554885786675187786
2222123252212221822222543222211222182132222242823222232221132122218253732221222324225112222522922252
3323222413111243343132515233243323235312332533322135132631422324323223222333232333421342533221252233
3223554221263411654166663121214535445442533633464556234462653444335222162315255352425664415545643789
3542466535933853575551552555345248253353595358344168343445565696388567417233586243234255268432444525
1322222222352533222233321321212226223338221463732643131312322234119231233143241433223854332132822232
2133523321332211323422211362321433222342224213232343323417234322222233321342242533333333323333125238
4442532442331543445334443241333323353434444334533544644534435433336454333544334444124544525433444163
2122255211422232222434222242214523222222224142122422222222223221213212326122642221712212322232112122
2223221222122322132242212122212121422622422221222211231122111412132112231227112222212122222212222221
1331213223222623323223223223322333312313233223222226313243451322243322122222912233223441112123221221
4334333445443333433435348412343433352364442313928933345323235343742233233223244322433343334343413634
1522222323423232323223225111122231222222332232322221224362223321433262233344231212222233231222232221
4335544454842144444446562442444464464545614442635244564564544445646644657657463342444444454453443466
4535548864948745546467835655555553466857483844668454648734456326754834382865556374548845484357766846
6442335333644333635234445236435433347332334422323236543543232446322243343233424436842632556345548252
1253223323252432332822153263384394346433232233323343355652343618122542243583453323355245542323234234
4321122212222122322212231221312212222222232221222122226212122231226522123333222323228111122242232352
3543245537344421334462492335237225273253334356412524322253263323242343425433444332124232134323632562
5354553445358856434533465543457553455575652335335542522634455356544478763545454245455555443349353332
2413324238344155244516224434225614433244324423242433224325224634222433555241342432331443474445331431
3232793334393323356314732426321832338331263333733333763112323332213613321827135523322336211223552226
7462432234672311647443274431982643375242412322344446634494723247257834236432332443636744942622351328
4422444122433223232241312322313412432322322223343213222322223421132223213322322212323621221132123122
3126222523212233244315222323522321522673252342434623447233544232423462461162425523222352661222722228
6222322122227256322229222826252232222272262274123262211222382212252112226216562227222222713181322236
2222222222222226233311223333522212323222224323212323331322322628123322233222122224266211221322222223
4455233345325522251243563224514424431254544325534222256443253343245265272521824454252443344523433443
5432424444383432242432331434224444243124249422414432352134171324234424244934432443242143225413444521
3113222334331225322232232223433244331324433223322124432362822322332432124233223332731222342341311222
2224341233323233332332233331231322233215235333333323122352233212232222432333223521232332333233333333
9322537356355554372654624537563375324425767232232374931332364233363536334623355364673653314157532664
2251162211122226565122222232228115331322251125221222221222231222211152222212252222222222562165121322
5443642434244523633142849234234448483434365285424343364444427423443436444554665344354215642437494241
3252222222252322223222221322222112221212222322251222322222211321232231342312232312231222122122232222
2142266334638584473814684445825848233686346436874518344736543847527354418686557411888833311355831649
3232331322233232333332425133223223432232113424432523313333122223223222243333625432333224333335233363
2222325295222132222112231262312223225222221242332122332222213261434432232322322232654221353222142222
5335253633223337443133443436355335433342352334333363333333132134334332423453343433343353111633323353
9438282551562642322555323414263458452851118575265524122325354376522253622262463224315562822566222927
2333242253136843333323235433245243247222262123623423232535223573543153133233855224353122325323923762
3234683424433365412363364392243327227234242342418332753644442222942563132234234731344219662653123233
3213232233232233216131232353312312212122622222212241252325332232223252553223422323233132332232221222
2222128224917522122223252222282898562721922922222212412212272286932222172922222287524552382232124222
7588737682216716295573557234566922257347722527378356685322827177812272782387342515268266277243223737
3435334532334364244242423544436225644443444434985133457145274348345423247363335144384344434884344732
5355863547465669655475557845454375565453545332543555735543415324853384554348875454667575541355525635
5564585557585228453324834457524545455463457443433455855333573552555547455447555156454535555555375455
4333145344315463834446334423644441433444334445623243341443444243344413445134372463434423343147414484
3252225313221554221545342412344345145455244454554342552452425153535332433254445541425514553124222152
3332355324424334493432313623523436445432547321333353336643473344333833354235423633473332633463334427
1221121122221222121232242222232611232512212212322211221222222322221222212223222213222222222124222122
5133423326355353252224232724552152332552362422315136223181431232312252242142322532461325224222154151
4442474734455435444374245749544544873457574442654433434446471364441584724544442335447443434555434244
5145154275546566645625545554554753555349544452665552365456458557435455545355575666533546644355555645
2211252232223132332221322328322221232362222322241262323382232333242322332822312122422222252152122122
8793499235353729234687469335236988344133963227937175952525334433884712497248337384875668621435953367
2222437223345352721242114242243132424423321322342222321424353272152143231321424542434432234244211122

4
src/day3/day3-test.txt Normal file
View File

@@ -0,0 +1,4 @@
987654321111111
811111111111119
234234234234278
818181911112111

47
src/day3/main.rs Normal file
View File

@@ -0,0 +1,47 @@
use anyhow::Result;
use std::fs;
trait NiceSum {
fn nice_sum(&self) -> u64;
}
impl NiceSum for Vec<u8> {
fn nice_sum(&self) -> u64 {
self.iter()
.rfold((0 as u64, 1 as u64), |(s, it), i| {
(s + ((*i) as u64) * it, it * 10)
})
.0
}
}
fn sol(text: &String, bat_size: usize) -> u64 {
text.split("\n")
.filter(|s| s.len() > 0)
.fold(0, |sum, sline| {
let line: Vec<u8> = sline.chars().map(|a| (a as u8) - 48).collect();
let mut best: Vec<u8> = Vec::from(&line[line.len() - bat_size..]);
for i in line.into_iter().rev().skip(bat_size) {
if i >= best[0] {
'removed: {
for j in 1..bat_size {
if best[j] > best[j - 1] {
best.remove(j - 1);
break 'removed;
}
}
best.remove(bat_size - 1);
}
best.insert(0, i);
}
}
sum + best.nice_sum()
})
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day3/day3-act.txt")?;
println!("sol1: {}, sol2: {}", sol(&text, 2), sol(&text, 12));
Ok(())
}

140
src/day4/act.txt Normal file
View File

@@ -0,0 +1,140 @@
@@..@.@@.@@.@@@@@.@@@.@@..@.@@@@@@@.@..@.@@@@@.@.@.@@@@@.@@.@@...@@@@.@@..@@...@.@.@@@@@@@@.@.@@@@@@.@@@@@..@@.@@@.@.@@@..@.@@@@.@@@@@..@@..
..@.@.@@@@@@@.@.@@@@@@.@@..@@.@@.@..@..@@@@..@.@.@@@@..@..@@.@..@@.@@.@@..@@@@.@.@@@@@@.@.@@@@@@@@..@@@@@@@@@@@@.@.@@.@@@@@@...@.@@.@@..@@.@
...@@@.@.@@@@@@....@..@.@@@@@@....@.@.@@.@@@@@@@.@@@.@@@@@@.....@@..@.@@..@..@@@..@@.@.@.@@..@@@@@@@@.@@.@.@.@....@.@..@@.@..@@@@.@@.....@@@
@@@@@@@@@@.@@@@@.@@@.@@.@@@.@.@@@@.@.@@.@@@..@.@..@@..@@.@@.@@@@..@.@@@@.@@@@@.@.@@@@.@.@@@@@@.@.@@@@.@@@@@@@@..@@.@@@.@@@..@...@@@@@@@@@@@@
.@@.@@@@@@@@@@@.@@@@.@..@.@@@@@.@..@@...@@@@@@@@.@@@@..@@@@@@..@...@.@.@.@@@@@.@@@.@@@.@@@.@@@@@@..@@.@.@@.@....@.@.@@@@@.@@@@..@@@@..@@..@@
.@@@@.@@@@@@@....@..@.@@.@@@@@@@..@@@@@@@@@@@@..@@@@@..@@.@..@..@@@.@.@@@@@@@@@.@@.@....@..@@@@@.@@@@@@@@.@@@@@@.@.@.@@@@@@@@.@.@.@@.@@@@..@
@@.@..@@@@@@@@@@...@...@@..@@@@@@.@@@@.@..@@..@...@@@.@@@.@@@.@@.@@@@@@@@@@@@@.@@@@@.@@@@@.@@@@@@@.@@.@.@@...@@.@@@.@.@@.@@@@.@@.@..@@@.@@.@
@.@@..@..@.@@@@@@@@@@.@@@...@@@@@@.....@@@@@@@....@.@@....@@.@@..@....@@.@@@@.@@.@.@...@..@..@@.@..@@...@.@@@@..@@@.@.@@@@@@@..@@@@.@@@@...@
.....@..@..@@@.@@..@@.@@@.@.@@.@@@@.@@@..@.@..@@@.@@@@....@@@.@@@@@@@@@.@.@.@@@.@@@...@@@@.@..@..@.@..@@@@.@@@..@.@@@@.@@...@@@.@@.@...@....
.@@@...@@.@..@@@@@@@.@@......@.@@@@@@@.@@@..@..@@.@@..@@@@@.@@@@@@.@@.@..@@@@@@@@..@@....@.@.....@@@@@@@.@..@@@@@.@@@..@@@@@@@.@@@@.@@@.@@.@
@@@@@...@@@@@.@.@@...@@@@@.@@@@@.@@@.@@@.@@@.@@@@.@@.@@.@.@@.@.@..@@...@@@@@@.@.@@@@@..@@@.@@@.@..@@@@.@.@@..@.@.@@@@@@@@.@@.@@@@.@@@@@..@@@
@..@..@@@@...@.@@@.@@@@..@.@@@@@@@@@@@@.@@.@@..@@.@@@@..@@@@@@@.@@@.@@@.@@@@.@.@.@@@@@@..@.@.@@@@@@..@@@.@..@@@@.@@@@.@@..@..@.@.@@@@@...@@@
@...@@@@.@@@@@@.@@@@@@@@@@@..@@.@@...@@.@@.@.@@@...@@@.@@.@@.@@..@@@@@@.@@..@.@@@@@@.@@@@.@.@...@@.@@@.@.@@@@@@.@@@@.@.@@.@.@..@@.@..@.@.@@@
.@@@@@...@.@.@@@@.@@@.@@.@@.@.@@@@.@@@@.@@@.@@@.@@@@@@..@@..@@.@@..@@@@@@@@@@@..@@@@.@@@@..@@@.@@@.@@.@@.@@@@.@@@.@.....@@@@@@@@@@@@@@@.@.@@
@.@.@.@..@@..@.@@@.....@@..@@.@@@..@@@@@@..@.@@.@@.@@.@@@@@.@@@.@@@.@@@.@@@@@@.@.@.@@@@.@.@@...@..@@...@@.@@@@@@..@@.@@@@.@@.@.@@@..@@@.@@@@
..@@.@@@@@@@@..@@.@@@@@@@@@.@.@@.@@.@..@@@@.@.@@.@..@@..@@@.@...@.@.@.@@.@@.@.@.@.@@@..@@@.@.....@@.@@@@@@@@@@@@.@.@..@....@..@@.@@@@.@.@...
.@.....@@@.@.@@@@@@@..@@.@@.@@.@@@@.@@@@@@.@.@@@@@.@@@@@.@@@.@@@@@@@.@@@@.@@@@...@@.@@@@.@@.@@.@@..@@..@@..@.@@@@@@@@..@@@@@@@@@@.@@@@.@..@@
@@@.@@.@.@@..@@@@@@@.@@.@@@.@.@@@@.@@.@......@.@@@.@.@@..@@@...@...@@.@@@@..@@@.@.@@..@.@@.@.@.@@@@@@..@@.@@.@@@@.@@@.@@.@....@@@..@.@@..@@@
@@.@...@.@@@.@.@..@@.@@.@@..@...@@@@.@.@@@@..@....@@.@.@@@..@@.@@..@@@@@..@@@.@@.@@.@..@@@@@..@@.@.@..@@.@.@.@.@@@@..@@..@@@@@@@@.@@.@@@.@@@
@@@@..@@@@..@@@@@.@@.@@@@.@.@@@@@@.@..@.@@@..@@@@@@.@@.@..@@..@@@@@...@@.@@@@@@..@@@@..@.@..@@@@@.@....@.@.@@@.@.@@@@@.@@.@.@@@.@.@@..@.@@@@
.@@@@.@.@...@@@@@.@@...@...@@..@..@.@.@@.@@.@.@.@@@..@@..@.@@.@..@..@@@@@.@.@..@@@.@@..@@.@.@@@.@..@@@@@...@@.@.@@@@.@@@@@@@@@@@@@@...@.@@..
@@@@@@..@.@@...@@.@@..@@@@..@@@@.@@@.@@.@@..@@@...@@@@.@@...@@@@..@@.@..@...@..@@@.@@@@.@@@@@@.@@@.@.@@@@@..@...@...@..@@@@.@.@@@@@@@@@@@..@
@@@@@@..@@@@@...@@@@..@@..@...@@.@@..@@@@@.@@@@@@.@.@@.@@.@@@@@@@@@.@@@@.@@@@@@@@.@..@.......@.@@@.@.....@..@@@@@@..@@@.@@@.@@..@..@@@.@@@@@
@@@@@.@.@@..@.@@@..@@@@....@.@.@@.@@@.@@@@@@.@.@.@@@..@@...@@@@@@..@.@.@@@.@.@.@@@@@.@@.@@@...@@@.@@.@@@@@..@.@@@@@.@.@.@.@@@@.@@@@@.@@@@@@@
.@.@@@.@@@@.@@.@@..@.@@...@.@@.@@.@.@@@@@@@.@@@@@@@@@..@@.@@..@@@@@@.......@@.@@@.@@.@@.@@@..@@@@@.@.@..@@@@@@@@@@@@.@..@@.@.@@@@@.@.@....@@
@@.@@.@@.@..@..@.@@@@@@@@@.@@@.@...@@.@@@@@@.@@@@@@@...@....@.@.@@@@@@@..@@@@@@@.@@@@.@@@@@@@@.@@....@.@@@..@.@.@@.@...@.@@@..@@......@@@@@@
@@@@.@@@@.@.@@@.@@.@@@@.@@@.@...@.@.@.@@@@.@@@@@@...@.@.@@.@..@@@@@.@@@@@@.@.@.@.@@@@@@@...@....@.@@.@.@.@....@.@.@@.@@@.@.@@.@@@@@.@@@@..@@
@..@.@.......@@@@@..@@.@@.@@@@.@..@@.@.@.@.@@@.@..@.@..@@.@@@@@@@...@@@@..@@@@....@@@..@@..@@@.@.@@..@@@..@@..@@@@@@@..@@.@.@@..@@.@@.@.@@@@
@.@@@@@@@@.@..@@@.@@@@...@@@.@@.@@@@@@@@@..@@.@.@...@@@@@.@.@.@..@..@..@@@.@..@@..@@@@@.@.@@@..@@.@@@@@.@.@.@@....@@@....@.@...@@@@.@@@@.@@.
@..@..@.@@@@..@@@.@.@@@@@@@@.@@.@@@@@.@@@@@..@@..@.@.....@@.@...@@@...@.@@@@@.@@@@@@@@.@@@@...@.@.@.@@@@@.@.@.@.@@@@@@.@@@@.@@.@@.@@@@@@@@@@
@.@@.@@@@@@.@@..@.@@@@....@.@.@.@@.@.@.@@..@@.@.@.@.@.@.@.@...@@@@.@..@@..@.@@@.@.@.@.@..@@@@@.@@.@@@@@@.@@.@@@.@.@@@@.@@@@@@@@@@.@..@.@@..@
@..@.@@.@@..@@@@@@.@@@@@@@@@.@.@@@@...@@.@@.@.@.@@.@@@.@....@@@.@.@@.@@.@.@@@@@@.@..@@.@@..@.@...@..@.@@..@@...@..@.@@@@.@@@.@@@..@@@@@@@@@.
@.@@@...@@.@@@@.@@..@@.@@..@.@@.@@@@...@@@@@..@@..@@.@@@@.@@@@.@@.@..@@@@.@.@@@@@@@.@@@@.@@..@@.@@..@@@.@@.@@@@@@.@@.@@@@@@@@@@@@@.@@@@@@@@.
.@@@@.@@@@.@.@@.@@@@@.@..@.@@@.@.@.@@@..@@@@@@@.@@..@..@@.@@@@..@.@.@@@..@....@@@@@@.@..@..@@@..@@@@@.@@.@@.@@..@@@@@@@@@@@..@@.@.@.@.....@@
@@@@@@..@@@@@@@..@.@@@.@@@..@@@@.@@..@@.@@..@..@...@@@@.@@@@@.@@@@@..@.@@@.@....@@@@@@@@.@..@@.@@.@@@.@..@@..@@@@@@.@@@.@.@@.@..@@@@@@@.@.@@
@.@@..@.@@@.@@@@.@@@@@@@@...@.@@@@@@@@.@@@@@..@@@.@.@@@.@@@..@.@..@@@@@@.@@@@@.@@..@@@.@@@.@@@@.@@@@@@@@@.@.@@@@.@@@..@...@.@@@@@@...@@@@@@.
@@..@@@@@@@@@.@@@@@@@@@@@.@@.@@.@@@@.@.@@.@..@.@.@.@@.@@@@.@.@@.@...@@..@.@@.@@.@.@@@@@.@@..@@@@.@@.@@@.@@@@@..@.@@@@@.@@..@..@.@...@@@.@.@@
@@@@.@@@@.@@@.@.@@@...@@.@@@@.@@...@@@@...@@.@@.@@.@@@@@@...@.@...@..@...@@@@@.@@@@..@.@..@@@@@@@.@..@.@@@@@@@.@.@@@.@@.@.@.@@..@@.....@@@@.
.@@.@@.@.@@@@.@@.@..@.@.@@.@@@.@@.@@.@@.@.@..@.@@@.@@@@@@@@@@@@...@@@@@@@@@.@@.@..@.@.@@@.@...@.@@@@@@@@@@@..@.@@@@..@..@@...@@@.@@....@..@.
@@....@@.@@@@.@.@.@.@@@@@@@@....@@@.@@@@@@..@@.@@.@.@@@@@.@@@.@..@..@....@@@@@.@@@....@.@..@..@@@.@..@..@@..@.@.@@@@@.@@..@...@@@@@@..@@@@@@
.@@.@@.@.@.@.@..@@@.@@.@@@...@@.@@@.@@.@..@@.@@@.@@.@@@@.@@.@@@@.@@@@@@@@...@..@@@..@@@.@@.@.@..@@@@@@.@@.@@@.@..@..@.@.@@@@@..@@@@@.@@.@.@.
@@..@@.@@@.@.@@@..@@@.@@@@.@.@@@@..@@@@@@@@.@.@.@@@.@.@@@@@@@..@.@@@.@@@@...@@@.@@@@.@@@@.@@@@.@@@@.@@.@.@@@.@.@@@@@@.@@@..@@.@.@.@@...@@@.@
@@@@.@@@@.@@@@@@@@..@@@@.@@@.@...@..@..@.@@@@.@@@@@@@@@@.@@...@.@@@@@@...@@@...@@@@..@@@@@@.@@.@@.@.@@@@@.@@@.@.@@@@@@@@@.@@@@@@@@@@@....@.@
@@.@@.@.@@@@@@@.@@@.@@.@@@@@@@@@....@.@..@@@@@@.@@..@@@@...@..@@..@@@@.@.@@@@@@@@@@.@.@@@..@@@@@.@@@@....@.@@.@.......@.@@.@@@@@@@@@@@.@@.@@
@@@@.@@@...@@@.@@@..@@......@@.@.@.@@@@@@@@@@@.@..@@@@...@@@..@@.@.@...@.@.@@.@@.@@@...@.@@@@@@@@@.@@@@@@@@..@.@@.@.@.@@.@@@.@.@.@.@@@@@@@.@
@@@@.@@@...@@.@@.@@@..@...@@@@@@.@@@@@@@.@@@...@.@@@@@.@@@...@..@@@..@@@@.@@@.@.@.@.@.@@..@.@.@@..@..@@@..@@@.@.@@@.@@...@@.....@..@...@@@@@
@@@...@@@@@.@@.@@@@@...@.@@@.@@.@.@@@@@@..@@@.@.@@.@@.@@@@.....@@.@.@@.@@@@@..@@.@.@@...@@@.@.@@@@@.@@@...@@..@@@...@.@@@@@...@@@@@.@@@@@@@.
.@@@@@.@..@.@@...@@@@.@.@.....@..@@..@@@@@..@@.@@@@@@.@.@@@@@..@@.@..@@..@@@.@.@@.@@.@.@...@@@@@.@@.@.@..@@@.@@@@...@..@.@.@@@@@.@@..@..@@@@
@..@.@.@.@@@.@@.@.@@.@@.@@@@...@.@...@.@..@@@.@...@@@....@@@@.@@@@@@.@@.@@.@@.@@@@.@...@@@@@..@@..@....@.@@@@@@@@..@@@.@@@.@@@@@@@...@.@..@@
..@@@....@.@@@@@@@@..@..@@.@@@@...@...@@.@@@@.@@@.@..@@.@@@@@@@.@@....@@@@@.@@@.@@.@..@@@.@@.@..@@@@@@@...@...@.@@@@@.@.@@...@@@.@@.@.@@..@@
@@.@@@@@..@@@@...@@@@@..@..@...@@@@@.@@@@.@@@@@@@@@@...@.@@@@@@.@@@.@@@@@..@.@@.@@.@..@@@@@...@@@.@@@@@.@@.@@@@@@.@..@@@.@@@.@@@@@..@..@@.@.
@.@@@.@.@@.@@@..@@@@@@...@.@@.@.@@.@@@..@..@.@@@.@@@@@.@@@.@@@@@..@@.@...@.@..@.@@.@@.@@@@@..@..@..@@.@@@@...@@@.@.@@@.@@...@...@..@@@..@..@
@@@@@@@@@.@@@.@.@@@@.@..@.@@@.@.@..@@@..@@.@.@.@@.@@..@@@@.@@..@.@@@@@@.@@..@@@@@.@@@@.@@@@@@@@@@.@@.@...@@@@@.@@.@@@.@@.@.@@..@.@@.@@..@@@@
@.@@@@.@@..@@...@@@.@@..@.@@.@@.@@@.@.@.@.@@@@@@@@@@@@@@@.@@.@@@.@@.@@@.@@@@@@@@.@.@@@@@@.@@..@..@@@@@@.@@@@@@@@@@..@@..@@@.@.@@@@@.@@.@..@@
@@@..@.@.@@.@@@..@@..@@@.@@.@@@@@@@@@@@@.@@@@@.@@@...@@..@@..@.@.@.@@..@@@.@@@@@@@@@@..@.@..@..@@@@@.@@@....@..@@.@..@..@@.@...@@.@@@@@@@@.@
@@@.@@..@.@@.@@.@@@@@@@@...@@@@@.@@@@@@@.@.@@@.@..@@..@@..@@@@@@@@@@@@.@@...@@@@@.@....@@@@.@@....@@.@.@..@.@@.@@.@@.@@@@@..@.....@.@@@@@@@@
@...@.@@@@@@@.@@...@...@@@.@@@.@@..@@.@.@@@@@@@.@.@@.@@@.@@@@.@@.@@.@@@@@@.@@@@@@.@..@@@@@@@.@..@@@.@.@@@@.@...@@..@@@...@@@@...@@.@.@@.@@@@
.@@@.@@@@@@@@.@..@@..@.@@@@..@@@@.@.@@..@@@@@@@@.@@@@@...@..@@.....@...@.@.@...@@@@@@@@....@@@@..@.@@@@@@.@.@@@..@.@.@.@.@@@.@..@.@@@.@@..@.
.@@@@@@@@..@.@...@@...@.@.@@.@@@@@@..@...@@@.@@.@@.@..@@..@@@@.@.@....@@.@@@@.@@.@.@@.@@...@@@@@@@..@@@..@@@@@@@@..@@..@@@..@..@.@.@@.@@@@.@
@@.@@...@@@.@@.@@@@@@.@@@.@@@@@..@.@@@..@@.@..@.@@@.@@@@@@.@@@.@.@@@.@@@@.@.@..@....@...@@.@@@@@@.@@@@.@...@@@@@@@@@.@@@@.@@@@@.@@@@...@@@@@
@@@.@@..@@.@@@@@@.@.@@@@@@@@.@@@@@@@@@.@@.@@.@@.@......@.@.@.@.@@...@..@..@@.@@@.@@@.....@.@.@@....@.@@@....@@@.@.@.@.@@@@@@@@@@@.@@@.@@@@..
@.@@@@@...@..@@@@@@@..@..@@@.@..@.@@@@@@@...@@@@@@@.@@@@.@@..@.@..@@@@@..@..@@@.@@..@.@@@@@..@@.@@@.@.@@@@@@@..@..@@..@.@@.@@@@@@@.@..@@.@@.
..@@@@@@@.@@@@@@@@.@@@.@@@.@@@..@@.@@@@@@@@..@@@.@..@@@@@....@@@@.@@.@@.@.@@....@..@@.@@@@@.@@.@.@.@@@.@@.@@@..@@@@@@.@@@.@@@.@@.@@.@@.@@@@.
.@@.@@.@@@@@.@.@.@.@@@..@@@.@@@@@..@@.@....@...@@.@@@..@@.@@@.@@@.@@@@.@....@@..@@@.@@@@..@@..@.@.@@@.@@@@.@..@@@...@@...@@.@...@@@...@..@.@
@@@@@@@@@@.@@..@@@...@@@@@@@@..@.@@..@@....@@@@@@.@.@@@@@...@.@..@@@@..@@@@@..@.@@.@@@@..@@@@@@..@.@@@...@@@@..@@.@.@@..@@@@@.@@@@@.@.@@.@..
@@.@@@@@.@@@@.@.@.@@@@@@@.@@@...@@@@@@@@@@@@.@@@..@@@@@..@.@@@@@.@@.@@@@..@@..@.@.@.@......@@...@@@.@@..@@@@@@.@@@@@...@..@@@@@.@@@@@.@@..@.
@..@@@@...@.@@@@@..@.@@@.@.@..@@@@..@.@@@@.@...@@@@.@...@@.@@@@@@....@.@@@.@@@.@@.@@@.@@@@@@.@..@....@..@@@..@.@.@@..@@@@@.@@@@..@@.@.@@@.@@
.@@@@..@@@..@@.@.@..@@.@@.@@@...@..@.@@@.@.@@.@.@@@....@@@.@@@@@@@@@@@@@@.@..@..@@..@@@.@@@@@.@.@@..@@.@.@@.@@@@@@@.@.@...@..@@@@@@@@..@@@@@
@.@@@@.@.@.@@.@@@..@@@.@@@..@@@@@@@.@.@.@@@...@@@@.@.@.@..@@@..@@@.@@.@.@@..@@.@.@@@.@..@.@.@@@@@..@@@@@@@.@.@..@@.@.@.@@@.@.@..@.@@.@@@.@@.
@@@.@@@@@@.@@@@.@.@@@@.@@.@..@.@@..@.@...@@@@.@.@.@.@@.@@@....@@@@@@..@.@@@.@@@.@@@@..@@@@@@.@@@.@@@@@@....@.@...@@@@.@@@@@@.@@@...@.@@@.@@@
@.@@.@@@@@@@@.@...@@..@@.@@@@@@@.@.@@@..@@@@@.@@@@@.@@@@.@@.@@.@@....@@@@@@@..@.@@@@@@@@@@..@...@.@.@@.@@@.@@@..@@@...@..@@.@@..@@..@.@@@@@.
@.@@..@....@@@@.@..@@@@@@@@@@...@@@@..@@@.@@...@@@.@..@@@.@.@@.@@@@@@.@.@@@@@@@@@@@@@@@@.@@.@@.@@@@@@@.@@..@@@@@@@@@.@@@@@@@.@@.@.@.@@.@@@@@
@.@.@@@.@@.@@@.@@@@@..@@@.@.@.@.@@@@@.@@..@@@.@@@@@@@@@@.@@@@@.@@@@@@.@@@.@@@@@@.@@.@@@@.@..@@@@@@..@@@@@.@@.@@@@.@@..@@.@@@@.@.@.@@@@@...@@
@@@@@..@.@@@..@..@.@@@@...@@.@@@@@@..@@.@@@@.@..@@@.@.@@.@@@@.@.@@@@.....@...@@....@.....@@..@.@@@@@.@@@.@@@@..@@.@@.@@@..@.@@@@@@@.@..@.@@@
.@@@..@@@@@.@@@@.@.@.@@.@@@.@.@....@..@@.@@@..@.@@@@@@.@@@.@@..@..@.@.@.@@@.@@..@@@....@@@..@@@@@@@@.@@@@@@@..@.@...@@@.@@@@@..@@..@@.@.@@.@
@..@@@.@@..@@.@@@@@....@@@@@@@..@@@@.@.@@@..@.@@@.@@@@@@@..@@.@@@@.@..@.@@.@..@@@@..@@@.@..@@@@@.@@.@@..@@@.@@@@.@..@.@@@@.@.@@@@.@@@@@@@@.@
.@@@@@.@@@.@@@@@@@@..@@@..@@.@@@@@@@.@@@.@.@.@.@@..@@.@...@@@@.@.@@.@@@..@.@@@@...@.@@.@@@.@@@..@@@.@.@.@..@@@@.@...@@.@....@@@.@..@@@.@@.@@
@@..@@.@.@@@@@@.@.@.@.@@@@.@@..@@@..@@..@..@..@@.@@@.@@.@@@@@@@@.@.@@.@.@@@@...@@@@.@.@@@.@@@@...@.@@@@@@@@@@@@.....@.@@.@@..@@..@@@..@@@.@@
@@@.@@@@@.@.@@.@@.@@.@.@@@@..@@@..@..@.@@.@@.@@@@@...@@@.@@..@.@@@.@@.@@@@@@@@@@@..@.@@@.@.@@..@@.@.@@@.@@.@@@@@.@.@@.@@@@@@@@@@@@..@@...@@@
..@@@@@@..@...@@@@.@.@@@@..@.@@@@...@..@@@@@@@@@@.@@@..@@@.@@..@@@.@@@@@@..@@@@.@@@@@@@@.@...@.@@.@@@@@@@@@..@@@@..@.@.@@@@..@@@.@@@@@@.@@@.
@@@@...@@@@@@@@.@@@@@@@..@@@@@@...@@...@@@@@.@.@@.@@@.@@@..@.@.@@@@@@@@...@@@@@..@.@@@@@@@@@.@@.@@@@@@@@@@.@@@@...@@@@@@@.@@@..@...@@@.@...@
@.@@@@@.@@.@..@@@@@@@@@@@.@@@@.@@.@@@.@@.....@@..@@@@@.@@..@.@@@.@@@...@@@.@@@.@.@.@@.@.@.@@..@.@@@@@@..@.@@.@..@@@.@@@..@@@@...@..@@@@@@...
@@@@.@@@.@.@@@@.@@@@@@@....@@@@@....@.@..@@@.@...@@@.@@..@@@...@..@@@@.@.@.@...@.@@@@@@@@.@@@.@@@.@.@@@.@@@.@.@.@@@.@.@@@@@@@..@@@@@...@.@.@
@.@@@.@.@.@@@@@@.@..@@.@.@@.@.@.@.@@@@..@@..@...@@@@@..@.....@@@@..@@.@@@.@.@@@@@@@@@..@.@..@@@.@@.@@@...@.@@@@..@...@@@.@..@@@@..@@@@.@@.@@
@@@@.@.@..@.@@.@@..@.@.@@@..@.@@@.@@@@.@.@@@@@@.@.@@@@@@@@@.@@@.@.@@@@..@@@.@@.@@.@@@@@....@..@@.@@@@.@..@@@@@.@@@@..@@@@@@...@@@@.....@@@@.
.@.@.@@@@@@.@@..@@@@@@@@@....@@@@.@@.@@.@@@.@@@..@.....@@@@.....@@..@@..@@@@@@@@@@.@@@@.@.@@@@@..@@.@..@@.@.@@@@..@.@@@.@.@@.@.@@.@@@.@...@.
.@..@@@@.@@@.@@@.....@@@@@@.@@@@..@@.@@@.@@..@.@@....@.@..@@@.@.@@.@@@...@@@.@@.@@@@@...@.@@@.@@@.@.@@@.@@.@@@@@@@..@@.....@@@.@@.@@@@.@@@.@
@@@@.@.@.@..@@@..@.@@@@@@@.@@@.@@@.@@@.@@.@.@@.@..@@..@@.@@@.@@@.@@@.@@@..@@.@..@..@@@..@@@@..@....@....@..@@..@@@.@.@.@@.@@@@@@@.@@.@@..@@@
@@.@@@@@@.@@..@@...@@@@.@@@.@@.@.@.@@.@@@.@.@@@@@@@.@@@@..@@.@.@@@@@.@@@@.@.@...@@.@.@@...@@@@...@.@@@...@...@@.@..@.@@@..@..@.@@@@@..@..@@.
@.@...@@.@@@..@@@@@@@@.@..@@@@@@@@@@@...@.@.@@@@@..@@@@@..@.@@.@@@..@...@@..@@@@..@.@@@@@.@@..@@@.@@@@@@@@.@.@@@@..@@.@.@@@@...@...@@@@..@@@
@..@@@@@...@.@...@.@@@@@@@...@@.@.@.@@..@@@@@@.@@@@@@@@...@@@..@.@..@.@@@..@.@.@...@@@.@@@@@@..@@.@@@@@.@.@@.@@@@@@@@..@@..@@@@@@@@@@@.@@@..
@..@@@@@.@@@@@@@@..@@@@@.@@@.@@.@@@@@@.@@@.@@@@.@@@.@.@@...@...@@@.@@@...@@@....@..@@@@@@..@@@@@@.@.@@@.@@.@.@@@@@@@@@.@@@@..@@@@...@.@@..@@
@@.@@@@@@@.@.@@@.@@@@.@.@...@@.@.@....@..@@@@.@@@.@@@.@@.@@@@@...@.@..@@@.@..@@@@..@.@@..@@.@@.@...@@@@..@..@@.@.@@@@.@.@@.@@@...@.@..@@@@.@
@@.@@@@.@@..@@.@@.@..@@@@@@.@..@@.@.@@@@@@.@.@.@.@@@@@.@@@..@..@.@@@@@....@@...@@.@.@@@@@@..@@.@..@@@.@@@@@@@@.@@.@@..@..@..@@@@@..@@@.@@.@.
@@@@@@@.@.@@@...@@@.@@@@..@@.@@@.@@@@@..@.@.@@..@@..@...@.@@@@.@@@@@@@@@..@.@.@.@@@@@@..@@@..@.@..@..@@.@@.@..@@@@@@@@@@....@@@@....@.@.@@@.
@@.@@@.@@@@.@..@@@@@.@@.@.@.@.@@..@.@.@.@@@@@.@@@@.@@..@@...@@.@.@@@..@.@@@..@@@@@.@@@@.@@@...@.@@@@@@.@@.@.@..@@@.@@..@.@@.@@@@@.@@.@..@..@
.@.@@@@@.@@@@@......@...@@@..@.@@@@@@@@...@@.@..@..@@.@@.@.@@@.@.@@..@@@.@..@@@.@@.@@..@@@@@....@@.@.@@@@@...@@@.@@@@..@..@@@@@.@..@@@@@@.@.
.@@.@@@@@..@@@.@@@@....@@@..@@.@....@@@.@.@@@...@@@@.@..@@@@..@.....@.@@@@@@.@@@.@@..@.....@@@.@.@@@@..@.@@@@@@@.@@@.@@.@@.@...@@@@@@..@...@
@@@@@@.@@@@..@..@.@@@@@@@@@@.@@@@@.@...@@.@@.@@.@.@@.@@...@@@..@@@..@@....@@@.@.@.@@@@@..@.@@.@@.@@@@@.@@@.@.@@@@@@@@@@.@@@..@@@@@@...@.@.@@
@@.@@.@@@..@@.@@@..@@@@@@.@.@@@@.@@.@@....@@.@.@.@@@.@@@@...@..@@.@@@@..@@.@@......@.@.@@..@@@@@.@@@.@.@@.@@.@@@.@...@@@@.@.@@@.@@@@@@@@..@@
@...@.@.@@.@.@@@@..@.@..@@@@@@@@@..@@@@@@@.@@@@@...@@@.@@@@@.@@.@.@.@@@@.@@@.@@@.@@@@@...@.@.@@.@@.@@@@...@@.@.@@@@.@@.@..@@@..@@@@@@..@.@.@
@.@@@@@@@..@@@@.@...@.@.@@@@...@.@@.@@.@..@@@@.@@@.@@@..@.@@@.@.@@..@..@.@....@.@@@.@@@@..@.@@@@@@@...@@@@@@@@@@@@@.@@..@@@...@.@...@@@..@@@
@@@.@@@.@.@..@.@@..@.@@@@@@@@@@...@.@.@@@@@@@.@.@@@.@@.@.@@@@..@@....@@@@@...@.@.@@@@@.@@.@@@@.@.@@.@.@@@...@@@.@.@.@@...@@@......@@@@@@@.@.
.@@@@.@@@@@@.@@@@@.@@.@@@@@@@@.@@@@@...@@@@.@.@@@@......@.@@@@@..@@@@@.@@.@@@.@@@@@.@@..@@@@@@@.@..@@.@...@@@@.@.@.@@..@@.@@@@..@...@@.@@@@.
@@@@@@@@.@@...@@@@@@.@.@...@.@@@.@@@@..@.@@....@@@@@@@@.@.@@@.@@@.@.@@@@.@@.@..@@@.@@@@..@@.@@@..@..@...@@.@@@@@.@@@.....@@@@@.@@.@.@..@@@@@
@@@.@..@@.@@@.@..@.@@.@@.@.@.@@@@@..@.@@.@@@.@@@@@...@@@@@@.@.@.@@@..@@@@.@@..@.@.@.@@..@@.@@@@@.@..@.@@@@@...@@@@@@@@@.@@@..@.@@.@.@@.@@@@.
@@.@@@@@..@@@..@.@.@@......@@@.@@@@@..@@@..@@@@.@@@.@@@.@@@@.@.@@..@@.@.@@..@...@.@@.@@@..@.@.@.@@@@..@@@@@@.@@.@..@@...@@...@.@@@.@@@.@@.@@
@.@@@...@.@@@@@@.@@@@@@.@..@@@@@.@.@@@@@..@@.@@@.@@.@@@@@@@@@@.@..@@@@@@@@@..@@@.@.@@.@@@@@@@.@..@@@@@..@...@@.@@.@@.@@@.@@@@@@@@@....@@@.@@
@@@@@@@.@@@@.@..@@@.@.@@@@@.@@@@@@.@...@@@@@.@@..@@@@@@@@@.@@@@.@@@.@@.@@@@.@@@..@..@.@.@@@@@@.@....@@..@@.@.@@@..@..@@@@@..@@@@..@.@@@.@@@@
@..@@.@@.@@...@.@.@@@@@@@@@...@...@.@@.@.@@.@@@.@@@.@@..@.@@@....@.@.@@@.@@@@@@@@@@@@@@@@.@@@@@@@.@@@@..@.@@@@@.@@@..@.@@@@@@.@@@@.@@@@.@@.@
@@@.@@@@..@.@@@.@.@@....@@.@@..@@..@@@@@@@@@.@..@@@@@.@@@.@@...@.@@@@@@.@@@@.@.@@@.@@@@..@@@@.@....@@.@@@@..@.@.@.@.@@.@.@.@@@.@..@..@@@@@@@
@@@.@@@.@@@.@@@@..@.@@@@@@@@@@@.@..@..@@@@@.@@@@@..@@@@.@..@..@.@.@..@@.@@@@@@@@@@@@...@@..@@.@...@.@.@.@@.@.@@.@@@...@....@.@.@@@@...@.....
@@.@@@.@@@@@@@.@@@@..@...@@@@..@@@@@@@.@@@..@.@@@@@@.@@@...@@@.@@@@...@@@.@@@....@@.@@.@.@.@@@@@.@@@@@@..@...@@@@.@.@..@..@@@@@@@..@@@.@@@@.
@.@.@.@.@@@.@@.@@@@@.@@..@.@@..@.@..@.@@@.@@.@..@.@@@@@.@..@.@@@@@.@@.@@@.@@@@.@.@@@@@..@.@...@.@..@@.@@@@@@..@.@@@.@@...@.@@@.@@.@.@@..@.@@
@.@@..@.@@@@@@@@@.@@..@..@@...@@@..@.@..@@@@@.@@@@@@@@@@.@.@@@@.@@@@@@@@@@@@.@@@@@@..@@.@.@@@.@@@.@.@..@@@@@.@.@@@@@...@@.@@@.@@.@@@..@@..@@
@@@@...@@@@@..@@.@@.@@@.@..@@@.@@.@.@.@..@@.@@@@...@...@..@.@@@@.@...@@.@.@.@@..@......@@@.@@..@....@.@@@@.@@@.@@.@@@....@@@.@@.@.@..@@.@.@.
@.@@..@@@@@@@.@.@@...@.@.@@@@.@@@.@.@..@@@@@..@..@.@..@..@.@..@....@@.@..@@@@@@.@.@@@@@@@@@@@@@..@..@@.@@@@@.@@@@@.@.@@@@@@..@@.@...@@@@.@@.
@.@.@..@@@@@@@@@@@@.@@@@..@@@.@@@@.@@@..@@.@.@@@@..@@...@@.@@@@.@.@@@@@.@@.@@@.@@.@@@@.@@@@.@@@@@@.@@@...@@@@@.@@@..@.@@..@@.@@@@@@@...@@@.@
@@.@..@@@@.@@@@...@..@@..@@.@@@@.@@@...@@@@@@@@@@@.@.....@@.@@@@@..@@@@@..@@@.....@@..@@@@.@@.@@..@@..@..@.@@@@@....@@@@@.@..@.@.@@.@.@@@@@@
@.@@.@@.@@@.@@..@@@@@@@@@@@@@.@.@.@.@..@@@@@@@@..@...@@@@.@.@.@@.@@@@..@..@@@@@...@@.@@@@....@@@@@@..@.@@@@@@@..@@@.@..@@..@..@@.@@@@@.@@@@.
..@@@.@.@@...@@@@.@@@..@@.@..@@.@@@.@@.@..@.@@..@.@.@@@@@.@@@.@@@.@@@@@.@@..@.@@@@.@@@.@@@@@..@@.@@@...@@.@@@@@...@@@@@@@@@@@@..@@@@@@.@@@@@
.@.@....@@@..@@.@.@@@@@@@@@@@@@@@@.@@@@@.@@@@.@@@@@@@@@@@@@.@.......@@@@.@@@@@..@@@.@.@@@.@@@@@@@@@.@@@.@@....@....@.@@@@@@@.@@@.@@@@@@@@..@
.@..@@@@.@@.@@.@......@..@.@.@@@..@@@@.@@@@@@@...@@@.@@@@@.@@.@@.@@@@@@.@.@@...@@@...@.@..@@.@@..@@@@@...@@.@@@.@@..@@@@@.@@@@@.@@.@...@@.@.
@@@@@.@@@@@@.@@@@@@...@@@@@@@.@@.@@.@@@@.@...@@@@@..@@.@.@@.....@....@.@.@.@.@..@@.@@.@@@@...@@@@.@.@@@@@@...@@@.@@@@@@@.@..@..@@@@@@.@..@.@
@@.@@.@@@.@@@@.@@@@.@@@.@.@@@...@@@@@@.@.@.@@@@@.@.@@@@.@@..@.@..@@@@.@@..@.@@@.@@@.@.@@@..@.@.@@.@.@@@@@@..@..@@..@@@..@.@@@@@..@@.@@@@@..@
.@@.@@@.@@.@.@@@@.@@.@...@@@@.@..@@@..@.@..@..@@.@...@.@@.@@..@..@@.@..@@@@@.@@@@.@@@.@.@@@@...@.@@@....@..@@@@.@@@@@@.@.@..@@..@.@@@@...@@@
..@@.@@.@.@@...@...@..@.@.@@.@..@..@@@@.@...@.@@@@@@@.@@@@.@...@.@..@@@@@.@.@@@@.@.@@.@.@@..@.@@@...@.@@@@@.@..@@@@.@@@@@@@..@@@.@@.@.@..@@.
@@@@.@@@...@.@...@@@@@@@@@@.@@..@@.@.@.@@@@@@..@.@.@.@@.@.@@@@..@@.@@@.@.@@.....@@.@@@..@@.@.@.@.@.@.@@@..@@@@@@@.@@@@@.@@.@@@@..@@@@@@@@.@@
@...@@@...@@.@@@@..@..@.@@@@@@@.@.@@@@.@@@@@@..@@...@@@@@@@@.@@@@@.@@@@.@@.@@..@@@@.@@.@..@@...@@@.@.@@.@..@@@@@@@@@.@..@@.@@.@@..@@@.@.@@..
@..@@@@@.@..@@@@@@.@@.@..@@@@@.....@..@..@@.@@.@.@@.@@.@@@@@@@....@@..@@.@@..@@@@@@@@@@@@@.@.@@@@@@@.@@@.@@.@@@@@@@@@@@@@@@@@.@@@@@@@.@.@@@.
.@@@@@.@@.@@@@...@.@@.@..@@@@..@@@..@.@@@.@@@@@@@.@...@..@@@@..@...@@..@@.@..@@@@.@.@....@.@@@@@.@@@@@@@@@..@@.@@@@..@@.@..@@@.@..@@@@.@@.@@
.@@@...@..@@@@@@@@@@...@...@@@@..@@@.@@@@.@@.....@@@@.@...@...@@...@@@@@...@.@@.@.@.@@.@.@.@@.@@.@@@@@.@@@@@@..@@@@@.@.@@@...@.@.@@.@@@@.@@@
@.@..@@@.@.@..@.@..@@@@@@@@..@...@.@.@@@...@@@.@@@@..@@@.@@@@@@.@.@@@..@@@@@..@......@@.@.@.@@@@@@..@@@@.@@@..@@@.@@.@.@@@@.@@@@...@..@@@@@@
@@@@@@@.@.@.@@@@@@.@.@@..@@@@.@@@@@.@@@@@.@@.@@..@@@@@@.@.@..@@@.@.@.@@@@.@@@..@@@@.@@@@.@@..@.@@@@@..@@@@@@.@...@@@...@.....@@@..@@.@@.@.@.
@@...@.@..@@@.@@.@@@@@.@@@@@@@@@@.@@.@@@.@@.@@..@@@@...@.@.@@@.@..@.@.@@@@@...@@.@@.@.@.@@@@@@.@@@@@@@.....@@@@@.@@.@@.@@.@@@..@@@@.@@@.@@.@
.@@..@@.@@@@@.@@@..@@.@@..@@@@..@@@@@@@..@.@.@@@@..@.@@@.@.@.@..@..@@.@.@@.@.@@@@@..@@@..@@.@.@@.@@.@@..@@.@@@@@@..@@.@.@.@@@.@.@@@@@@.@..@@
@.@@.@@.@@.@@..@.@@.@@.@.@@@.@@@.@.@...@..@.@.@.@..@....@@@.@..@@@@@@@.@@..@@@@@.@..@@@.@..@.@@@@@@@@@.@@@@@@@@@@..@@@@@.@....@@@.@.@.@.@@@@
@@.@......@@@.@@.@..@...@@@@@@@@@@@@@...@@.@@.@@@@@@.@.@@@@@.@.@@@@.@.@@.@@@@.@@@.@..@@..@....@.@.@@@@@.@..@@@@.@@@@.@..@@@@@..@..@.@..@.@.@
@@@@@@@..@.@@@@@@@.@@@@@.@@@..@.@.@@.@.@@@..@@@@@.@@@....@@@@..@.@@...@@.@@@.@@@@.@@.@@@....@@@.@@@@@....@@@@@@...@@@@@@@@@@@..@@.@@@.@@@@@@
.@@@...@@.@@..@@@.@@..@@@..@..@.@@@@..@.@..@.@@@.@@@.@...@@@@@@@@.@@@.@.@.@..@.@@...@.@@@@@@@@@.@@@@@..@.@.@@.@@..@@.@....@@.@@@@@@..@@@@@.@

102
src/day4/main.rs Normal file
View File

@@ -0,0 +1,102 @@
use anyhow::Result;
use std::fs;
#[derive(PartialEq, Clone, Copy, Debug)]
enum Position {
Roll,
Empty,
CanMove,
}
fn step(pos: Vec<Vec<Position>>) -> (u64, Vec<Vec<Position>>) {
let y_max = pos.len() as i64;
let x_max = pos[0].len() as i64;
let mut new_pos: Vec<Vec<Position>> = pos.iter().cloned().collect();
let new_sum = pos.iter().enumerate().fold(0, |movable, (y, line)| {
let y = y as i64;
movable
+ line.iter().enumerate().fold(0, |sum, (x, _pos)| {
if pos[y as usize][x as usize] != Position::Roll {
sum
} else {
let x = x as i64;
let mut count = -1;
for i in -1..2 {
if y + i >= 0 && y + i < y_max {
for j in -1..2 {
if x + j >= 0 && x + j < x_max {
if pos[(y + i) as usize][(x + j) as usize] == Position::Roll {
count += 1;
}
}
}
}
}
if count < 4 {
new_pos[y as usize][x as usize] = Position::CanMove;
}
sum + (count < 4) as u64
}
})
});
(new_sum, new_pos)
}
fn sol(text: &String, stop_after: Option<usize>) -> u64 {
let mut pos: Vec<Vec<Position>> =
text.split("\n")
.filter(|s| s.len() > 0)
.fold(Vec::new(), |mut sum, sline| {
sum.push(
sline
.chars()
.map(|a| {
if a == '@' {
Position::Roll
} else {
Position::Empty
}
})
.collect(),
);
sum
});
let mut count = 0;
let mut step_num = 0;
loop {
if let Some(stop_after) = stop_after
&& stop_after == step_num
{
break;
}
let (c, new_pos) = step(pos);
if c == 0 {
break;
}
count += c;
pos = new_pos
.iter()
.map(|line| {
line.iter()
.map(|item| {
if *item == Position::CanMove {
Position::Empty
} else {
*item
}
})
.collect()
})
.collect();
step_num += 1;
}
count
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day4/act.txt")?;
println!("sol1: {}; sol2: {}", sol(&text, Some(1)), sol(&text, None));
Ok(())
}

10
src/day4/test.txt Normal file
View File

@@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.

1187
src/day5/act.txt Normal file

File diff suppressed because it is too large Load Diff

112
src/day5/main.rs Normal file
View File

@@ -0,0 +1,112 @@
use anyhow::Result;
use std::{fs, ops::RangeInclusive};
trait Extend<T> {
fn extend(&self, other: &T) -> Option<T>;
}
impl Extend<RangeInclusive<u64>> for RangeInclusive<u64> {
fn extend(&self, other: &RangeInclusive<u64>) -> Option<RangeInclusive<u64>> {
if other.contains(self.start()) && other.contains(self.end()) {
return Some(other.clone());
} else if self.contains(other.start()) && self.contains(other.end()) {
return Some((*self).clone());
} else if self.contains(other.start()) {
return Some(*self.start()..=*other.end());
} else if self.contains(other.end()) {
return Some(*other.start()..=*self.end());
}
return None;
}
}
struct ReduceUtilFold<Return, Over: Iterator, P>
where
P: FnMut(Over::Item, Option<Over::Item>) -> (Option<Over::Item>, Option<Return>),
{
over: Over,
cur: Option<Over::Item>,
perdicate: P,
}
impl<Return, Over: Iterator, P> ReduceUtilFold<Return, Over, P>
where
P: FnMut(Over::Item, Option<Over::Item>) -> (Option<Over::Item>, Option<Return>),
{
fn new(over: Over, perdicate: P) -> ReduceUtilFold<Return, Over, P> {
ReduceUtilFold {
over,
perdicate,
cur: None,
}
}
}
impl<
Return,
Over: Iterator,
P: FnMut(Over::Item, Option<Over::Item>) -> (Option<Over::Item>, Option<Return>),
> Iterator for ReduceUtilFold<Return, Over, P>
{
type Item = Return;
fn next(&mut self) -> Option<Return> {
let mut first: Option<Over::Item> = None;
std::mem::swap(&mut first, &mut self.cur);
let mut first = first.or_else(|| self.over.next())?;
loop {
let (cont, ret) = (self.perdicate)(first, self.over.next());
if ret.is_some() {
self.cur = cont;
return ret;
}
first = cont?;
}
}
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day5/act.txt")?;
let mut valid_ids: Vec<RangeInclusive<u64>> = text
.split("\n")
.take_while(|s| s.len() > 0)
.map(|s| {
let mut v = s.split('-').map(|a| a.parse().unwrap());
let start: u64 = v.next().unwrap();
let end: u64 = v.next().unwrap();
return start..=end;
})
.collect();
valid_ids.sort_by(|a, b| a.start().cmp(b.start()));
let valid_ids: Vec<RangeInclusive<u64>> = ReduceUtilFold::new(valid_ids.into_iter(), |a, b| {
if let Some(b) = b {
if let Some(extended) = a.extend(&b) {
(Some(extended), None)
} else {
(Some(b), Some(a))
}
} else {
(None, Some(a))
}
})
.collect();
let fresh_ids = text
.split("\n")
.skip_while(|s| s.len() > 0)
.skip(1)
.filter(|s| s.len() > 0)
.fold(0, |sum, line| {
let i: u64 = line.parse().unwrap();
sum + valid_ids.iter().any(|range| range.contains(&i)) as i64
});
let num_valid_ids = valid_ids.iter().fold(0, |sum, range_id| {
sum + range_id.end() - range_id.start() + 1
});
println!("sol1: {}! sol2: {}", fresh_ids, num_valid_ids);
Ok(())
}

11
src/day5/test.txt Normal file
View File

@@ -0,0 +1,11 @@
3-5
10-14
16-20
12-18
1
5
8
11
17
32

5
src/day6/act.txt Normal file
View File

@@ -0,0 +1,5 @@
836 7512 183 33 113 1 47 655 3 7 43 57 46 1 75 74 96 8 37 785 785 92 425 95 1144 977 7 57 619 53 13 8925 9 755 32 13 34 792 395 39 2 4 873 66 31 24 438 9274 79 6 675 76 14 156 45 78 631 35 844 76 32 636 9 56 1 83 44 165 22 217 643 3 748 676 2 648 57 53 95 6 3 42 765 17 51 6392 6 24 98 477 847 86 67 783 63 3 2 16 4 15 26 92 6 3139 534 855 21 539 6 3 369 538 24 19 57 812 635 37 53 487 151 658 76 91 73 26 749 438 866 785 3 45 1527 21 58 76 148 11 3 83 6 86 73 83 64 444 419 1 616 51 7 81 183 1 14 2 4 1 39 33 23 7 58 7232 28 91 198 299 17 814 898 49 738 64 528 63 96 211 39 4 2 37 9 82 2646 283 541 981 4336 41 285 11 28 89 841 961 31 8 78 61 374 59 71 157 574 8 1 795 326 226 415 59 552 84 71 8712 667 81 38 116 8749 518 743 628 48 8 39 696 345 31 49 87 71 94 8352 79 834 418 57 36 54 3 41 738 85 2763 8231 4824 298 1 68 7188 86 2417 582 858 6376 393 91 274 9 33 8652 19 11 88 1 59 469 415 87 594 25 44 85 324 2 373 55 139 36 172 7 64 25 8727 7 91 884 44 13 1682 1133 86 13 3957 442 4551 3 795 46 664 129 5 86 858 675 76 9 6 5 652 3 7676 63 851 2417 3 54 6 22 945 7 9218 76 981 5 239 133 3329 33 128 2 9828 76 78 24 968 33 6 26 673 2521 95 2 43 572 429 3391 891 81 95 379 2 834 7 52 82 16 96 99 42 4364 99 6 22 6 744 9 34 4 291 3721 79 5 76 64 112 88 923 18 8 798 653 482 6164 2 364 4 15 4 73 289 4313 88 77 8 9 78 33 81 3191 75 317 89 8 543 3 613 77 85 883 432 842 3 69 84 9 31 747 96 488 29 537 6 9 249 74 35 6312 8547 52 9 765 36 34 788 76 74 29 38 596 732 86 6 73 32 53 92 9 95 17 64 378 3918 74 96 15 318 2 63 382 597 45 353 16 37 69 255 51 83 24 685 4454 51 23 38 2 2 3 813 98 155 97 139 5765 4 388 1 7 5953 492 68 417 7622 92 658 963 3 43 161 455 243 587 438 46 475 3 25 578 3163 95 4847 347 71 11 1 2 259 65 39 45 8 76 586 116 3 3 618 5 65 62 22 262 511 716 86 46 2933 253 2 17 76 46 23 76 648 386 875 115 43 525 9 4 563 2655 79 123 728 48 969 586 37 3 26 7 423 17 232 19 22 8 6 63 35 4 9451 231 2 8 134 417 168 755 922 97 44 36 1 133 47 9 51 9 7 784 21 65 34 4823 912 9 135 12 28 6 88 95 493 37 67 518 388 9 4 987 56 57 47 218 721 12 322 2 14 22 6 13 53 9323 11 54 1158 32 61 436 62 7 5 3511 1 511 316 9 32 29 42 79 749 64 69 82 18 62 47 99 9 61 2 26 5427 553 145 82 874 11 554 24 39 759 97 32 74 742 869 6 2 957 831 36 33 18 4 1 265 94 1 241 76 6 21 524 4 26 13 47 23 97 63 3 33 25 473 272 3 66 87 1385 32 3 59 719 898 62 44 1457 86 12 8 968 19 745 95 3 83 71 55 4573 8 73 2 527 29 673 97 66 31 68 74 31 29 271 154 7 4 51 83 77 44 6334 429 4 486 39 3 58 4 81 888 1 48 66 1 149 3 5174 14 35 791 8668 76 6 2 664 291 94 9 8485 59 866 71 116 6256 1 871 6345 251 92 29 21 7 925 5 938 1962 774 94 3 65 615 4 14 111 7374 95 45 764 13 96 15 83 18 576 21 1 66 13 65 46 7 46 352 58 85 72 378 3779 7898 85 96 15 49 21 251 44 38 61 98 97 13 5596 3415 86 959 53 615 14 1 557 16 424 312 4 2 13 749 51 62 472 438 6381 252 89 3 815 3685 82 692 44 6 23 82 62 68 1 968 57 53 57 2 99 62 41 87 77 37 2 174 753 36 815 65 4 71 94 843 124 977 7892 13 4 6 38 1699 477 952 156 3655 915 377 61 97 75 221 635 914 62 83 23 75 25 26 13 37 296 7424 6 97 956 13 4 131 517 16 5 95 97 3983 7 746 1 65 86 3234 782 9 14 93 186 341 12 856 87 74 5222 62 69 4459 568 2365 1278 63 79 97 38 675 8 5366 74 49 38 5 741 33 5 94 988 96 31 2319 7 4 92 68 18 7956 77 8112 462 9232 97 168 8 1183 4392 8593 736 383 3 43
183 685 317 99 739 68 58 669 2 5 49 27 18 6 18 39 67 7 38 187 2267 79 996 13 5948 317 23 15 344 681 45 8187 1 514 87 953 91 195 831 23 29 72 543 86 13 672 972 1527 49 5 242 22 86 649 22 929 346 73 122 41 81 28 14 93 881 23 826 28 58 3651 492 62 335 727 597 322 281 86 39 273 8 85 231 79 47 1339 1 72 86 691 132 15 39 514 28 2 68 9 76 59 31 51 22 4266 169 746 85 839 76 19 215 678 58 75 683 278 621 671 23 7463 818 645 72 17 87 74 349 123 596 137 8 96 1657 98 73 69 393 57 28 76 17 484 85 987 347 169 177 115 955 4 79 32 142 13 17 72 293 96 61 61 32 18 41 311 67 254 788 812 58 779 993 118 558 98 843 74 35 489 11 213 18 41 9 87 4476 725 161 869 144 46 999 79 879 581 284 447 32 27 44 34 6474 62 28 687 4851 9 13 385 681 875 188 4 571 636 67 1946 922 49 22 494 2295 312 2636 141 39 615 72 923 652 26 9 31 81 23 1169 12 593 945 37 71 972 455 12 914 69 1652 6556 1716 829 95 76 7486 54 4727 9269 275 952 933 36 764 429 51 7587 43 477 3 96 92 478 229 84 617 342 33 472 9571 238 689 1 215 75 217 92 95 426 3787 591 397 921 358 8139 4314 6311 84 17 2771 964 7434 782 444 64 878 394 95 6816 638 414 146 995 61 1 932 4 3599 18 154 6373 1 36 41 858 163 95 411 58 279 3 178 66 448 13 764 362 3724 75 42 32 274 569 87 13 384 4112 629 4 43 537 872 6177 852 39 38 353 9 49 29 87 94 333 36 34 21 5988 74 948 48 87 38 44 13 925 223 8825 25 218 12 66 846 76 8325 32 6 299 183 522 1484 9 464 1 82 57 52 4832 8124 87 65 65 26 94 71 95 2234 89 329 41 49 576 7 171 44 16 135 4181 114 54 79 22 881 265 222 959 473 58 38 27 32 495 76 712 1926 4596 34 75 199 75 35 535 95 94 37 55 832 551 12 575 4894 34 92 58 917 71 71 582 153 6284 43 22 77 875 76 3 513 423 14 759 54 288 33 969 49 14 14 473 446 44 6485 31 96 3 7 494 14 62 48 453 1335 62 199 3 1 9335 779 48 469 1848 38 864 736 29 53 136 514 311 421 547 21 987 77 61 264 7446 26 7384 145 777 36 4 93 936 17 39 97 15 84 571 439 18 27 544 5 83 23 89 196 692 517 259 34 3899 693 1 75 29 36 32 86 839 136 721 3961 47 413 27 53 47 5952 94 2956 882 12 149 893 3 497 15 71 452 565 895 69 64 23 98 37 257 77 686 867 79 7 887 574 271 276 331 96 97 461 31 197 65 3 35 43 354 176 34 41 69 4234 538 66 115 22 48 23 95 311 511 43 37 845 612 14 8 253 217 99 71 614 963 27 877 2 2388 37 86 35 55 5778 48 182 422 81 47 717 15 99 3 1316 975 8121 49 22 24 66 58 43 388 91 18 69 23 47 88 62 6 86 976 67 6993 439 824 612 138 81 973 16 73 833 95 73 57 253 975 65 2 292 18 573 114 82 4 828 577 31 78 777 93 19 6 974 313 74 63 93 16 915 24 279 21 54 446 583 94 16 89 9434 584 7 666 961 4929 45 89 7651 81 39 4 216 84 74 38 75 452 514 76 5696 54 52 45 284 88 1544 69 74 49 33 97 96 26 931 414 655 8 23 67 38 1 6374 688 5 162 78 18 11 37 916 552 44 949 86 75 431 6 7265 53 17 943 2494 38 22 7 865 5337 36 14 594 4 675 46 274 8826 91 425 4958 772 29 45 68 914 916 73 562 986 255 59 67 158 249 14 19 661 9238 26 81 561 68 141 48 31 683 197 35 49 832 61 298 387 55 63 781 67 72 14 4481 1922 1148 631 53 51 3 13 29 71 92 92 49 29 27 398 2592 9 725 81 993 34 757 64 17 289 212 488 1 434 948 741 71 144 892 1857 4551 18 219 183 1997 86 311 78 49 27 494 76 91 59 827 26 58 3 42 93 372 24 74 94 31 35 461 743 27 546 94 6 99 76 373 384 916 4343 4535 26 9 392 8234 681 1372 66 2985 636 249 78 116 79 495 57 45 58 93 42 14 53 166 18 89 367 9452 1 418 437 52 9 171 337 71 838 988 21 123 493 736 65 84 47 1996 598 94 477 56 538 283 68 7245 48 75 146 46 97 3749 613 5658 7934 8316 68 25 69 1564 9 964 99 45 73 2 312 95 43 46 914 25 89 6211 74 2 67 51 92 1695 39 1832 361 461 31 28 471 2523 2775 3347 312 734 979 57
26 319 36 341 266 33 9 889 66 3 72 58 22 37 62 69 53 86 19 388 9962 52 324 845 964 849 53 11 343 798 98 6315 16 43 8 847 43 915 79 7 67 39 593 79 63 761 37 6127 55 92 238 38 86 74 72 922 374 4 849 49 96 36 19 91 418 88 147 85 44 1848 491 137 73 492 165 73 166 76 19 169 22 44 25 64 27 3557 3 63 42 555 735 91 8 317 28 77 94 1 85 72 12 65 533 694 553 214 36 918 972 19 191 269 136 21 673 468 687 418 85 1792 73 753 88 666 47 86 694 129 11 133 3 71 1151 816 14 61 37 665 23 278 92 367 96 881 465 613 938 3149 854 2 76 32 422 46 27 78 263 859 32 75 79 56 34 68 23 266 16 473 33 62 8 648 973 72 499 19 71 514 97 686 86 25 68 65 5554 578 24 237 232 22 55 7 683 197 629 797 37 1681 52 99 7263 44 86 941 1431 38 52 858 631 249 47 9 319 388 2 628 574 44 98 316 3499 739 1941 617 1 921 19 761 69 7 9 62 3 96 7448 19 916 757 7 92 359 538 48 643 6 621 936 3819 873 62 41 9891 43 1454 2256 356 377 675 51 2965 989 14 4876 74 316 5 84 71 29 784 48 787 795 27 346 1568 856 164 8 354 32 745 482 48 2185 3681 649 7972 731 362 2339 1265 6525 97 54 751 789 9779 9526 529 68 524 816 572 4788 969 18 616 745 31 9 336 15 7697 3186 3939 577 9 39 58 5388 825 994 61 12 174 26 471 89 316 54 11 837 4336 92 12 32 79 925 93 82 758 879 386 5 13 5578 337 153 32 51 95 64 1 5 196 44 57 4695 38 6 25 8931 485 628 17 17 33 79 7849 235 115 5451 19 861 683 89 197 24 4393 44 63 73 633 72 8714 4 918 95 76 14 55 8421 2487 9 31 78 785 96 3 95 1869 29 95 17 69 253 24 631 53 28 286 4366 446 63 51 5 6297 144 426 385 948 81 96 419 34 631 35 338 2859 534 66 939 447 781 56 618 11 9 78 9 955 748 39 599 3992 8 33 9 196 79 6 988 457 13 98 37 17 93 829 6 558 366 66 642 81 683 6 793 93 75 51 357 42 84 5834 1 12 89 115 3 5 74 51 68 2346 273 426 72 65 649 85 69 243 569 39 231 156 67 84 383 878 58 825 523 12 762 97 71 84 197 69 8282 998 784 26 72 47 51 8 62 25 26 43 677 254 31 5526 2117 1 585 95 595 385 776 713 693 3 2577 586 6 62 52 8 5 96 911 58 152 1115 76 198 12 9693 43 1288 13 5891 428 82 92 763 1 188 65 56 849 669 72 95 972 65 729 78 942 195 78 29 46 51 81 394 488 327 267 66 1 1996 24 84 53 28 6132 17 2858 891 22 18 35 3737 99 314 183 53 34 45 62 382 388 94 89 661 661 27 5 53 165 29 46 9653 551 9781 981 26 1886 99 47 34 92 3171 88 267 896 95 64 717 58 76 5 7563 178 7152 6 68 59 737 8 39 523 41 27 7357 49 96 93 84 11 88 614 15 4289 278 38 767 483 4 847 61 57 51 651 76 41 719 177 563 55 5 72 2542 9841 84 91 592 264 33 48 916 22 98 6 75 779 41 64 414 74 655 69 253 27 51 768 42 541 56 81 257 375 61 3417 827 7471 96 666 2144 17 34 91 385 69 25 66 83 222 118 95 727 31 3 62 23 65 1183 43 15 35 8 16 331 29 44 6857 415 53 5 82 586 7 314 22 7 23 83 22 98 496 678 35 994 767 8212 399 67 82 41 53 44 749 8198 7 19 451 915 3583 43 99 64 6 99 89 244 8468 996 535 5435 43 88 16 8 575 53 955 325 412 728 15 798 675 834 59 83 931 517 59 99 268 59 713 81 47 7117 399 45 144 737 37 614 362 75 6 493 81 94 34 2588 3353 7814 762 8 93 5 49 28 47 83 87 92 789 21 666 1157 7 748 27 377 1 254 61 226 146 189 124 86 9954 8 185 3 746 6929 3178 5778 92 336 423 834 39 712 238 29 213 5463 56 38 763 846 18 24 8 33 12 726 79 56 78 18 42 79 343 8 183 63 71 98 287 729 229 297 686 6936 18 1 559 1446 193 2491 7 9821 598 964 93 844 51 38 4 62 2 313 513 9 29 141 569 45 998 5577 65 8212 492 17 29 121 381 5 781 275 13 792 931 49 2472 68 85 198 557 83 292 81 583 718 66 4462 14 41 684 3 41 8737 717 5369 384 9643 13 54 453 3418 93 25 98 38 44 58 347 96 58 4 39 8 17 8727 928 51 35 54 42 65 69 466 96 46 3 32 237 6928 1214 382 55 682 813 49
22 51 63 985 428 94 9 49 82 82 52 37 4 59 7 8 36 72 62 2 5356 4 998 656 1 41 25 1 75 857 9 37 26 17 1 7277 75 677 9 6 81 58 23 85 9 473 2 7596 37 47 411 8 88 37 46 991 56 7 449 4 6 6 69 48 329 26 874 66 15 5378 968 819 59 669 146 3 168 44 24 119 14 8 88 65 2 713 89 45 5 918 3 56 8 19 21 53 64 2 19 539 93 748 285 88 714 926 584 311 691 96 47 98 792 52 383 732 991 777 39 5773 35 83 58 144 85 86 767 422 4 71 31 59 86 187 9 13 7 467 55 744 95 747 91 696 262 79 44 7485 58 3 17 62 59 97 89 61 391 627 2 14 47 37 37 6 16 767 18 573 28 32 7 423 999 25 76 68 896 749 73 148 98 243 47 88 574 318 99 925 671 5 26 1 871 581 596 32 52 5522 45 589 9389 4 13 578 9328 85 36 528 97 67 4 3 526 215 6 14 85 7 67 656 682 345 9789 242 6 7512 42 85 9 6 5 4 2 7 3759 83 971 124 5 98 9986 2573 8 2178 6 185 7 5119 71 76 33 4 53 977 9812 456 25 968 64 6422 496 84 724 44 685 5 914 55 8 189 6 693 975 38 666 6826 641 596 1 999 74 96 839 73 3112 243 416 2589 51 864 8529 8982 18 3 21 44 2 645 7982 31 2 716 278 226 4942 7 8 465 914 72 77 463 778 853 5846 7923 93 98 6 97 3661 429 532 4 44 928 858 82 44 628 1 92 621 33 7 8 86 34 848 52 63 542 3 572 58 29 3432 781 59 2 85 97 9 863 4 312 99 4 2712 15 3 39 2162 598 866 9 165 85 69 6378 672 912 737 8 548 463 3 2 76 3261 95 81 9 6 92 3 42 68 83 26 31 17 2521 182 9 6 56 531 48 1 36 952 36 46 24 96 23 41 32 78 792 518 3685 97 83 1 9 7248 643 77 158 839 99 68 937 43 958 361 559 283 654 56 833 919 489 59 1 7 7 9 5 886 783 47 239 3332 7 52 1 958 38 1 495 4 73 43 88 74 16 283 5 2 62 141 44 13 411 6 717 2 99 72 6 74 1 2545 1 74 39 657 5 4 73 99 2 8262 583 527 47 87 93 3 27 2 347 66 9 67 93 11 9 6 37 438 7 51 8 32 17 64 12 56 75 8 756 55 63 37 61 4 29 65 14 56 931 247 25 7138 3388 64 161 67 255 16 1 74 185 9 9264 67 72 6 99 9 7 4 16 64 39 4372 74 433 46 1493 48 2333 72 2993 886 2 2 695 5 7378 652 34 2 442 62 42 372 87 364 57 788 813 7 4 77 87 7 1 747 42 882 72 7 9912 97 34 786 596 1723 79 4429 856 16 68 7 1171 17 849 49 99 38 61 6 392 7 6 41 932 217 93 61 49 987 15 47 3525 895 9155 76 54 8711 59 83 1 354 24 86 525 71 4 55 23 3 53 18 423 434 8391 7 77 39 976 6 51 168 53 9 7741 11 98 2 27 75 63 435 61 5555 918 3 724 38 3 824 42 78 4 297 97 78 52 9 551 51 3 5 6826 4369 61 55 132 59 43 46 463 45 68 9 45 455 98 9 981 16 261 64 226 45 6 636 24 681 94 96 76 389 55 6242 634 3747 94 671 8674 48 4 12 328 9 2 73 34 378 287 387 941 73 3 721 8 6 2591 36 71 84 6 75 666 2 3 3354 972 39 6 14 875 4 898 7 29 46 4 61 24 663 641 1 319 931 3263 256 73 67 51 4 75 137 827 4 78 924 132 4243 11 52 47 9 4 9 677 9 375 619 69 58 13 7 8 259 9 463 46 92 993 52 151 445 13 92 49 64 796 11 23 467 4 4179 1 13 8995 14 67 363 363 6 739 269 83 5 134 6 7 16 2976 84 1237 842 6 14 8 3 9 53 72 31 89 874 9 99 9886 2 78 9 961 3 615 6 246 471 771 643 98 7632 4 122 2 59 8914 3483 2292 15 914 15 54 63 2 413 13 639 6615 35 76 472 452 59 8 2 16 7 432 7 35 986 24 92 34 19 6 77 22 93 1 468 648 222 857 93 7966 65 27 531 68 335 7699 6 7651 4 865 24 415 5 52 5 11 5 8234 426 9 2 538 5342 48 81 872 297 3997 827 483 74 523 92 5 2763 618 15 48 159 17 9766 27 3 83 5 97 257 4 684 34 5 5677 76 59 477 8 55 4 752 36 12 1767 812 89 729 3416 73 97 35 91 57 99 44 87 72 6 58 8 95 68 191 74 66 96 2 1 6 69 59 4 7 2 383 457 5225 519 22 74 849 51
+ + + * * + + * * + * + * * + + + * * * + * * * + + * + * * + + + + + + * * + + * * + * * * * + * * * + * * * * * + + + + * + + * + * * * + + * * * + * + + * + * + * + + + * * + + * * + + + + + * + * * * + + * * * + * + + + + + * + * * + + * + * + + + + + * * * * + + + * * + * + * + + * + * * + * + + * + + + * * + + * * * * + * + * * + * * * * + * * + + * + + * * * + * + + + * * * * * * * * + + * + * + * + + * * + + * * * + + + * * + * + * + + + + + * + + + * * * + + * + + * + + * + + + + + + * + + * + + + + + * + * * + * + + + * + + * + * * + + + * * + + * + + + + * + + * + + + * * + * + + + + * * + + + * * * + + + * + + + + + + + + + + + * * + * * + * + * + * * * * * * * + + * + + + + + + * + + * * * + * + + + * + * * + + + + + + + + + + * * * * + + + + + + + + * + * * * + + + + * + * + * + * * * + + * + * + * + + + * + + + + * * + + + + + * * + + * * + * * * * + + * + * * * + * * * * + + * + + + + * * + * + + * + + + * * * * * * + + + + * + * + * + * + + * + * + + * * * + * * + * * * * + + + * * + * * + * + + + + * + * * * + * * * + + + + + * + * + + * + + + * * + + * * * * * + + * * * + * + * + * + + * + + * + + + + * * * + + + + + * * + * * + + * + * + + * * + + * + * * + * + * * * * * * * + * + * * * * * + * + * + + + + * + + * * * + * * + + + * * + + + + + * * + * * * * * * + + * * + + + + * + + * + * * * * + * * + * * + + * * + + + * + + * * * + + + + * * * * + * * + * + * * + * * * + * * + + + + * + + * + * * * * * * * * + * + + + + + + * * * * + * * + * * + + * * + * + * * * * + * * + + + + + * + * + * + * * * * + * + + + * + * + * * + + * * + + + * * + * * * * + * + + + * + * * + * + + * + * + * * * * * + * * * + + + * * + * + + * + * + * * + + + * * + + * * + * + + * + * + * * + + + * * + + + + + + * + + * * + * * + + + + + * * * * * + * * * * * + + + + + + * * * + + + + + + + * * * * + + + + * * * + + + * + + + + + * * * * + + * + * + + * * + * * + * * * * + * * + * * + * + + + + + + + * + * + + + * * + + + * * + * * * * + + * + * + * * * + + + + * + *

128
src/day6/main.rs Normal file
View File

@@ -0,0 +1,128 @@
use anyhow::Result;
use std::fs;
enum Op {
Sum = '+' as isize,
Mult = '*' as isize,
}
impl Into<Op> for char {
fn into(self) -> Op {
match self {
'*' => Op::Mult,
'+' => Op::Sum,
_ => panic!("invalid char"),
}
}
}
struct Ans {
sum: u64,
mult: u64,
op: Option<Op>,
}
impl Ans {
fn new(mult: u64, sum: u64) -> Ans {
Ans {
op: None,
mult,
sum,
}
}
fn extend(&mut self, num: u64) {
self.mult *= num;
self.sum += num;
}
fn res(&self) -> u64 {
match self.op {
Some(Op::Sum) => self.sum,
Some(Op::Mult) => self.mult,
_ => panic!("you are doing something wrong"),
}
}
}
fn sol2(text: &str) -> Result<()> {
let lines = text.split("\n").collect::<Vec<&str>>();
// There is an empty line at the end
let lines_len = lines.len() - 1;
let mut grand_total = 0;
let mut cur_ans = Ans::new(1, 0);
let mut x: i64 = lines[0].len() as i64 + 1;
while x >= 0 {
// Note if we have found a no space char
let mut cur_num = 0;
let mut has_found = false;
let mut has_commited = false;
for y in 0..lines_len {
let c = lines[y].chars().nth(x as usize).unwrap_or(' ');
match c {
' ' => {
if has_found && !has_commited {
// We have reached the end of the colum
has_commited = true;
cur_ans.extend(cur_num);
}
}
'*' | '+' => {
assert!(has_found);
if !has_commited {
cur_ans.extend(cur_num);
}
cur_ans.op = Some(c.into());
grand_total += cur_ans.res();
cur_ans = Ans::new(1, 0);
x -= 1;
}
c => {
// convert ascci to int
let num: u64 = (c as u64) - 48;
cur_num = cur_num * 10 + num;
has_found = true;
}
}
}
x -= 1;
}
println!("sol2: {}", grand_total);
Ok(())
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day6/act.txt")?;
let problems = text
.split("\n")
.filter(|s| s.len() > 0)
.fold(Vec::new(), |probs, line| {
line.split(" ")
.filter(|s| s.len() > 0)
.enumerate()
.fold(probs, |mut probs, (i, op)| {
if probs.len() <= i {
let as_num: u64 = op.parse().unwrap();
probs.push(Ans::new(as_num, as_num));
} else {
match op {
"+" | "*" => probs[i].op = Some(op.chars().nth(0).unwrap().into()),
_ => probs[i].extend(op.parse().unwrap()),
}
}
probs
})
});
let sol1 = problems.iter().fold(0, |s, i| s + i.res());
println!("sol1: {}!", sol1);
sol2(&text)?;
Ok(())
}

4
src/day6/test.txt Normal file
View File

@@ -0,0 +1,4 @@
123 328 51 64
45 64 387 23
6 98 215 314
* + * +

142
src/day7/act.txt Normal file
View File

@@ -0,0 +1,142 @@
......................................................................S......................................................................
.............................................................................................................................................
......................................................................^......................................................................
.............................................................................................................................................
.....................................................................^.^.....................................................................
.............................................................................................................................................
....................................................................^.^.^....................................................................
.............................................................................................................................................
...................................................................^.....^...................................................................
.............................................................................................................................................
..................................................................^.^.^.^.^..................................................................
.............................................................................................................................................
.................................................................^.^...^...^.................................................................
.............................................................................................................................................
................................................................^.^.^.^.^.^.^................................................................
.............................................................................................................................................
...............................................................^.^.^.....^.^.^...............................................................
.............................................................................................................................................
..............................................................^.^.^.^...^.^.^.^..............................................................
.............................................................................................................................................
.............................................................^.^.^.^.......^.^.^.............................................................
.............................................................................................................................................
............................................................^.^.^...^.^...^.^.^.^............................................................
.............................................................................................................................................
...........................................................^.^.^...^.^...^.^.^.^.^...........................................................
.............................................................................................................................................
..........................................................^...^.....^.^.^.^.^.^...^..........................................................
.............................................................................................................................................
.........................................................^.^.......^.^...^.^.^...^.^.........................................................
.............................................................................................................................................
........................................................^.^.^.^.^...^.....^.^.....^.^........................................................
.............................................................................................................................................
.......................................................^.^.^.^.^.^...^.^.....^.^...^.^.......................................................
.............................................................................................................................................
......................................................^.^.^...^...^...^...^.^.^.^.^.^.^......................................................
.............................................................................................................................................
.....................................................^.^...^...^...^.^.^.^.^.^...^.^...^.....................................................
.............................................................................................................................................
....................................................^.^.^.....^.^.........^...^.^.^.....^....................................................
.............................................................................................................................................
...................................................^...^.^.^.....^.^.^...^...^.....^.^.^.^...................................................
.............................................................................................................................................
..................................................^.^.^.^.^.^.^...^.^.^...^...^.......^...^..................................................
.............................................................................................................................................
.................................................^...^.....^.^.^.^.....^.^...^.....^.^.^...^.................................................
.............................................................................................................................................
................................................^...^.....^.^.^.^.^.^.^.^.^.^.............^.^................................................
.............................................................................................................................................
...............................................^.^.^.....^.^.....^.^.^.^.^.....^.....^...^.^.^...............................................
.............................................................................................................................................
..............................................^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.^...^..............................................
.............................................................................................................................................
.............................................^.^.^...^.^.^...^...^.^.^.....^...^.....^.^.^...^.^.............................................
.............................................................................................................................................
............................................^.^.......^.^.^.^.....^.......^.^.^...^.^.........^.^............................................
.............................................................................................................................................
...........................................^...^...^...^...^.^.........^.^...^.^.....^.....^.^.^.^...........................................
.............................................................................................................................................
..........................................^...^.^...^.^.^.^.^...^.^.^.^.^.^.....^...^...^.^.^.^.^.^..........................................
.............................................................................................................................................
.........................................^.^...^.^...^.^.....^.^.......^.^.....^.^.^.^.^.^...^.^.^.^.........................................
.............................................................................................................................................
........................................^.^...^.^...^.^.......^.......^.^.^.^.^.^.^.......^.^.^...^.^........................................
.............................................................................................................................................
.......................................^.^.^...^.^...^.^...^.^...^.....^.^.^...^.......^...^.^.^.^.^.^.......................................
.............................................................................................................................................
......................................^.....^.^.....^.....^...^...^.^.^...^.^.^.^.....^.^.^...^.^.^...^......................................
.............................................................................................................................................
.....................................^.^.....^.^.^...^.....^.^.^.^...^.^.......^.^...^.^.^...^.^.^.^.^.^.....................................
.............................................................................................................................................
....................................^.^.^.^...^.......^.^...^...^.....^...^...^.^...^.^.^.......^.^.^...^....................................
.............................................................................................................................................
...................................^.^.....^.....^.^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^...^.^.^...^.....^...................................
.............................................................................................................................................
..................................^...^...^.^.^...^.^.^.....^.^.^.....^.^.^.^.^.^.^.^.......^.^...^.^.^.^.^..................................
.............................................................................................................................................
.................................^.^...^.^.^.^.^...^.^...^.^.^.^.......^.^.^.^.^...^...^.^.^.^.^.^.^.......^.................................
.............................................................................................................................................
................................^...^.^.^...^.^.^.^.^...^.^.^...^...^.^...^.^.......^.^.^.^.^.....^.^.^.^.^.^................................
.............................................................................................................................................
...............................^.^.^.^.^...^.^.^.....^.^...^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^...............................
.............................................................................................................................................
..............................^.^.^.....^...^.^.^.^...^...^.^.^.^.^.^.^...^.^.^.......^...^.^.^.^.^.^...^.^.^.^..............................
.............................................................................................................................................
.............................^.....^.^...^.^.^.^...^.^.^.^...^...^...^.^.^.^.....^.^.......^...^.^...^.^.^.^...^.............................
.............................................................................................................................................
............................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.......^.^.^...^.^...^.....^............................
.............................................................................................................................................
...........................^.^...^...^...^.^.^.^...^.....^...^.^.^.^.^.^.^...^.......^.^.^.^.^...^...^.......^.^.^...........................
.............................................................................................................................................
..........................^.....^...^.^.^.....^.^.^...^...^...^.....^...^...^.^.^.^.^.^.^.^.^.....^...^.^.^.......^..........................
.............................................................................................................................................
.........................^.^.^...^.^.....^.^...^.^.^...^.....^.^.^.^.....^...^...^.^.^...^.^...^.....^.^.^.^.....^.^.........................
.............................................................................................................................................
........................^...^.^.^.^.^.......^.^.^.......^.^.^...^.^.....^.^.^.^.^...^.^.^.......^.^.^.........^.^.^.^........................
.............................................................................................................................................
.......................^.^.^.^.^.....^.^...^.^.^...^.^.^.^...^.^...^...^...^.....^.^.^.^...^.^.^.^...^.......^.^.^.^.^.......................
.............................................................................................................................................
......................^.^.^.^.^.^.....^.^.......^.^.^...^.^.^.^.^.^...^.^.^.^...^.^...^...^.......^.^.^.^...^.^.^.^...^......................
.............................................................................................................................................
.....................^.^.^.^...^.^.^.^.^.^.^...^...^.^.^.....^.^.^...^.^.^.....^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^...^.....................
.............................................................................................................................................
....................^.^...^.^.^.^...^...^.........^.^...^...^...^...^.^...^.^.^...^...^...^...^.^.^.^.^.^.^...^.^.^.....^....................
.............................................................................................................................................
...................^.^.^...^...^...^.^.^...^.^.^...^.....^.^.^.^.....^.^...^...^.^...^...^.^.^.^.^.^...^.^.^.^...^.....^.^...................
.............................................................................................................................................
..................^.^.......^.^.^...^.^.^...^.^.....^.^.^.^.^.^.^.^.....^...^.^.^.........^.............^.......^...^.^.^.^..................
.............................................................................................................................................
.................^.^.........^...^.^.......^.^.^.^.^.^.^.^.^...^.....^.^.^.^.........^.^.^.^.^.....^...^...^.^.^.^.^...^...^.................
.............................................................................................................................................
................^.^.^...^.^.^.....^.^.^...^.^.^.^...^...^.^...^.^.^.^.^.^...^.^...^.^.^.....^...^.^...^...^.^...^.^.^.....^.^................
.............................................................................................................................................
...............^.^.^.^.^.^.^.^.....^...^.^.^.^.^...^.........^.^.^.^...^.^.^.....^...^...^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.^.^...............
.............................................................................................................................................
..............^.^.^...^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.^...^.^...^.....^.^...^.............^.^...^.^.^.^.^...^.^.^.^.....^.^.^..............
.............................................................................................................................................
.............^.^.^.^.....^...^...^.....^.^...^...^.......^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^...^...^.^.^.....^.............
.............................................................................................................................................
............^...^.^.^.^.^...^...^.^.^.....^.^.^.^...^.^...^...^...^...^.^.......^.^.^.....^...^...^.^.^.^.^.^.......^.^.^...^.^.^............
.............................................................................................................................................
...........^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.......^.^.^...^.^.^.^.^.^.^.^...^.^...^.........^.^.^.^.....^...^.^...^.^.^.^.....^.^...........
.............................................................................................................................................
..........^.....^.^.^.....^.....^.....^.^.^.^.^.^.^.^.^.....^.^.^.^.^...^.^.^...^.......^.^...^...^...^.....^...^.^.^.^.^.^.^.^.^.^..........
.............................................................................................................................................
.........^...^...^.^.^.....^.^.^.^.^.^...^...^...^...^.......^.^.^.^.^.^.^...^.^.^.^.^.^.........^...^.^.^...^.^.....^.^.^.^.^.....^.........
.............................................................................................................................................
........^.^.....^.^.^.^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.^...^...^...^.........^.^.^.^.^.....^.^.^...^.^.^.^.^...^...^.^.^...^........
.............................................................................................................................................
.......^.^.^.^.^.^.^.......^.^.........^.^.^.^.^.^.^.^.^.^.^...^...^.^...^...^...^...^...^.^.....^...^...^...^.^.^.....^...^...^.....^.......
.............................................................................................................................................
......^.^.^...^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^.....^.....^.....^.^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.^.......^.^.....^.^.^.^.....^.^.^......
.............................................................................................................................................
.....^...^.^.^.^.....^...^...^.....^.^.^.^.^.^.^.....^.^.^...^...^.^.^.^.^.^...^...^.^.^.^.....^.^.^.^...^.....^.^...^...^.^...^.^.^.^.^.....
.............................................................................................................................................
....^.^.^...^.^.^.^.^.^...^...^.^.^.^.^...^.^.^.^...^...^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.^.^...^.......^...^.....^....
.............................................................................................................................................
...^.^.^.....^.^.^.^.^.....^...^.....^...^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^...^.^.^.....^.....^...^.^.^.^.^...^.^...^...^.^...^.^.^.^.^...
.............................................................................................................................................
..^.^.......^.^.^.^...^...^.^.....^.^.^.^.^.^...^.^.....^...^.^.....^.^...^.^.^...^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^...^.^...^..
.............................................................................................................................................
.^.^...^.^.^...^...^...^.^.....^.^.....^.^.^.^...^.....^.^.^.^...^.^.^.^.^.^...^.^.^.....^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.....^.^.
.............................................................................................................................................

44
src/day7/main.rs Normal file
View File

@@ -0,0 +1,44 @@
use anyhow::Result;
use std::{collections::HashMap, fs};
fn main() -> Result<()> {
let text = fs::read_to_string("src/day7/act.txt")?;
let lines = text.split("\n").filter(|s| s.len() > 0).into_iter();
let mut beams = lines.clone().next().unwrap().chars().enumerate().fold(
HashMap::new(),
|mut map, (i, item)| {
if item == 'S' {
map.insert(i as i64, 1 as usize);
}
map
},
);
let mut lines = lines.skip(1);
let mut split_hit = 0;
while let Some(line) = lines.next() {
let spliters = line
.chars()
.enumerate()
.filter(|(_i, item)| *item == '^')
.map(|(i, _item)| i as i64);
for split in spliters {
if let Some(bs) = beams.get(&split) {
let bs = bs.clone();
beams.remove(&split);
split_hit += 1;
let new_p = split + 1;
beams.insert(new_p, *beams.get(&new_p).unwrap_or(&0) + bs);
let new_p = split - 1;
beams.insert(new_p, *beams.get(&new_p).unwrap_or(&0) + bs);
}
}
}
println!("Sol1: {}", split_hit);
println!("Sol2: {}", beams.values().fold(0, |s, v| s + *v));
Ok(())
}

16
src/day7/test.txt Normal file
View File

@@ -0,0 +1,16 @@
.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

1000
src/day8/act.txt Normal file

File diff suppressed because it is too large Load Diff

151
src/day8/main.rs Normal file
View File

@@ -0,0 +1,151 @@
use anyhow::Result;
use std::{
collections::{HashMap, HashSet},
fs,
};
#[derive(Debug, PartialEq, Eq, Hash)]
struct JunctionBox {
x: i64,
y: i64,
z: i64,
}
impl JunctionBox {
fn dist(&self, other: &JunctionBox) -> f64 {
(((self.x - other.x).pow(2) + (self.y - other.y).pow(2) + (self.z - other.z).pow(2)) as f64)
.sqrt()
}
}
impl Into<JunctionBox> for &str {
fn into(self) -> JunctionBox {
let mut niter = self.split(",");
let x: i64 = niter.next().unwrap().parse().unwrap();
let y: i64 = niter.next().unwrap().parse().unwrap();
let z: i64 = niter.next().unwrap().parse().unwrap();
JunctionBox { x, y, z }
}
}
struct Pair<'a> {
b1: &'a JunctionBox,
b2: &'a JunctionBox,
dist: f64,
}
impl<'a> Pair<'a> {
fn new(b1: &'a JunctionBox, b2: &'a JunctionBox) -> Pair<'a> {
Pair {
b1,
b2,
dist: b1.dist(b2),
}
}
}
struct Circuit<'a> {
set: HashSet<&'a JunctionBox>,
}
/**
*
* Note this is not a general solution if your anwerser for the first part is in the
* happends to be in a merge then this will probably give you the wrong result
*
*/
fn main() -> Result<()> {
let text = fs::read_to_string("src/day8/act.txt")?;
let boxes: Vec<JunctionBox> = text
.split("\n")
.filter(|s| s.len() > 0)
.map(|s| s.into())
.collect();
let mut pairs: Vec<Pair> = Vec::with_capacity(boxes.len() * boxes.len());
for (i, b1) in boxes.iter().enumerate() {
for b2 in boxes.iter().skip(i + 1) {
pairs.push(Pair::new(b1, b2))
}
}
pairs.sort_by(|a, b| a.dist.total_cmp(&b.dist));
let mut box_to_circuit: HashMap<&JunctionBox, usize> = HashMap::new();
let mut circuits: Vec<Option<Circuit>> = Vec::new();
let mut count = 0;
for pair in pairs.iter() {
let b1c = box_to_circuit.get(pair.b1);
let b2c = box_to_circuit.get(pair.b2);
if b1c.is_some() && b2c.is_some() {
let b1c = *b1c.unwrap();
let b1c_set = circuits[b1c].as_ref().unwrap();
if b1c_set.set.contains(pair.b2) {
count += 1;
continue;
}
let b2c = *b2c.unwrap();
let mut b2c_set: Option<Circuit> = None;
std::mem::swap(&mut circuits[b2c], &mut b2c_set);
let b2c_set = b2c_set.unwrap();
for item in b2c_set.set.iter() {
box_to_circuit.insert(item, b1c);
}
circuits[b1c].as_mut().unwrap().set.extend(&b2c_set.set);
if circuits[b1c].as_ref().unwrap().set.len() == boxes.len() {
println!("Sol2: {}", pair.b1.x * pair.b2.x);
return Ok(());
}
} else if b1c.is_some() {
let b1c = *b1c.unwrap();
circuits[b1c].as_mut().unwrap().set.insert(pair.b2);
box_to_circuit.insert(pair.b2, b1c);
if circuits[b1c].as_ref().unwrap().set.len() == boxes.len() {
println!("Sol2: {}", pair.b1.x * pair.b2.x);
return Ok(());
}
} else if b2c.is_some() {
let b2c = *b2c.unwrap();
circuits[b2c].as_mut().unwrap().set.insert(pair.b1);
box_to_circuit.insert(pair.b1, b2c);
if circuits[b2c].as_ref().unwrap().set.len() == boxes.len() {
println!("Sol2: {}", pair.b1.x * pair.b2.x);
return Ok(());
}
} else {
let mut set = HashSet::new();
set.insert(pair.b1);
set.insert(pair.b2);
circuits.push(Some(Circuit { set }));
box_to_circuit.insert(pair.b1, circuits.len() - 1);
box_to_circuit.insert(pair.b2, circuits.len() - 1);
}
if count == 1000 {
let mut circuits: Vec<&Circuit> = circuits
.iter()
.filter(|s| s.is_some())
.map(|a| a.as_ref().unwrap())
.collect();
circuits.sort_by(|a, b| a.set.len().cmp(&b.set.len()));
println!(
"Sol1: {}",
circuits
.iter()
.rev()
.take(3)
.fold(1, |m, i| m * i.set.len())
);
}
count += 1;
}
panic!("Sould not reach here");
}

20
src/day8/test.txt Normal file
View File

@@ -0,0 +1,20 @@
162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689

13
src/day9/act.html Normal file

File diff suppressed because one or more lines are too long

496
src/day9/act.txt Normal file
View File

@@ -0,0 +1,496 @@
98004,50283
98004,51502
98073,51502
98073,52727
98144,52727
98144,53937
97953,53937
97953,55168
98003,55168
98003,56406
98033,56406
98033,57473
96926,57473
96926,58748
97199,58748
97199,59926
96895,59926
96895,61220
97084,61220
97084,62314
96426,62314
96426,63395
95789,63395
95789,64490
95244,64490
95244,65829
95432,65829
95432,66934
94907,66934
94907,68050
94423,68050
94423,69341
94345,69341
94345,70156
93192,70156
93192,71485
93153,71485
93153,72568
92590,72568
92590,73702
92113,73702
92113,74741
91467,74741
91467,75567
90483,75567
90483,76688
89978,76688
89978,77537
89068,77537
89068,78372
88163,78372
88163,79469
87609,79469
87609,80612
87093,80612
87093,81578
86346,81578
86346,82422
85463,82422
85463,82939
84244,82939
84244,84206
83804,84206
83804,84848
82735,84848
82735,85434
81634,85434
81634,86745
81168,86745
81168,87730
80395,87730
80395,87950
79018,87950
79018,88564
77968,88564
77968,89681
77272,89681
77272,90032
76045,90032
76045,90883
75148,90883
75148,91125
73882,91125
73882,91934
72952,91934
72952,92557
71910,92557
71910,92993
70774,92993
70774,93784
69804,93784
69804,94065
68601,94065
68601,94737
67564,94737
67564,94644
66234,94644
66234,95260
65172,95260
65172,96308
64228,96308
64228,96569
63027,96569
63027,96815
61826,96815
61826,96343
60465,96343
60465,96835
59336,96835
59336,97723
58262,97723
58262,97006
56916,97006
56916,97227
55731,97227
55731,97435
54540,97435
54540,98266
53388,98266
53388,98391
52167,98391
52167,98195
50936,98195
50936,98172
49715,98172
49715,97959
48500,97959
48500,98135
47273,98135
47273,98219
46040,98219
46040,97295
44907,97295
44907,97942
43605,97942
43605,96967
42520,96967
42520,96937
41300,96937
41300,96652
40124,96652
40124,96994
38801,96994
38801,96419
37687,96419
37687,95965
36552,95965
36552,95897
35300,95897
35300,95312
34211,95312
34211,94929
33056,94929
33056,94007
32118,94007
32118,93804
30894,93804
30894,93729
29593,93729
29593,93046
28568,93046
28568,92453
27503,92453
27503,91601
26586,91601
26586,90840
25632,90840
25632,90635
24336,90635
24336,89546
23599,89546
23599,89479
22173,89479
22173,88691
21234,88691
21234,87455
20651,87455
20651,87191
19306,87191
19306,86273
18485,86273
18485,85089
17918,85089
17918,84736
16587,84736
16587,83568
16032,83568
16032,83102
14760,83102
14760,82116
14026,82116
14026,81313
13084,81313
13084,79817
12987,79817
12987,79115
11922,79115
11922,78148
11187,78148
11187,77151
10493,77151
10493,75950
10112,75950
10112,74905
9511,74905
9511,74201
8326,74201
8326,72904
8152,72904
8152,71838
7581,71838
7581,70676
7210,70676
7210,69798
6230,69798
6230,68607
5921,68607
5921,67692
4935,67692
4935,66370
4983,66370
4983,65240
4534,65240
4534,64208
3759,64208
3759,62870
3992,62870
3992,61715
3622,61715
3622,60663
2780,60663
2780,59343
3127,59343
3127,58209
2581,58209
2581,57040
2155,57040
2155,55761
2518,55761
2518,54592
2022,54592
2022,53344
2362,53344
2362,52146
2079,52146
2079,50925
2365,50925
2365,50265
94901,50265
94901,48488
1659,48488
1659,47308
2494,47308
2494,46043
1812,46043
1812,44875
2401,44875
2401,43591
1950,43591
1950,42377
2134,42377
2134,41191
2472,41191
2472,40153
3483,40153
3483,38963
3684,38963
3684,37617
3317,37617
3317,36454
3697,36454
3697,35377
4342,35377
4342,34263
4837,34263
4837,32955
4800,32955
4800,31869
5379,31869
5379,30923
6262,30923
6262,29782
6675,29782
6675,28650
7119,28650
7119,27415
7379,27415
7379,26415
8095,26415
8095,25406
8781,25406
8781,24145
9061,24145
9061,23300
10005,23300
10005,22154
10494,22154
10494,21597
11796,21597
11796,20131
11881,20131
11881,19735
13328,19735
13328,18722
13998,18722
13998,17795
14776,17795
14776,16811
15496,16811
15496,15841
16243,15841
16243,14681
16822,14681
16822,14162
18004,14162
18004,13340
18903,13340
18903,12715
19963,12715
19963,11815
20802,11815
20802,11108
21793,11108
21793,10828
23078,10828
23078,10062
24016,10062
24016,9070
24823,9070
24823,8392
25837,8392
25837,7547
26764,7547
26764,7731
28238,7731
28238,6379
28922,6379
28922,5921
30062,5921
30062,5661
31282,5661
31282,5137
32386,5137
32386,5118
33678,5118
33678,4277
34673,4277
34673,4403
35989,4403
35989,4090
37156,4090
37156,3656
38292,3656
38292,3559
39512,3559
39512,2594
40549,2594
40549,2472
41771,2472
41771,2323
42984,2323
42984,2689
44258,2689
44258,2443
45448,2443
45448,2139
46639,2139
46639,1555
47830,1555
47830,1845
49064,1845
49064,1634
50286,1634
50286,2188
51494,2188
51494,2386
52697,2386
52697,2595
53892,2595
53892,2621
55101,2621
55101,2661
56313,2661
56313,2728
57528,2728
57528,2364
58828,2364
58828,2818
59987,2818
59987,2845
61236,2845
61236,3836
62244,3836
62244,3791
63518,3791
63518,4250
64651,4250
64651,4284
65928,4284
65928,5346
66839,5346
66839,5849
67939,5849
67939,5650
69343,5650
69343,6127
70473,6127
70473,7026
71396,7026
71396,7311
72621,7311
72621,7898
73695,7898
73695,8360
74844,8360
74844,9323
75689,9323
75689,9834
76813,9834
76813,10909
77552,10909
77552,11764
78426,11764
78426,12198
79619,12198
79619,12720
80766,12720
80766,13911
81353,13911
81353,14300
82639,14300
82639,15444
83238,15444
83238,15925
84480,15925
84480,17167
84951,17167
84951,18280
85528,18280
85528,19271
86225,19271
86225,20163
87036,20163
87036,20724
88286,20724
88286,21775
88917,21775
88917,22924
89395,22924
89395,24077
89844,24077
89844,24888
90823,24888
90823,25962
91392,25962
91392,27042
91944,27042
91944,28174
92391,28174
92391,28956
93550,28956
93550,30107
93978,30107
93978,31501
93820,31501
93820,32387
94861,32387
94861,33531
95288,33531
95288,34727
95560,34727
95560,35758
96349,35758
96349,37174
95847,37174
95847,38217
96640,38217
96640,39523
96391,39523
96391,40646
96922,40646
96922,41796
97381,41796
97381,43019
97440,43019
97440,44222
97609,44222
97609,45404
98016,45404
98016,46605
98352,46605
98352,47838
98266,47838
98266,49062
98278,49062
98278,50283

193
src/day9/main.rs Normal file
View File

@@ -0,0 +1,193 @@
use anyhow::Result;
use std::{fs, ops::Range};
#[derive(Debug, PartialEq, Eq, Hash)]
struct TilePos {
x: i64,
y: i64,
}
impl TilePos {
fn area(&self, other: &TilePos) -> u64 {
(((self.x - other.x).abs() + 1) * ((self.y - other.y).abs() + 1)) as u64
}
}
impl Into<TilePos> for &str {
fn into(self) -> TilePos {
let mut niter = self.split(",");
let x: i64 = niter.next().unwrap().parse().unwrap();
let y: i64 = niter.next().unwrap().parse().unwrap();
TilePos { x, y }
}
}
#[derive(Debug)]
struct Pair<'a> {
b1: &'a TilePos,
b2: &'a TilePos,
area: u64,
}
impl<'a> Pair<'a> {
fn new(b1: &'a TilePos, b2: &'a TilePos) -> Pair<'a> {
Pair {
b1,
b2,
area: b1.area(b2),
}
}
fn get_x_range(&'a self) -> Range<i64> {
match self.b1.x.cmp(&self.b2.x) {
std::cmp::Ordering::Equal => panic!("unrechable {:?}", self),
std::cmp::Ordering::Less => (self.b1.x + 1)..self.b2.x,
std::cmp::Ordering::Greater => (self.b2.x + 1)..self.b1.x,
}
}
fn get_y_range(&'a self) -> Range<i64> {
match self.b1.y.cmp(&self.b2.y) {
std::cmp::Ordering::Equal => panic!("unrechable {:?}", self),
std::cmp::Ordering::Less => (self.b1.y + 1)..self.b2.y,
std::cmp::Ordering::Greater => (self.b2.y + 1)..self.b1.y,
}
}
fn colide(&'a self, other: &'a Pair) -> bool {
if self.b1.x == self.b2.x && other.b1.y == other.b2.y {
self.get_y_range().contains(&other.b1.y) && other.get_x_range().contains(&self.b1.x)
} else if self.b1.y == self.b2.y && other.b1.x == other.b2.x {
self.get_x_range().contains(&other.b1.x) && other.get_y_range().contains(&self.b1.y)
} else {
false
}
}
fn as_rect(&self) {
println!(
"<path style=\"fill:black\" d=\"M{} {} L{} {} L{} {} L{} {}\" count=\"{}\" />",
self.b1.x,
self.b1.y,
self.b2.x,
self.b1.y,
self.b2.x,
self.b2.y,
self.b1.x,
self.b2.y,
self.area
);
}
// Usefull for debugging
// fn as_line(&self) {
// println!(
// "<line x1=\"{}\" y1=\"{}\" x2=\"{}\" y2=\"{}\" style=\"stroke:yellow;stroke-width:100\" />",
// self.b1.x, self.b1.y, self.b2.x, self.b2.y,
// );
// }
}
fn main() -> Result<()> {
let text = fs::read_to_string("src/day9/act.txt")?;
let boxes: Vec<TilePos> = text
.split("\n")
.filter(|s| s.len() > 0)
.map(|s| s.into())
.collect();
let mut order_pair = Vec::with_capacity(boxes.len() + 1);
for (i, b1) in boxes.iter().enumerate() {
order_pair.push(Pair::new(
b1,
if i + 1 >= boxes.len() {
&boxes[0]
} else {
&boxes[i + 1]
},
))
}
let mut pairs: Vec<Pair> = Vec::with_capacity(boxes.len() * boxes.len());
for (i, b1) in boxes.iter().enumerate() {
for b2 in boxes.iter().skip(i) {
pairs.push(Pair::new(b1, b2))
}
}
pairs.sort_by(|a, b| a.area.cmp(&b.area));
let b = pairs.iter().rev().take(1).next().unwrap();
println!("sol1: {} {:?} {:?}", b.area, b.b1, b.b2);
'b2: for b in pairs.iter().rev() {
// This check sees if there is a point inside the target square
// this will probably fail if you have a case like this
// #XXXX#
// X ## X
// #X##X#
// Lucky we don't tho this could be saved by detecting those and just removing them...
let max_x = b.b1.x.max(b.b2.x);
let min_x = b.b1.x.min(b.b2.x);
let max_y = b.b1.y.max(b.b2.y);
let min_y = b.b1.y.min(b.b2.y);
for p in boxes.iter() {
if p.x > min_x && p.x < max_x && p.y > min_y && p.y < max_y {
continue 'b2;
}
}
// Raycasting to detect when there is no square but we go outside bounds
// this would also fail for the above case
//
// 1 -> p
// ↓
// ↑
// t <- 2
//
let p = TilePos {
x: b.b2.x,
y: b.b1.y,
};
let t = TilePos {
x: b.b1.x,
y: b.b2.y,
};
let ray1 = Pair {
b1: b.b1,
b2: &p,
area: 0,
};
let ray2 = Pair {
b1: b.b1,
b2: &t,
area: 0,
};
let ray3 = Pair {
b1: b.b2,
b2: &p,
area: 0,
};
let ray4 = Pair {
b1: b.b2,
b2: &t,
area: 0,
};
for i in order_pair.iter() {
if i.colide(&ray1) || i.colide(&ray2) || i.colide(&ray3) || i.colide(&ray4) {
continue 'b2;
}
}
println!("sol2 = {} {:?}", b.area, b);
b.as_rect();
break;
}
Ok(())
}

8
src/day9/test.txt Normal file
View File

@@ -0,0 +1,8 @@
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3