I work in 3 shifts, each week different one. The order is morning shift (m), night one (n) and afternoon one (a). The order i fixed, i.e. it never changes, even if one won't work that week.
I created a function to get ISO week number. When I throw it a date, it returns week number.
This week (no. 48), for example, I work morning, therefore 48 % 3 = 0 → m = 0; n = 1; a = 2.
I saved this into array shifts = ["m", "n", "a"].
This is the easy part. But as the end of the year comes, I need to solve a problem. As 52 (the total number of weeks in 2017) is not divisible by 3 and there are different number of weeks in different years, modulo 0 (which for year 2017 means m), means something else in different years.
So, the actual question is what would be the fastest and simplest algorithm (rather fastest than simplest), doesn't need to be human-readable, with explanation (if necessary) why/how does it do what it does.
I thought of one (which is neither fast nor simple): to the known week no. & shift type combo add the number of weeks following that week until the end of the year, and recalculate the array shifts.