Day 1 cleanup

This commit is contained in:
Logan G 2024-12-01 00:03:27 -07:00
parent 90edac903a
commit aa7351c5a6
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 16 additions and 16 deletions

View file

@ -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<String> = 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);
}

View file

@ -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<String> = 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);
}