1
0
mirror of https://gitlab.com/MisterBiggs/aoc2021.git synced 2025-08-05 12:51:22 +00:00

beginning of days 4 and 5

This commit is contained in:
2021-12-17 15:15:21 -07:00
parent 6aae31f295
commit 83a6196b20
7 changed files with 98 additions and 0 deletions

9
day5/rust/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itertools = "0.10"

34
day5/rust/src/main.rs Normal file
View File

@@ -0,0 +1,34 @@
use itertools::Itertools;
use std::collections::HashMap;
use std::fs;
fn main() {
let input = fs::read_to_string("../input.txt").expect("Could not read file");
let lines = input
.lines()
.filter_map(|l| {
l.split(" -> ")
.map(|s| s.split(','))
.flatten()
.map(|i| i.parse::<i8>().unwrap())
.collect_tuple()
})
.collect::<Vec<(i8, i8, i8, i8)>>();
let mut points = HashMap::new();
for (x1, y1, x2, y2) in lines {
let dx: i8 = x2 - x1;
let dy: i8 = y2 - y1;
for x in x1..x1 + dx {
for y in y1..y1 + dy {
*points.entry((x, y)).or_insert(0) += 1;
}
}
}
for (key, value) in points.into_iter() {
println!("({}, {}), {}", key.0, key.1, value);
}
}