diff --git a/2024/day1/part1/step2/src/main.rs b/2024/day1/part1/step2/src/main.rs index 2f8b0ec..c3701c3 100644 --- a/2024/day1/part1/step2/src/main.rs +++ b/2024/day1/part1/step2/src/main.rs @@ -1,8 +1,8 @@ fn main() { - - - let mut list1: Vec = serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap(); - let mut list2: Vec = serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap(); + let mut list1: Vec = + serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap(); + let mut list2: Vec = + serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap(); list1.sort(); list2.sort(); @@ -17,8 +17,7 @@ fn main() { let int2 = list2[i]; if int1 > int2 { totaldiff += (int1 - int2) as i64; - } - else if int1 < int2 { + } else if int1 < int2 { totaldiff += (int2 - int1) as i64; } } diff --git a/2024/day1/part2/src/main.rs b/2024/day1/part2/src/main.rs index 0b92783..b8cdeb4 100644 --- a/2024/day1/part2/src/main.rs +++ b/2024/day1/part2/src/main.rs @@ -1,17 +1,19 @@ fn main() { - let mut list1: Vec = serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap(); - let mut list2: Vec = serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap(); + let mut list1: Vec = + serde_json::from_reader(std::fs::File::open("l1.json").unwrap()).unwrap(); + let mut list2: Vec = + serde_json::from_reader(std::fs::File::open("l2.json").unwrap()).unwrap(); let mut simScoreTotal: i64 = 0; for i in &list1 { let mut totalsRight: i32 = 0; for j in &list2 { - if i==j { + if i == j { totalsRight += 1; } } - simScoreTotal += (totalsRight*i) as i64; + simScoreTotal += (totalsRight * i) as i64; } println!("{simScoreTotal}") } diff --git a/2024/day2/part1/src/main.rs b/2024/day2/part1/src/main.rs index 8177fa2..5280184 100644 --- a/2024/day2/part1/src/main.rs +++ b/2024/day2/part1/src/main.rs @@ -3,12 +3,15 @@ use std::thread::current; fn main() { // read file input - let lines: Vec = read_to_string("input.txt").unwrap().lines().map(String::from).collect(); + let lines: Vec = read_to_string("input.txt") + .unwrap() + .lines() + .map(String::from) + .collect(); // current safe total count let mut safecount = 0; // for each line for i in lines { - println!("{i}"); // for each line, split into a Vec of the values let mut frfrstr: Vec = i.split_whitespace().map(|s| s.parse().unwrap()).collect(); @@ -28,19 +31,16 @@ fn main() { let mut sort2 = sort1.clone(); sort2.reverse(); if frfr == sort1 || frfr == sort2 { - let mut mode = 0; let tempval0 = frfr[*&0]; let tempval1 = frfr[*&1]; if tempval0 < tempval1 { println!("increasing mode"); mode = 1; - } - else if tempval0 > tempval1 { + } else if tempval0 > tempval1 { println!("decreasing mode"); mode = -1; - } - else if tempval0 == tempval1 { + } else if tempval0 == tempval1 { println!("its equal and so its discarded"); continue; } @@ -49,15 +49,14 @@ fn main() { // starts true, becomes invalid let mut currentcheckstate = true; 'fr1: for i2 in 1..frfr.len() { - let realdiff = frfr[*&i2-1] - (frfr[*&i2]); + let realdiff = frfr[*&i2 - 1] - (frfr[*&i2]); if mode == 1 { if realdiff > -1 || realdiff < -3 { println!("realdiff {realdiff} plus"); currentcheckstate = false; println!("abs diff averted"); } - } - else if mode == -1 { + } else if mode == -1 { if realdiff > 3 || realdiff < 1 { println!("realdiff {realdiff} minus"); currentcheckstate = false; @@ -69,15 +68,11 @@ fn main() { safemini = true; println!("allowed") } - - } if safemini { safecount += 1 } - - } println!("{safecount}") } diff --git a/2024/day2/part2/src/main.rs b/2024/day2/part2/src/main.rs index e185596..b4bc3e0 100644 --- a/2024/day2/part2/src/main.rs +++ b/2024/day2/part2/src/main.rs @@ -3,12 +3,15 @@ use std::thread::current; fn main() { // read file input - let lines: Vec = read_to_string("input.txt").unwrap().lines().map(String::from).collect(); + let lines: Vec = read_to_string("input.txt") + .unwrap() + .lines() + .map(String::from) + .collect(); // current safe total count let mut safecount = 0; // for each line for i in lines { - println!("{i}"); // for each line, split into a Vec of the values let mut frfrstr: Vec = i.split_whitespace().map(|s| s.parse().unwrap()).collect(); @@ -27,7 +30,6 @@ fn main() { frfr.remove(i); } - // sorted regular and reverse to check condition 1 let mut sort1 = frfr.clone(); sort1.sort(); @@ -77,8 +79,6 @@ fn main() { if safemini { safecount += 1 } - - } println!("{safecount}") }