summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-12-14 01:07:49 -0500
committerJesse Luehrs <doy@tozt.net>2022-12-14 01:07:49 -0500
commit41bd54af7fd1ebd28122584abe811c7076571bc0 (patch)
tree2e34eea0b7c613b9b2b940c79665346c3a2f85d9
parent08d25b19f75484fc2d036dec7d431910e75f7cad (diff)
downloadadvent-of-code-41bd54af7fd1ebd28122584abe811c7076571bc0.tar.gz
advent-of-code-41bd54af7fd1ebd28122584abe811c7076571bc0.zip
day 14
-rw-r--r--benches/2022.rs5
-rw-r--r--data/2022/14.txt148
-rw-r--r--src/bin/2022/day14.rs129
-rw-r--r--src/bin/2022/main.rs2
-rw-r--r--src/grid.rs8
5 files changed, 290 insertions, 2 deletions
diff --git a/benches/2022.rs b/benches/2022.rs
index a94f8bb..99becce 100644
--- a/benches/2022.rs
+++ b/benches/2022.rs
@@ -27,6 +27,8 @@ mod day8;
mod day9;
#[path = "../src/bin/2022/day13.rs"]
mod day13;
+#[path = "../src/bin/2022/day14.rs"]
+mod day14;
// NEXT MOD
day!(2022, 1, day1);
@@ -42,6 +44,7 @@ day!(2022, 10, day10);
day!(2022, 11, day11);
day!(2022, 12, day12);
day!(2022, 13, day13);
+day!(2022, 14, day14);
// NEXT DAY
fn bench_2022(c: &mut criterion::Criterion) {
@@ -60,6 +63,7 @@ fn bench_2022(c: &mut criterion::Criterion) {
day_combined!(2022, 11, day11);
day_combined!(2022, 12, day12);
day_combined!(2022, 13, day13);
+ day_combined!(2022, 14, day14);
// NEXT DAY COMBINED
})
});
@@ -81,5 +85,6 @@ criterion::criterion_main!(
bench_2022day11,
bench_2022day12,
bench_2022day13,
+ bench_2022day14,
// NEXT GROUP
);
diff --git a/data/2022/14.txt b/data/2022/14.txt
new file mode 100644
index 0000000..0ba6ba3
--- /dev/null
+++ b/data/2022/14.txt
@@ -0,0 +1,148 @@
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+516,113 -> 521,113
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+529,82 -> 533,82
+541,157 -> 545,157
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+512,111 -> 517,111
+538,154 -> 542,154
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+523,76 -> 527,76
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+511,82 -> 515,82
+514,79 -> 518,79
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+514,85 -> 518,85
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+532,85 -> 536,85
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+535,151 -> 539,151
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+526,85 -> 530,85
+497,50 -> 497,51 -> 512,51
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+509,113 -> 514,113
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+538,148 -> 542,148
+492,17 -> 496,17
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+541,145 -> 545,145
+497,50 -> 497,51 -> 512,51
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+550,154 -> 554,154
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+520,79 -> 524,79
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+517,63 -> 517,64 -> 524,64 -> 524,63
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+532,154 -> 536,154
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+521,117 -> 521,118 -> 531,118 -> 531,117
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+547,157 -> 551,157
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+521,117 -> 521,118 -> 531,118 -> 531,117
+517,63 -> 517,64 -> 524,64 -> 524,63
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+523,82 -> 527,82
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+495,15 -> 499,15
+553,157 -> 557,157
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+498,17 -> 502,17
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+547,151 -> 551,151
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+504,17 -> 508,17
+544,148 -> 548,148
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+523,113 -> 528,113
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+535,157 -> 539,157
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+498,13 -> 502,13
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+526,79 -> 530,79
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+521,117 -> 521,118 -> 531,118 -> 531,117
+541,151 -> 545,151
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+532,134 -> 532,136 -> 530,136 -> 530,142 -> 542,142 -> 542,136 -> 536,136 -> 536,134
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+519,111 -> 524,111
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+529,157 -> 533,157
+511,101 -> 511,103 -> 504,103 -> 504,106 -> 517,106 -> 517,103 -> 513,103 -> 513,101
+501,15 -> 505,15
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+508,85 -> 512,85
+520,85 -> 524,85
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+517,76 -> 521,76
+517,82 -> 521,82
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+523,69 -> 523,70 -> 530,70
+520,73 -> 524,73
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+544,154 -> 548,154
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+511,54 -> 511,56 -> 504,56 -> 504,61 -> 520,61 -> 520,56 -> 515,56 -> 515,54
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+515,109 -> 520,109
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+517,63 -> 517,64 -> 524,64 -> 524,63
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
+523,69 -> 523,70 -> 530,70
+528,131 -> 528,121 -> 528,131 -> 530,131 -> 530,127 -> 530,131 -> 532,131 -> 532,124 -> 532,131 -> 534,131 -> 534,126 -> 534,131
+501,98 -> 501,93 -> 501,98 -> 503,98 -> 503,97 -> 503,98 -> 505,98 -> 505,90 -> 505,98 -> 507,98 -> 507,92 -> 507,98 -> 509,98 -> 509,94 -> 509,98 -> 511,98 -> 511,93 -> 511,98
+489,45 -> 489,38 -> 489,45 -> 491,45 -> 491,38 -> 491,45 -> 493,45 -> 493,40 -> 493,45 -> 495,45 -> 495,39 -> 495,45 -> 497,45 -> 497,43 -> 497,45 -> 499,45 -> 499,43 -> 499,45 -> 501,45 -> 501,36 -> 501,45
+489,20 -> 489,24 -> 483,24 -> 483,32 -> 495,32 -> 495,24 -> 492,24 -> 492,20
+521,170 -> 521,163 -> 521,170 -> 523,170 -> 523,160 -> 523,170 -> 525,170 -> 525,165 -> 525,170 -> 527,170 -> 527,168 -> 527,170 -> 529,170 -> 529,169 -> 529,170 -> 531,170 -> 531,169 -> 531,170 -> 533,170 -> 533,160 -> 533,170
diff --git a/src/bin/2022/day14.rs b/src/bin/2022/day14.rs
new file mode 100644
index 0000000..96c986c
--- /dev/null
+++ b/src/bin/2022/day14.rs
@@ -0,0 +1,129 @@
+#![allow(dead_code)]
+#![allow(unused_variables)]
+
+use advent_of_code::prelude::*;
+
+pub struct Map {
+ grid: Grid<bool>,
+ generator: (Row, Col),
+ abyss: Row,
+ sand_count: usize,
+}
+
+impl Map {
+ fn filled(&self, pos: (Row, Col), floor: bool) -> bool {
+ self.grid[pos.0][pos.1] || (floor && (pos.0 > self.abyss))
+ }
+
+ fn fill(&mut self, pos: (Row, Col)) {
+ self.grid[pos.0][pos.1] = true;
+ }
+
+ fn drop(&mut self, floor: bool) -> bool {
+ let mut pos = self.generator;
+ if self.filled(pos, floor) {
+ if floor {
+ return true;
+ } else {
+ panic!("generator filled but no floor");
+ }
+ }
+ loop {
+ if !floor && pos.0 + 1 >= self.abyss {
+ return true;
+ }
+ let mut can_fall = false;
+ for next in [
+ (pos.0 + 1, pos.1),
+ (pos.0 + 1, pos.1 - 1),
+ (pos.0 + 1, pos.1 + 1),
+ ] {
+ if !self.filled(next, floor) {
+ pos = next;
+ can_fall = true;
+ break;
+ }
+ }
+ if !can_fall {
+ break;
+ }
+ }
+ self.fill(pos);
+ self.sand_count += 1;
+ false
+ }
+}
+
+pub fn parse(fh: File) -> Result<Map> {
+ let mut grid = Grid::default();
+ for line in parse::raw_lines(fh) {
+ let coords: Vec<_> = line
+ .split(" -> ")
+ .map(|pos| {
+ let mut parts = pos.split(',');
+ let col = parts.next().unwrap();
+ let row = parts.next().unwrap();
+ (Row(row.parse().unwrap()), Col(col.parse().unwrap()))
+ })
+ .collect();
+ for pair in coords.windows(2) {
+ let (row, col) = pair[0];
+ let (next_row, next_col) = pair[1];
+ grid.grow(row + 1, col + 1);
+ grid.grow(next_row + 1, next_col + 1);
+ if row == next_row {
+ for col in
+ (col.0.min(next_col.0)..=col.0.max(next_col.0)).map(Col)
+ {
+ grid[row][col] = true;
+ }
+ } else if col == next_col {
+ for row in
+ (row.0.min(next_row.0)..=row.0.max(next_row.0)).map(Row)
+ {
+ grid[row][col] = true;
+ }
+ } else {
+ panic!("diagonal line?");
+ }
+ }
+ }
+ let abyss = grid.rows();
+ grid.grow(grid.rows() + grid.rows().0, grid.cols() + grid.cols().0);
+ Ok(Map {
+ grid,
+ generator: (Row(0), Col(500)),
+ abyss,
+ sand_count: 0,
+ })
+}
+
+pub fn part1(mut map: Map) -> Result<usize> {
+ loop {
+ let abyss = map.drop(false);
+ if abyss {
+ return Ok(map.sand_count);
+ }
+ }
+}
+
+pub fn part2(mut map: Map) -> Result<usize> {
+ loop {
+ let blocked = map.drop(true);
+ if blocked {
+ return Ok(map.sand_count);
+ }
+ }
+}
+
+#[test]
+fn test() {
+ assert_eq!(
+ part1(parse(parse::data(2022, 14).unwrap()).unwrap()).unwrap(),
+ 737
+ );
+ assert_eq!(
+ part2(parse(parse::data(2022, 14).unwrap()).unwrap()).unwrap(),
+ 28145
+ );
+}
diff --git a/src/bin/2022/main.rs b/src/bin/2022/main.rs
index 90221d9..9cc2ba6 100644
--- a/src/bin/2022/main.rs
+++ b/src/bin/2022/main.rs
@@ -24,6 +24,7 @@ mod day8;
mod day9;
mod day12;
mod day13;
+mod day14;
// NEXT MOD
#[paw::main]
@@ -43,6 +44,7 @@ fn main(opt: Opt) -> Result<()> {
11 => advent_of_code::day!(2022, opt.day, opt.puzzle, day11),
12 => advent_of_code::day!(2022, opt.day, opt.puzzle, day12),
13 => advent_of_code::day!(2022, opt.day, opt.puzzle, day13),
+ 14 => advent_of_code::day!(2022, opt.day, opt.puzzle, day14),
// NEXT PART
_ => panic!("unknown day {}", opt.day),
}
diff --git a/src/grid.rs b/src/grid.rs
index 4720fdb..659ef01 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -1,6 +1,10 @@
-#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Default)]
+#[derive(
+ Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default,
+)]
pub struct Row(pub usize);
-#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Default)]
+#[derive(
+ Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default,
+)]
pub struct Col(pub usize);
impl std::ops::Add<usize> for Row {