diff --git a/day1/p1.rs b/day1/p1.rs index c66d1b5..cc8985d 100644 --- a/day1/p1.rs +++ b/day1/p1.rs @@ -1,13 +1,13 @@ use std::env; use std::fs; use std::process; -use std::{thread, time}; +//use std::{thread, time}; fn main() { //println!("Hello world!"); let args: Vec = env::args().collect(); - let mut path = String::from(""); + let path: String; if args.len() > 1 { path = args[1].clone(); @@ -45,12 +45,12 @@ fn main() { let mut accum: i32 = 0; for i in 0..right.len() { - println!("{}, {}", left[i], right[i]); - println!("Distance is {}", (right[i] - left[i]).abs()); + //println!("{}, {}", left[i], right[i]); + //println!("Distance is {}", (right[i] - left[i]).abs()); accum += (right[i] - left[i]).abs(); //thread::sleep(time::Duration::from_millis(1000)); } - println!("{}", accum); + println!("Answer: {}", accum); } diff --git a/day1/p2.rs b/day1/p2.rs index 0005341..2c45236 100644 --- a/day1/p2.rs +++ b/day1/p2.rs @@ -1,14 +1,14 @@ use std::env; use std::fs; use std::process; -use std::{thread, time}; +//use std::{thread, time}; use std::collections::HashMap; fn main() { //println!("Hello world!"); let args: Vec = env::args().collect(); - let mut path = String::from(""); + let path: String; if args.len() > 1 { path = args[1].clone(); @@ -41,8 +41,8 @@ fn main() { left.sort(); right.sort(); - let mut leftDup = HashMap::new(); - let mut rightDup = HashMap::new(); + let mut left_dup = HashMap::new(); + let mut right_dup = HashMap::new(); // This is kinda ass but I don't care :) let mut i: usize = 0; @@ -52,12 +52,12 @@ fn main() { k+=1; } - leftDup.insert(left[i],k-i); + left_dup.insert(left[i],k-i); i = k; } - //println!("{}", leftDup[&3]); + //println!("{}", left_dup[&3]); i = 0; while i < right.len() { @@ -66,21 +66,21 @@ fn main() { k+=1; } - rightDup.insert(right[i],k-i); + right_dup.insert(right[i],k-i); i = k; } - //println!("{}", rightDup[&3]); + //println!("{}", right_dup[&3]); let mut accum: i32 = 0; - for (left, num) in &leftDup { - let shit = match rightDup.get(left) { + for (left, num) in &left_dup { + let shit = match right_dup.get(left) { Some(val) => *val, None => 0, }; accum += (*left * (*num as i32)) * (shit as i32); } - println!("{}", accum); + println!("Answer: {}", accum); }