aboutsummaryrefslogtreecommitdiff
path: root/2022/15/b.rs
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-02 14:45:11 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-02 14:45:11 +0200
commit6b89133a79e798edadca7eb59800441535e97670 (patch)
tree2ee1b25378fa235038f7ce28b5b7896c64bda259 /2022/15/b.rs
parentd287854b301bb8b4726b50ac21513b658fe1fb6b (diff)
downloadaoc-6b89133a79e798edadca7eb59800441535e97670.tar.gz
aoc-6b89133a79e798edadca7eb59800441535e97670.zip
Day 15 2022
Diffstat (limited to '2022/15/b.rs')
-rw-r--r--2022/15/b.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/2022/15/b.rs b/2022/15/b.rs
new file mode 100644
index 0000000..3c321e1
--- /dev/null
+++ b/2022/15/b.rs
@@ -0,0 +1,33 @@
1use std::cmp::max;
2mod common;
3use common::*;
4
5#[allow(non_snake_case)]
6fn get_pos(sensors: &Vec<Sensor>, N: i64) -> Pos {
7 for i in 0..=N {
8 let mut ranges = sensors.iter()
9 .map(|s| s.get_range(i))
10 .filter(|r| r.left <= r.right)
11 .collect::<Vec<_>>();
12 ranges.sort();
13 let mut lastr = ranges[0].right;
14 for j in 1..ranges.len() {
15 if lastr + 1 < ranges[j].left {
16 return Pos { x: lastr+1, y: i };
17 }
18 lastr = max(lastr, ranges[j].right);
19 }
20 if lastr < N {
21 return Pos { x: N, y: i };
22 }
23 }
24 panic!("Position not found");
25}
26
27fn main() {
28 const N: i64 = 4000000;
29 const M: i64 = 4000000;
30 let sensors = read_sensors_from_stdin();
31 let p = get_pos(&sensors, N);
32 println!("x = {}, y = {} -> {}", p.x, p.y, p.x * M + p.y);
33}

Generated with cgit - Back to sebastiano.tronto.net