Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Thanks for the comment, I will revise the kata tomorrow.
Answer to the first part:
Answer to the second part of the comment:
If I am not wrong, Unnamed was using a mathematical approach and it levarages the periodicity of the sequence in terms of odd and even terms. While most of us is using iterative approach.The provided solution is more efficient for larger values.
Regarding you question:
First part (n mod 6)
If you know the parity of two numbers, you also know the parity of their sum. So the sequence is defined as: f(n) = f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)
Initial values: f(0)=0, f(1)=1, f(2)=1, f(3)=2, f(4)=4. If you compute the parity, you will be able to see a pattern (i.e.odd, odd, even, even, even, even, odd, odd, even, even, even, even,...). So you will be able to notice the pattern repeats every 6 terms.
The list [0,1,2,2,2,2],
The above pattern (section 1) gives us the cumulative count of odd numbers.
For n, there are (n/6) complete segments of 6 terms. Therefore, 2x(n/6) gives the number of odd terms in these complete segments.
The remainder, n mod 6, tells us where in the 6-term segment we are. The list [0,1,2,2,2,2] gives the cumulative count of odd numbers up to that point in the cycle.
In summary, the sequence has a repeating pattern of parity due its linear definition and the properties of of parity over addition. Therefore, this repeating pattern allowed him, Unnamed, to use a mathematical approach.