diff options
author | Guillermo Ramos | 2024-12-04 10:28:51 +0100 |
---|---|---|
committer | Guillermo Ramos | 2024-12-04 10:51:41 +0100 |
commit | 1c9620d4666fdf41ef751f100dfb17f14133dd35 (patch) | |
tree | ece2ef499492b2426b13bd9b48f98f35a60123c2 /2024/1/p2.rs | |
parent | a42dc9c3efb52a74fc581835f585679e8a5e2bb1 (diff) | |
download | AoC-1c9620d4666fdf41ef751f100dfb17f14133dd35.tar.gz |
2024: move to single Rust crate
Diffstat (limited to '2024/1/p2.rs')
-rw-r--r-- | 2024/1/p2.rs | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/2024/1/p2.rs b/2024/1/p2.rs deleted file mode 100644 index ebaa4db..0000000 --- a/2024/1/p2.rs +++ /dev/null @@ -1,25 +0,0 @@ -use std::collections::HashMap; - -const INPUT_FILE: &str = "input"; - -fn main() { - let input = std::fs::read_to_string(INPUT_FILE).expect("Reading input file"); - let mut left: Vec<u32> = vec![]; - let mut right: HashMap<u32, u32> = HashMap::new(); - for line in input.lines() { - let mut fields = line.split_whitespace(); - let e = "Wrong file format"; - left.push(fields.next().expect(e).parse().expect(e)); - let r: u32 = fields.next().expect(e).parse().expect(e); - match right.get(&r) { - None => right.insert(r, 1), - Some(v) => right.insert(r, v + 1), - }; - } - - let mut distance: u32 = 0; - for l in left { - distance += l * right.get(&l).unwrap_or(&0); - } - println!("Distance: {}", distance); -} |