24
4
This simple challenge is very similar to this one: How many days in a month? The only difference is you yield the number of days in a month given the index of the month instead of its name.
The reason I ask this near-duplicate is curiosity about mathematical patterns in the sequence of numbers. For example, a simple observation is that even-indexed months have 31 until August and then it flips — but golf that observation and/or make better ones that yield better strokes...
INPUT: Integer indicating the month; 1
through 12
. (Optionally, you can accept 0
-indexed month numbers from 0
to 11
.)
OUTPUT: Number of days in that month. February can return 28
or 29
.
Complete I/O table:
INPUT : OUTPUT
1 31
2 28 or 29
3 31
4 30
5 31
6 30
7 31
8 31
9 30
10 31
11 30
12 31
What is the $[1=x]$ notation? – infinitezero – 2019-11-15T23:59:56.557
@infinitezero It means "1 if x=1, 0 otherwise". – Vincent – 2019-11-16T14:59:48.650
@infinitezero Iverson bracket (bottom of page: So far the notations…)
– Adám – 2019-11-16T19:32:10.913