Commit dcd64a86 authored by Kai Brandes's avatar Kai Brandes

some cleanup

parent 4a70c586
......@@ -19,7 +19,7 @@ fn rel_position_and_circle(pos: &u32) -> (u32, u32) {
// Calcs the sum based on direct followers and elements "touching" from previous circles
fn new_val_for(elements: &Vec<u32>, current_width: u32, circle_iter_ele_index: u32, nr_touched_elements: u32) -> u32 {
let mut direct_follower_sum = elements[elements.len() - 1];
if (circle_iter_ele_index % (current_width + 1) == 1) {
if circle_iter_ele_index % (current_width + 1) == 1 {
direct_follower_sum += elements[elements.len() - 2];
}
let mut touching_elements_sum = 0;
......@@ -43,9 +43,9 @@ fn nr_elements_touched(circle_iter_ele_index: u32, width: u32) -> u32 {
let max_elements_in_row = cmp::min(width, 3);
let mut ele: u32 = 0;
for i in 0..(index_in_single_iter+1) {
if(i <= inc_until) {
if i <= inc_until {
ele = cmp::min(max_elements_in_row,ele + 1);
}else if(i > dec_from){
}else if i > dec_from {
ele = cmp::max(1, ele - 1);
}
}
......@@ -62,10 +62,10 @@ pub fn calc_day_3_b(search_value: u32) -> u32 {
let mut elements_touched = 1;
while current_val <= search_value {
let current_width = (circle_iter_target / 2);
let current_width = circle_iter_target / 2;
let new_elements_touched = nr_elements_touched(circle_iter_ele_index, current_width);
// Drop elements which can not anymore be touched or referenced by future calcs
if(new_elements_touched < elements_touched || elements_touched == 3) {
if new_elements_touched < elements_touched || elements_touched == 3 {
elements.remove(0);
}
elements_touched = new_elements_touched;
......
......@@ -5,7 +5,7 @@ use std::collections::HashSet;
use wasm_bindgen::prelude::*;
fn line_valid(input: &str) -> bool {
let mut whitespace: Vec<&str> = input.split_whitespace().collect();
let whitespace: Vec<&str> = input.split_whitespace().collect();
let total_words = whitespace.len() as u32;
total_words == whitespace.iter().collect::<HashSet<&&str>>().len() as u32
}
......
......@@ -8,7 +8,7 @@ fn calc_new<F>(input: String, next_result_fn: F) -> u32 where F: Fn(i32) -> i32
let mut pos: i32 = 0;
let mut step: u32 = 0;
while (pos >= 0 && pos < instructions.len() as i32) {
while pos >= 0 && pos < instructions.len() as i32 {
let old_pos = pos;
pos = pos + instructions.get(pos as usize).unwrap();
instructions[old_pos as usize] = next_result_fn(instructions[old_pos as usize]);
......@@ -26,7 +26,7 @@ pub fn calc_day_5_a(input: String) -> u32 {
#[wasm_bindgen]
pub fn calc_day_5_b(input: String) -> u32 {
calc_new(input, |a| if (a == 3) { a - 1 } else { a + 1 })
calc_new(input, |a| if a == 3 { a - 1 } else { a + 1 })
}
#[cfg(test)]
......
......@@ -8,7 +8,7 @@ fn calc_next(v: Vec<u32>) -> (usize, u32) {
.fold(None, |old, it: (usize, &u32)|
match old {
None => Some((it.0, it.1)),
Some((a, b)) => if (b < it.1) { Some((it.0, it.1)) } else { Some((a, b)) }
Some((a, b)) => if b < it.1 { Some((it.0, it.1)) } else { Some((a, b)) }
},
).unwrap();
(result.0,result.1.clone())
......
extern crate adventofcode_2017;
extern crate time;
#[test]
fn it_shoul_assert_result_of_day5_a() {
......
extern crate adventofcode_2017;
extern crate time;
#[test]
fn it_shoul_assert_result_of_day6_a() {
......
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