first
This commit is contained in:
commit
d72a5b20fc
11 changed files with 1106 additions and 0 deletions
26
src/day_1_1.rs
Normal file
26
src/day_1_1.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Iter;
|
||||
|
||||
pub fn solve_day_1_1() {
|
||||
// --snip--
|
||||
let file_path = "/home/clement/RustroverProjects/advent_of_code/src/inputs/input_1.txt";
|
||||
println!("In file {file_path}");
|
||||
|
||||
let (mut l_list, mut r_list) : (Vec<i32>, Vec<i32>) = fs::read_to_string(file_path)
|
||||
.expect("Should have been able to read the file")
|
||||
.split('\n')
|
||||
.map(|s|{
|
||||
let mut splited = s.split_whitespace();
|
||||
(
|
||||
splited.next().unwrap().parse::<i32>().unwrap(),
|
||||
splited.next().unwrap().parse::<i32>().unwrap()
|
||||
)
|
||||
}).unzip();
|
||||
|
||||
l_list.sort();
|
||||
r_list.sort();
|
||||
let ans = l_list.iter().zip(r_list.iter()).map(|(l, r)| (l - r).abs()).sum::<i32>();
|
||||
println!("{}", ans);
|
||||
|
||||
}
|
||||
22
src/day_1_2.rs
Normal file
22
src/day_1_2.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Iter;
|
||||
|
||||
pub fn solve_day_1_2() {
|
||||
// --snip--
|
||||
let file_path = "/home/clement/RustroverProjects/advent_of_code/src/inputs/input_1.txt";
|
||||
println!("In file {file_path}");
|
||||
|
||||
let (mut l_list, mut r_list) : (Vec<i32>, Vec<i32>) = fs::read_to_string(file_path)
|
||||
.expect("Should have been able to read the file")
|
||||
.split('\n')
|
||||
.map(|s|{
|
||||
let mut splited = s.split_whitespace();
|
||||
(
|
||||
splited.next().unwrap().parse::<i32>().unwrap(),
|
||||
splited.next().unwrap().parse::<i32>().unwrap()
|
||||
)
|
||||
}).unzip();
|
||||
|
||||
l_list.sort();
|
||||
}
|
||||
1000
src/inputs/input_1.txt
Normal file
1000
src/inputs/input_1.txt
Normal file
File diff suppressed because it is too large
Load diff
9
src/main.rs
Normal file
9
src/main.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
mod day_1_1;
|
||||
mod day_1_2;
|
||||
|
||||
use crate::day_1_1::solve_day_1_1;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
// solve_day_1_1();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue