Advent of Code 2021 Day 1

Sonar Sweep. A simple question to start as always

It’s December and that means Advent of Code. As usual, the first day’s puzzle is pretty simple - just to get one warmed up.

Part 1 and Part 2 were not so different. Just finding the difference between terms in an array and counting the number that are increasing.

For part 1 it was the difference between the successive items, for part 2 it was the difference successive sums of a three term window.

The slight optimisation as that for successive three term windows, the sum of the last two terms in the first window is equal to the some of the first two terms in the second window. So you only need to check if the difference between the nth term and the (n+3)rd term is increasing.

My solution in swift can be seen here.