master
mitchellhansen 4 years ago
parent 9d41f04535
commit 1cdb2f668f

@ -35,6 +35,6 @@ pub trait Problem {
fn main() {
let problem9 = Problem9::new(&util::get_problem(9));
problem9.run_part1();
//problem9.run_part1();
problem9.run_part2();
}

@ -2,7 +2,7 @@
use crate::Problem;
pub struct Problem9 {
number_list: Vec<i32>,
number_list: Vec<u64>,
}
impl Problem9 {}
@ -15,7 +15,7 @@ impl Problem for Problem9 {
.filter_map(|s| {
let s = s.trim();
if !s.is_empty() {
Some(s.parse::<i32>().unwrap())
Some(s.parse::<u64>().unwrap())
} else {
None
}
@ -25,10 +25,71 @@ impl Problem for Problem9 {
fn run_part1(&self) {
let mut top = 0;
let mut bottom = 25;
let mut rolling_array = &self.number_list[top..bottom];
println!("{:?}", self.number_list);
while bottom < self.number_list.len() {
//let sum = rolling_array.iter().fold(0, |a, &b| a + b);
println!("{:?}", rolling_array);
let mut found = false;
for i in rolling_array {
for q in rolling_array {
let sum = i + q;
if sum == self.number_list[bottom] {
found = true;
println!("the two numbers are {} {}", i, q);
}
}
}
if found == false {
println!("bad stuff found at {},supposed to be {}", bottom + 1, self.number_list[bottom]);
}
top += 1;
bottom += 1;
rolling_array = &self.number_list[top..bottom];
}
}
// invalid number was 26134589
fn run_part2(&self) {
let mut top = 0;
let mut bottom = top + 1;
let mut rolling_array = &self.number_list[top..bottom];
println!("{:?}", self.number_list);
while top + 1 < self.number_list.len() {
while 26134589 >= rolling_array.iter().fold(0, |a, &b| a + b) {
bottom += 1;
rolling_array = &self.number_list[top..bottom];
if rolling_array.iter().fold(0, |a, &b| a + b) == 26134589 {
let mut v = vec![0; 17];
v.copy_from_slice(&rolling_array);
v.sort();
println!("{:?}", v);
println!("found top {:?} bottom {}", top, bottom);
}
}
let sum = rolling_array.iter().fold(0, |a, &b| a + b);
println!("top {}, bottom {}, sum {}", top, bottom, sum);
top += 1;
bottom = top + 1;
rolling_array = &self.number_list[top..bottom];
}
}
}

Loading…
Cancel
Save