Commit 53bab019 authored by Kai Brandes's avatar Kai Brandes

correct direct_follower_sum

parent e1549041
......@@ -22,8 +22,12 @@ fn print_vec(v: &Vec<u32>) {
println!();
}
fn new_val_for(elements: &Vec<u32>, ele_index: &u32) -> u32 {
fn new_val_for(elements: &Vec<u32>, circle_iter_ele_index: u32) -> u32 {
let mut direct_follower_sum = elements[elements.len()-2];
if(circle_iter_ele_index == 1) {
direct_follower_sum += elements[elements.len()-3];
}
println!("direct_follower_sum: {} ", direct_follower_sum);
elements.last().unwrap() + 1
}
......@@ -38,7 +42,7 @@ pub fn calc_day_3_b(search_value: u32) -> u32 {
let mut current_val = 2;
let mut elements: Vec<u32> = vec![1, 1, current_val.clone()] as Vec<u32>;
let mut ele_index = 0;
let mut circle_iter_ele_index = 0;
let mut circle_iter_count = 1;
let mut circle_iter_target = next_circle_iter_target(circle_iter_count);
......@@ -47,19 +51,19 @@ pub fn calc_day_3_b(search_value: u32) -> u32 {
while current_val <= search_value {
println!("-----------------");
println!("index: {}", ele_index);
println!("index: {}", circle_iter_ele_index);
print_vec(&elements);
current_val = new_val_for(&elements, &ele_index);
current_val = new_val_for(&elements, circle_iter_ele_index);
elements.push(current_val);
if(ele_index > 0 && ele_index % circle_iter_target == 0) {
if(circle_iter_ele_index > 0 && circle_iter_ele_index % circle_iter_target == 0) {
circle_iter_count += 1;
circle_iter_target = next_circle_iter_target(circle_iter_count);
ele_index = 0;
circle_iter_ele_index = 0;
println!("circle_iter_target: {}", circle_iter_target);
}else {
ele_index += 1;
circle_iter_ele_index += 1;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment