diff --git a/src/day2/main.rs b/src/day2/main.rs index 4725bd0..4d9a528 100644 --- a/src/day2/main.rs +++ b/src/day2/main.rs @@ -14,12 +14,10 @@ fn sol1(text: &String) { let end: i64 = range.next().unwrap().parse().unwrap(); let mut to_sum: i64 = 0; for i in start..(end + 1) { - // TODO maybe skip entire ones if the start and end are the same size and cannot have anything inside if (i as f64).log10().ceil() as i64 % 2 == 0 { let str = i.to_string(); let pivot = str.len() / 2; if str[0..pivot] == str[pivot..] { - // println!("Found wrong id: {}", i); to_sum += i; } } @@ -44,29 +42,20 @@ fn sol2(text: &String) { let mut to_sum: i64 = 0; 'bigloop: for i in start..(end + 1) { - // println!("Started Num: {}", i); let str = i.to_string(); let str_len = str.len(); - 'other_num: for test_num in 1..(str_len / 2) + 1 { + 'other_num: for test_num in (1..(str_len / 2) + 1).rev() { if str_len % test_num != 0 { continue 'other_num; } - for test_index in (test_num..str_len).step_by(test_num) { + for test_index in (test_num..str_len).step_by(test_num).rev() { let prev = test_index - test_num; - /*println!( - "Testing: {} {} {} != {}", - test_index, - test_num, - str[prev..prev + test_num].to_owned(), - str[test_index..test_index + test_num].to_owned() - );*/ if str[prev..prev + test_num] != str[test_index..test_index + test_num] { - // println!("SKIP"); continue 'other_num; } } - println!("Found wrong id: {}", i); + // println!("Found wrong id: {}", i); to_sum += i; continue 'bigloop;