Took me a while to figure out. I was initially going down some path finding algorithm. But after looking at it a while It started to look like some dynamic programming/combinatorics.
Took me a while to get the actual equation down but finally did it. input is with 0 and max + 3 already added.
#[aoc(day10,part1)]fnthe_path(input:&Vec<usize>)->usize{letmutone_count=0;letmutthree_count=0;for(i,v)ininput[..input.len()-1].iter().enumerate(){letdiff=((*v)asi32-(input[i+1])asi32).abs()asusize;ifdiff==1{one_count+=1;}elseifdiff==3{three_count+=1;}}one_count*three_count}#[aoc(day10,part2)]fnall_combinations(input:&Vec<usize>)->usize{letmutthe_ways=HashMap::new();// Only one way to get to 0 or 1the_ways.insert(0,1);the_ways.insert(1,1);for&vin&input[2..]{letmutval=the_ways.get(&(v-1)).unwrap_or(&0)+the_ways.get(&(v-2)).unwrap_or(&0);ifv>2{val+=the_ways.get(&(v-3)).unwrap_or(&0);}the_ways.insert(v,val);}*the_ways.get(input.last().unwrap()).unwrap()}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Took me a while to figure out. I was initially going down some path finding algorithm. But after looking at it a while It started to look like some dynamic programming/combinatorics.
Took me a while to get the actual equation down but finally did it.
input
is with0
andmax + 3
already added.