q/kdb+, 36 bytes
Solution:
28 30 31@2^1&(*)"ebeprunov"ss(_)1_3#
Examples:
q)28 30 31@2^1&(*)"ebeprunov"ss(_)1_3#"January"
31
q)28 30 31@2^1&(*)"ebeprunov"ss(_)1_3#"FEB"
28
q)28 30 31@2^1&(*)"ebeprunov"ss(_)1_3#"jun"
30
Explanation:
There are a million ways to skin a cat. I think is slightly different to the others. Take the 2nd and 3rd letters of the input, lowercase them, then look them up in the string "ebeprunov"
. If they are at location 0, then this is February, if they are at a location >0 they are a 30-dayer, if they are not in the string, they are a 31-dayer.
28 30 31@2^1&first"ebeprunov"ss lower 1_3# / ungolfed solution
3# / take first 3 items from list, January => Jan
1_ / drop the first item from the list, Jan => an
lower / lower-case, an => an
"ebeprunov"ss / string-search in "ebeprunov", an => ,0N (enlisted null)
first / take the first, ,0N => 0N
1& / take max (&) with 1, 0N => 0N
2^ / fill nulls with 2, 0N => 2
@ / index into
28 30 31 / list 28,30,31
19You should probably list out all the variations of the month names that we should be able to accept. – Giuseppe – 2017-10-28T17:40:44.443
what do you mean by case insensitive? do you mean we have to accept any case and give the right answer? or do you mean we can specify whether the input must be given in upper or lower case (presumably consistently)? – Level River St – 2017-10-28T17:46:13.133
1For anybody who can use it, the ASCII ordinal sums of the first 3 characters lowered are unique. – totallyhuman – 2017-10-28T18:20:25.423
19That was far, far too soon to accept a solution. – Shaggy – 2017-10-28T19:28:08.153
5i think this would be nicer if input was just the month in a fixed format, as the format now basically requires converting to a fixed case and only looking at the first 3 letters. – xnor – 2017-10-28T21:04:13.510
4As it stands it looks like you want answers to handle all of the listed forms - "For example,
december
,DEC
, anddec
should all return 31" - Is that the intention? – Jonathan Allan – 2017-10-28T23:27:28.607