3 ms·
I get that the point is Copilot and not the code but sum([arr[i] > arr[i - 3] for i in range(3, len(arr))]) will solve part 2. (Obviously for the first pa
by jstx1 5y ago
I get that the point is Copilot and not the code but
sum([arr[i] > arr[i - 3] for i in range(3, len(arr))])
will solve part 2. (Obviously for the first part subtract 1 and start the range at 1.)
You don't need functions (but that's kind of an opinion, so whatever).
More importantly, to check if a rolling sum is increasing you don't need to compute that sum. I wonder if Copilot can ever figure that out.
- WesleyJohnson 5y agoI haven't dug into this too deeply, but how does checking the current arr index against the value 3 positions back work to correctly calculate the answer?
- WesleyJohnson 5y agoAnother poster had the same thing, but explained it a bit further. I get it now. Clever!