# Days in indexed month

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


# C# (Visual C# Compiler), 28 bytes

x=>DateTime.DaysInMonth(1,x)


Try it online!

• This is exactly the old revision of Embodiment's C# answer: codegolf.stackexchange.com/posts/195901/revisions :( Commented Nov 15, 2019 at 15:16
• Ohh, I didn't see it in the answers so I assumed no one had posted this yet Commented Nov 15, 2019 at 15:17

# Pyth, 12 bytes

--31%%Q7 2q1


Try it online!

# Pyth, 22 18 bytes

-+30@+*4U2t*3U2Qq2


Try it online!

Uses 1-indexed months and 29 as February. Theres probably a more refined solution somewhere Saved 4 bytes by using U2 instead of ,Z1 and replacing the logic with -1 if input is 2

## How it works

-+30@+*4U2t*3U2Qq2
+30               - 30 plus...
@          Q   - The index Q=input
+*4U2         - Of 4 times the list [0,1] -> [0,1,0,1,0,1,0,1]
t*3U2    - Plus 3 times the list [0,1] minus the first element
-               q2 - Minus [2 == input], with input added implicitly


f 1=28;f m=31-mod m 7mod2


Try it online!

0-indexed. Handles February the same way that Andrew Ray's answer does, but otherwise uses the mod-7-mod-2 approach.

# C# .NET, 98 bytes

class P{static void Main(string[]a){System.Console.Write((int)" "[int.Parse(a[0])]);}}


Try Online
Uses Ascii control characters (RS, US and FS) and gets their absolute character value.

# TI-Basic, 18 bytes

31-(Ans=1)-2fPart(3.5fPart(Ans/7


Takes input in Ans as a 0-indexed month. Returns 29 for February.

### 18 bytes

101+Ans(Ans≠11
dbd(Ans,Ans+1


Alternative solution using a different approach. Takes input in Ans as a 0-indexed month. Returns 29 for February.

# Thunno 2, 9 bytes

7%ɗ$ḅ+31_  Try it online! Port of Adám's APL answer. #### Explanation 7%ɗ$ḅ+31_  # Implicit input
31_  # 31 - (
7%ɗ        #   (input % 7 % 2)
+     #   +
\$ḅ      #   (input == 1)
# )
# Implicit output