0

If we round down the number of weeks in a year to 52, And we label each of the 52 weeks either 1, 2, 3, or 4 And we label them in order, the first week of the year being 1, the second being 2, third being 3, fourth being 4, fifth being 1, sixth being 2, ... and so on

Then how can we calculate what the Week # of 4 is for any given Week #?

The slow way is make a table, like the following, and look it up manually. There has got to be a smart way :-)?

1   1
2   2
3   3
4   4
5   1
6   2
7   3
8   4
9   1
10  2
11  3
12  4
13  1
14  2
15  3
16  4
17  1
18  2
19  3
20  4
21  1
22  2
23  3
24  4
25  1
26  2
27  3
28  4
29  1
30  2
31  3
32  4
33  1
34  2
35  3
36  4
37  1
38  2
39  3
40  4
Luke Allen
  • 301
  • 5
  • 16

2 Answers2

1

let $n$ be the week number. Then your 'index' is $$1 + ((n-1) ~\text{mod}~ 4 ).$$ (Sorry for the wrong answer a few minutes ago.)

0

Your week number of 4 is just the week number $\bmod 4$ except that you want $4$ when multiples of $4$ give zero. You can either do

week # of 4=week $\bmod 4$ if (week # of 4=0) week # of 4=4

or if you hate if statements

week # of 4 = (week-1) $\bmod 4 +1$

Ross Millikan
  • 374,822