Skip to content

Commit

Permalink
day 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombadad committed Dec 21, 2022
1 parent 0f25e3b commit 675f0a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ path = "src/thirteenth-day.rs"
[[bin]]
name = "fourteenth-day"
path = "src/fourteenth-day.rs"

[[bin]]
name = "fifteenth-day"
path = "src/fifteenth-day.rs"
[dependencies]
grid = "0.9.0"
itertools = "0.10.5"
Expand Down
18 changes: 18 additions & 0 deletions src/fifteenth-day.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use itertools::Itertools;

const TEST: &str = include_str!("../test_data/test.txt");


fn main() {
let data = TEST.lines().map(|x| {
let (sensor_str, beacon_str) = x.split_once(": ").unwrap();
let (sen_loc_x, sen_loc_y) = sensor_str["Sensor at ".len()..].split_once(", ").unwrap();
let (bea_loc_x, bea_loc_y) = beacon_str["closest beacon is at ".len()..].split_once(", ").unwrap();
(
(sen_loc_x["x=".len()..].parse::<i32>().unwrap(), sen_loc_y["y=".len()..].parse::<i32>().unwrap()),
(bea_loc_x["x=".len()..].parse::<i32>().unwrap(), bea_loc_y["y=".len()..].parse::<i32>().unwrap())
)
}).collect_vec();

println!("{:?}", data);
}
16 changes: 14 additions & 2 deletions test_data/test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
Sensor at x=9, y=16: closest beacon is at x=10, y=16
Sensor at x=13, y=2: closest beacon is at x=15, y=3
Sensor at x=12, y=14: closest beacon is at x=10, y=16
Sensor at x=10, y=20: closest beacon is at x=10, y=16
Sensor at x=14, y=17: closest beacon is at x=10, y=16
Sensor at x=8, y=7: closest beacon is at x=2, y=10
Sensor at x=2, y=0: closest beacon is at x=2, y=10
Sensor at x=0, y=11: closest beacon is at x=2, y=10
Sensor at x=20, y=14: closest beacon is at x=25, y=17
Sensor at x=17, y=20: closest beacon is at x=21, y=22
Sensor at x=16, y=7: closest beacon is at x=15, y=3
Sensor at x=14, y=3: closest beacon is at x=15, y=3
Sensor at x=20, y=1: closest beacon is at x=15, y=3

0 comments on commit 675f0a0

Please sign in to comment.