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

pass touching indexes to nextelefn

parent 53bab019
......@@ -22,12 +22,19 @@ fn print_vec(v: &Vec<u32>) {
println!();
}
fn new_val_for(elements: &Vec<u32>, circle_iter_ele_index: u32) -> u32 {
fn new_val_for(elements: &Vec<u32>, circle_iter_ele_index: u32, index_touching_elements: &Vec<usize>) -> 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);
println!("--> direct_follower_sum: {} ", direct_follower_sum);
let touching_elements_sum: u32 = index_touching_elements.iter()
.map(|i: &usize| elements[*i])
.sum();
println!("--> touching_elements_sum: {} ", touching_elements_sum);
elements.last().unwrap() + 1
}
......@@ -41,11 +48,14 @@ pub fn calc_day_3_b(search_value: u32) -> u32 {
// We start with the first number
let mut current_val = 2;
let mut elements: Vec<u32> = vec![1, 1, current_val.clone()] as Vec<u32>;
let mut touching_indexes: Vec<usize> = Vec::with_capacity(3);
touching_indexes.push(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);
println!("circle_iter_target: {}", circle_iter_target);
println!("############## START ##############");
while current_val <= search_value {
......@@ -54,14 +64,15 @@ pub fn calc_day_3_b(search_value: u32) -> u32 {
println!("index: {}", circle_iter_ele_index);
print_vec(&elements);
current_val = new_val_for(&elements, circle_iter_ele_index);
current_val = new_val_for(&elements, circle_iter_ele_index, &touching_indexes);
elements.push(current_val);
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);
circle_iter_ele_index = 0;
println!("circle_iter_target: {}", circle_iter_target);
println!("###################### circle_iter_target: {}", circle_iter_target);
}else {
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