Compare commits

..

7 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
17 changed files with 4329 additions and 0 deletions

124
Cargo.lock generated
View File

@@ -13,4 +13,128 @@ name = "aoc"
version = "0.1.0"
dependencies = [
"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

@@ -35,5 +35,22 @@ path = "src/day7/main.rs"
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]
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

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