Day 02
Day 02, part 1
Discussion
Another line-by-line set of data. I think this time I'll try recursion. I'll call a template on a line, call an isSafe function on that line's sequence, adding 1 or not to the safe-levels variable, which I'll carry as a parameter to the recursive iteration on line+next until there's no +next values left. The isSafe function checks first if starts off ascending or descending then evaluates that each subsequent interval meets the criteria.
Solution
See formatted solution code on GitHub: solution-p1, line 98.
See formatted solution code on GitHub: check-levels-p1, line 119.
See formatted solution code on GitHub: gar:level-increment-p1, line 143.
Solution to the test data set
2
Solution to the actual data set
472
Day 02, part 2
Discussion
Looks like I just need to copy the solution template, the recursive check-levels
template, and change the gar:safe-increment() function. I'm thinking I could
save the previous index as I progress down the sequence, and when a condition against the next index fails, try again
using the previous index, and if that succeeds, drop the _current_ index and move on. But if it fails,
drop the _next_ index to see if it succeeds. If it does, move on, or else fail altogether.
one fails. I think.
Let's have at it.
Well, after struggling through it, I ended up checking how Daniel Persson solved it and it looks like he had
a time with it, too. Like he did, I decided to remove each index in sequence and test the sub-sequence (after making
sure the full sequence didn't already work by indexing at 0), using the some in .. satisfies to
exit upon success.
Solution
See formatted solution code on GitHub: gar:level-increment-p2, line 207.
Solution to the test data set
4
Solution to the actual data set
520