day01
This commit is contained in:
parent
08385f672a
commit
11b2addf4b
3 changed files with 1027 additions and 4 deletions
1000
res/01/input
Normal file
1000
res/01/input
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,34 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/01/input";
|
||||
|
||||
println!("Result 1: {}", 42);
|
||||
let contents = fs::read_to_string(path).expect("Something went wrong reading the file");
|
||||
|
||||
println!("Result 2: {}", 42);
|
||||
let mut numbers1 = Vec::<usize>::new();
|
||||
let mut numbers2 = Vec::<usize>::new();
|
||||
|
||||
for line in contents.lines() {
|
||||
let (n1, n2) = line.split_once(" ").unwrap();
|
||||
numbers1.push(n1.parse::<usize>().unwrap());
|
||||
numbers2.push(n2.parse::<usize>().unwrap());
|
||||
}
|
||||
|
||||
numbers1.sort();
|
||||
numbers2.sort();
|
||||
|
||||
let result: usize = numbers1
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, n)| n.abs_diff(numbers2[i]))
|
||||
.sum();
|
||||
|
||||
println!("Result 1: {}", result);
|
||||
|
||||
let result: usize = numbers1
|
||||
.iter()
|
||||
.map(|n| numbers2.iter().filter(|n2| n == *n2).count() * n)
|
||||
.sum();
|
||||
|
||||
println!("Result 2: {}", result);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub mod days;
|
||||
#[macro_use]
|
||||
extern crate scan_fmt;
|
||||
|
||||
use std::time::Instant;
|
||||
|
|
Loading…
Reference in a new issue