Days in indexed month

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

Luke Sawczak

Posted 2019-11-15T00:23:32.470

Reputation: 415

Answers

26

APL (Dyalog Unicode), 13 12 bytesSBCS

Anonymous tacit prefix function. 0-indexed. February is 29.

31-1∘=+2|7∘|

Try it online!

31- thirty-one minus…

1∘= the equal-to-one'ness…

  + plus…

   2| the two-mod of…

    7∘| the seven-mod'ness

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...

This solution implements the following mathematical pattern:

$$f(x)=31-[x=1]-\big((x\mod 7)\mod 2\big)$$

or

$$f(x)=31-x-\left[x=1\right]+7\left\lfloor\frac{x}7\right\rfloor+2\left\lfloor x-7\left\lfloor\frac{x}7\right\rfloor\over2\right\rfloor$$

Adám

Posted 2019-11-15T00:23:32.470

Reputation: 37 779

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

13

Poetic, 706 bytes

counting a day,one month<t-o>twelve
i got frustrated doing a list
i do say,o,i edited a list,a month&a day count
in twelve(in December)to one(January)i listed a day"s count,then the numeral months
and once i am ready,o,i think i got a number to say
a number,o,i know a count
o,i say i am thirty if one"s short
i am ready,o,i know a count is not a thirty if we switch it
a long,a short,a etc.i switch
i do think i want a count of Febr-u"ry=two n eight:a case of a month"s age as shorter than the others"s
a day"s a day,i reckon
i know,i am clever
o,a date"s count at min=a thirty-day,or affix a one,i think
i do start&i produce threes if ever i am thirty
P.S.note:i index by one,i receive any-format numbers

Try it online!

As noted in the final line of the program, this program takes months as 1-based indices, and can take both simple numbers and numbers with a leading 0. (How's that for code comments?)

In pseudocode, my approach was basically like this:

N = input(); // Poetic doesn't support native numerical input, only input as ASCII codes; I basically have to write myself a number input routine every time
DIGIT = 49 // ASCII value for "1"; I would set it to 3, but that would be slightly longer
if (N>7) N++; // this accounts for the July->August parity shift
if (N!=2) { // if not February...
    DIGIT += 2; // now it's "3"
    print(DIGIT); // output: "3"
    DIGIT -= 3; // and now it's "0"...
    if (N%2==1) THREE++; // ...unless N is odd
    print(DIGIT); // output: "30" if short month, "31" if long month
} else { // if February...
    DIGIT += 1; // now it's "2"
    print(DIGIT); // output: "2"
    DIGIT += 6; // now it's "8"
    print(DIGIT); // output: "28"
}

JosiahRyanW

Posted 2019-11-15T00:23:32.470

Reputation: 2 600

Is there a reason why you used " instead of '? – None – 2019-11-15T10:46:44.063

@A_ Apostrophes are "closed off" in Poetic; for example, can't is a 4-letter word. As far as code golf goes, apostrophes are entirely useless. (I'd have used the Unicode right-quotation-mark, but that's more than one byte.) – JosiahRyanW – 2019-11-15T11:27:30.060

@A_ Basically, apostrophes are deleted, non-letter characters (defined as a character that returns false for the is_alpha() function in Python, or equivalently that doesn't match the newfangled \p{L} regex) are replaced with whitespace, and then the whole program is split on whitespace and its word-lengths are counted and turned into program instructions. – JosiahRyanW – 2019-11-15T11:35:23.950

12

Pyke, 4 bytes

~%R@

I have no idea how does this work (actually, after reading the source, I think I do, but Pyke seems extremely weird to me) as I simply used the second half of the Pyke answer by @Blue in the related question OP linked to. Try it online!

my pronoun is monicareinstate

Posted 2019-11-15T00:23:32.470

Reputation: 3 111

4

For anyone else wondering what this does and don't know Pyke (like me): here are the Pyke docs and this code will: ~% push the builtin list ['Padding', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; R rotate the values on the stack (at least 2) - so with only a single value on the stack it takes the input implicitly and acts like a swap (Q -get input- instead of R would be more a more intuitive alternative); @ index this input into the list; (and output the result implicitly with trailing newline). PS: 0-based input with ~MQ@ is also possible.

– Kevin Cruijssen – 2019-11-15T12:36:08.403

Thank you for notifying me Pyke has docs! :) – my pronoun is monicareinstate – 2019-11-15T12:39:37.240

Took me a bit to find as well, haha. ;) On the github page it links to "me saying how great the language is", where it at the bottom links to "This documentation can be found in pure html form here." Not sure why this html docs aren't in the github README or Wiki page tbh..

– Kevin Cruijssen – 2019-11-15T12:42:01.017

9

C (gcc), 27 bytes

0-indexed.

Instead of indexing into a string, I get the day offset (from 28) for the month from a packed bit array. Luckily all the offsets fit in a two-bit representation, so the bit array fits in an integer: I just shift and mask the offset and add 28.

f(m){m=0xEEFBB3>>m*2&3|28;}

Try it online!

ErikF

Posted 2019-11-15T00:23:32.470

Reputation: 2 149

Are you sure this is shorter than indexing into a string though? – my pronoun is monicareinstate – 2019-11-15T11:56:52.933

2@someone No, it's not. It's more fun though. It probably would be if there were more than 12 months in a year, however! :-) – ErikF – 2019-11-15T15:37:09.007

8

JavaScript (ES6), 16 bytes

All solutions expect a 0-indexed input and output 29 days for February.

Using a decimal modulo.

n=>n%1.7+!~-n^31

Try it online!


Using a single integer modulo.

n=>30-!~-n|n%7^1

Try it online!


Same approach as Adám with 2 integer modulos.

n=>31-n%7%2-!~-n

Try it online!

Arnauld

Posted 2019-11-15T00:23:32.470

Reputation: 111 334

8

Gaia, 3 bytes

∂k=

Yep, there's a built-in.

Try it online!

∂k   List containing days in each month
  =  Index into it (implicit input)

Business Cat

Posted 2019-11-15T00:23:32.470

Reputation: 8 927

6

x86 Machine Code, 14 bytes

B8 B3 FB EE 00
01 C9
D3 E8
24 03
04 1C
C3

This is a straight port of ErikF's C answer. The above bytes define a function that accepts a zero-indexed month (in the ECX register), and outputs the number of days (in the AL register, the lower-order bytes of the EAX register). The result is calculated by adding 28 to a fix-up parameter obtained from a sequenced vector of 2-bit values.

B8 B3 FB EE 00   mov    eax, 0x00EEFBB3    ; load bit vector into EAX
01 C9            add    ecx, ecx           ; \ index into the bit vector
D3 E8            shr    eax, cl            ; |   by shifting it right
24 03            and    al,  3             ; /   and keeping only the lowest 2 bits
04 1C            add    al,  28            ; add 28
C3               ret

Try it online!

Note that we can do the AND and ADD on byte-sized operands, which results in 2-byte instructions, rather than the 3-byte instructions required to operate on double-words.

The big bloat here is that initial 32-bit MOV instruction required to load the bit vector, but this implementation is still significantly smaller than a solution implementing the mathematical algorithm cited by Adam: (31 - ((month % 7) % 2) - (month == 1)).

Cody Gray

Posted 2019-11-15T00:23:32.470

Reputation: 2 639

5

05AB1E, 9 bytes

7%É31αsΘ-

Same formula as @Adám's APL (Dyalog Unicode) answer, which I've also partially used in this earlier answer of mine.

Try it online.

Explanation:

7%         # Take the (implicit) input-integer modulo-7
  É        # Check whether it is odd (short for modulo-2)
   31α     # Take the absolute difference with 31
      s    # Swap to take the (implicit) input-integer again
       Θ   # 05AB1E truthify; 1 if n==1; 0 otherwise
        -  # And subtract this from the earlier number
           # (after which the result is output implicitly)

Kevin Cruijssen

Posted 2019-11-15T00:23:32.470

Reputation: 67 575

5

Turing Machine Code, 197 bytes

0 0 _ * j
0 1 _ r F
0 2 _ * j
0 3 2 * F
0 4 _ * j
0 5 2 * F
0 6 _ * j
0 7 _ * j
0 8 2 * F
0 9 _ * j
h * * * halt
j _ 3 r ǰ
ǰ _ 1 * h
F _ 2 r Ƒ
Ƒ _ 8 * h
F 0 2 * F
F 1 _ r j
N _ 0 * h
F 2 3 r N

Try it online!

ouflak

Posted 2019-11-15T00:23:32.470

Reputation: 925

4

Python 3, 58 45 bytes

lambda x:'312831303130313130313031'[x*2:][:2]

Try it online!

  • A weak solution to get it started with an "unanalyzed" solution space

  • Saved a few bytes by functionizing thanks to Jo King

Luke Sawczak

Posted 2019-11-15T00:23:32.470

Reputation: 415

2

This can quickly be improved to 37 bytes with unprintables, or 28 bytes as a function

– Jo King – 2019-11-15T00:39:15.883

1@JoKing Good call. The unprintables I think is inventive enough that you can post it as a separate answer if you want, but I've functionized. – Luke Sawczak – 2019-11-15T01:24:10.357

4

PHP, 31 bytes

<?=date(t,mktime(0,0,0,$argn));

Try it online!

Just using builtins really. Input month via STDIN, 1-indexed.

640KB

Posted 2019-11-15T00:23:32.470

Reputation: 7 149

4

Embodiment of Ignorance

Posted 2019-11-15T00:23:32.470

Reputation: 7 014

I think a string of unprintables is shorter. – my pronoun is monicareinstate – 2019-11-15T04:20:37.653

8What is this sorcery – Innat3 – 2019-11-15T10:11:08.127

@Innat3: indexing a string where the "characters" are small integers, below ASCII 32 = space. – Peter Cordes – 2019-11-18T02:21:18.033

4

Python 3, 24 bytes

lambda n:31-n%7%2-(n==1)

Try it online!

Adaptation of Adám's APL answer


Original answer:

Python 3, 29 bytes

lambda n:31^n%2^n//7^2*(n==1)

Try it online!

Jitse

Posted 2019-11-15T00:23:32.470

Reputation: 3 566

4

Retina, 29 28 bytes

^o$
x
o{7}|oo

^
31*
__x|_o

Explanation:

^o$      match input equal to "o"
x        replace it with x
o{7}|oo  match 7 or 2 "o"s, whichever the regex engine prefers
         replace them with nothing (this happens to compute a%7%2)
^        match the beginning of string
31*      and replace it with 31 times the default character (_)
__x|_o   match __x or _o literally
         and erase them (that is, "x" means "erase two _" and "o" means "erase one _")

Try it online!

my pronoun is monicareinstate

Posted 2019-11-15T00:23:32.470

Reputation: 3 111

You can remove the } to save a byte (relevant part of the docs EDIT: or maybe not, seems like an undocumented feature).

– Kevin Cruijssen – 2019-11-15T13:40:18.293

@Kevin Thanks, though I'm pretty sure that section refers to groupings when substituting, not the patterns themselves, so this is probably a different feature. – my pronoun is monicareinstate – 2019-11-15T13:42:22.107

Hmm good point.. I just noticed it works without the closing bracket, and was looking for the relevant docs. Maybe it's undocumented/hidden. :) – Kevin Cruijssen – 2019-11-15T13:43:53.367

For some reason it also doesn't seem to work with normal human circular () parentheses. Maybe that's a .NET regex "feature"? – my pronoun is monicareinstate – 2019-11-15T13:44:53.070

No, it doesn't seem to work in .NET C#. Ah well.. PS: You forgot to update your byte-count in the title.

– Kevin Cruijssen – 2019-11-15T13:50:34.223

The change Kevin suggested doesn't appear to produce the correct output. I believe it is trying to match a literal { in that case. However, you can save a byte by doing o{7}|oo instead of two replacements. – FryAmTheEggman – 2019-11-15T15:19:30.780

Huh; I'm not sure why haven't I tried that (for some reason I assumed it is likely to produce incorrect results, but haven't actually tried it). – my pronoun is monicareinstate – 2019-11-15T15:22:57.427

3

Red, 46 bytes

func[m][b:(a: to now[1 m 1])+ 31 b/4: 1 b - a]

Try it online!

A verbose solution that literally calculates the number of days in the given month (28 for february - year 1 AD)

Explanation:

Red[]
f: func[m][
    a: to now [1 m 1]   ; make a date dd-mm-yyyy (1st of the "month" year 1 AD)
    b: a + 31           ; add 31 days to it
    b/4: 1              ; and go back to the 1st day of the new month
    b - a               ; subtract the initial date from the new one 
]

Galen Ivanov

Posted 2019-11-15T00:23:32.470

Reputation: 13 815

3

Python 2, 42 39 35 bytes

lambda i:(30+(i%2==(i<8)),28)[i==2]

Try it online!

Not the shortest Python solution but an alternative approach (1 indexed).

Shorter but not very interesting:

Python 2, 34 bytes

lambda i:int("303232332323"[i])+28

Try it online!

ElPedro

Posted 2019-11-15T00:23:32.470

Reputation: 5 301

3

As suggested by @Xcali it can be even shorter:

Perl 5, 35 bytes

$_=substr"3128".3130313031x2,$_*2,2

Try it online!

As suggested by @manatwork this can be shortened substantial:

Perl 5, 39 bytes

("3128".3130313031x2)=~/(..){$_}/;$_=$1

Try it online!

Perl (And because I like regex, a first humble attempt):

Perl 5, 60 bytes

print $1 if "312831303130313130313031" =~ /(..){$ARGV[0]}/g;

Try it online!

Invoke via perl -e and user supplied input, e.g. 2 for the month, at command line argument with index 0.

stephanmg

Posted 2019-11-15T00:23:32.470

Reputation: 261

1

>

  • None of the spaces are needed. 2) Is shorter without if: just do the pattern matching then print in separate statements. 3) Is shorter to get the month number as input. 4) If taking input, is shorter to automate it using -p switch. 5) No need for the g modifier. Try it online!
  • – manatwork – 2019-11-15T11:26:43.083

    That's a substantial truncation. – stephanmg – 2019-11-15T11:28:23.747

    1A bit shorter if you repeat the common part of the string: ("3128".3130313031x2). – manatwork – 2019-11-15T11:33:20.257

    1

    Even shorter if you use substr and 0-index: Try it online!

    – Xcali – 2019-11-15T17:11:52.207

    Thanks @Xcali I incorporated the changes. – stephanmg – 2019-11-15T17:14:01.953

    3

    Haskell, 37 bytes

    Not in any way clever, but there you go. Pretty much checks all the non-31-day months and if it isn't any of them it falls back on 31.

    f 2=28;f m|elem m[4,6,9,11]=30;f _=31
    

    Try it online!

    Andrew Ray

    Posted 2019-11-15T00:23:32.470

    Reputation: 101

    27 bytes, with 0-indexing – Unrelated String – 2019-11-15T23:34:14.940

    1@UnrelatedString, go ahead and post as your own answer if you want. I think it's less a revision of my answer than a completely new one. – Andrew Ray – 2019-11-18T13:41:48.723

    3

    Excel, 29 bytes

    =DAY(EOMONTH(DATE(0,B1,1),0))
    

    Where B1 is the month number (1-based).

    atlasologist

    Posted 2019-11-15T00:23:32.470

    Reputation: 2 945

    Porting @Adam's formula is shorter at 27 bytes: =31-(A1=1)-MOD(MOD(A1,7),2) – Wernisch – 2019-11-20T13:22:32.223

    3

    z80 Machine Code, 13 bytes

    47 1F 1F 1F A8 E6 01 05 10 01 3D C6 30
    

    Takes input (starting at 1) in the A register and stores output in the same register. This was manually assembled from the ez80 manual and is not yet tested, therefore it might contain some mistakes.

    Explanation:

    47        ld b, a         ; Copy the value to the B register
    1F 1F 1F  rra   (3 times) ; \ Set A to ((A >> 3) ^ B) & 1, which is
    A8        xor a, b        ; | equal to 1 on all months with 31 days
    E6 01     and a, 1        ; / 
    05        dec b           ; \ Decrement the B register twice and skip the next instruction if 
    10 01     djnz $+3        ; / the resulting value is not zero (if the month is not february)
    3D        dec a           ; Decrement A (if february)
    C6 30     add a, 30       ; Add 30 to A
    

    Herman L

    Posted 2019-11-15T00:23:32.470

    Reputation: 3 611

    3

    C++ (g++), 60 54 47 40 bytes

    1-indexed. f(2)==29.

    int f(int n){return(n^n/8)%2-(n==2)+30;}
    

    Solution from k-map, which simplified to A=w+x+z and B=zw'+z'w. A was negated and became a subtraction.

    int f(int n){      //N is a 4-digit binary number wxyz.
    return (n^n/8) %2  //Add 1 if (w XOR z)
         - (n==2)      //Subtract 1 if !(w OR x OR z), which simplifies to (w'x'z'),
                       //which is only satisfied when N is 0000 or 0010.
                       //Since n is never 0, this condition is only satisfied when n==2.
         + 30;         //Add 30, the base month length.
    }
    

    At first I tried adding 1 or 2 instead of 1 or 1, but my solution was 87 bytes (if I remember correctly). I tried that with 0-indexing and 1-indexing, but they ended up being the exact same length.

    47 bytes: int f(int n){return(n/8|n/4|n)%2+(n^n/8)%2+29;}

    54 bytes: int f(int n){return((n>>3|n>>2|n)&1)+((n^n>>3)&1)+29;}

    60 bytes: int f(int n){return(n>>3&1|n>>2&1|n&1)+((n&1)^(n>>3&1))+29;}

    Edit: Thanks to Herman L. for the improvement to 54 bytes, I'm glad someone found my approach interesting even though it's clearly not the shortest!

    Edit 2: Thank you to ceilingcat for the improvement to 47 bytes. This uses division instead of bit shifting, which saves one byte in each of three places. It also replaces &1 with %2 in two places. Both of these functionally return the last byte of the integer, but the modulo operator has precedence over addition. This means that two pairs of parentheses can be removed, saving four bytes. In total, by mixing arithmetic and bitwise operators, ceilingcat managed to improve the answer by seven bytes!

    Edit 3: Another improvement by ceilingcat brings it down six bytes by doing bitwise comparison with 13, -!(n&13). Since this is only true in one case, simplified to an equality check.

    radeklew

    Posted 2019-11-15T00:23:32.470

    Reputation: 31

    Welcome to CG&CC! – Herman L – 2019-11-17T08:08:47.280

    1A few bytes can be saved by reordering the operators: int f(int n){return((n>>3|n>>2|n)&1)+((n^n>>3)&1)+29;} – Herman L – 2019-11-17T08:13:37.403

    @HermanL Thank you, it looks so obvious now that you point that out! I guess I need more practice with bitwise operators. – radeklew – 2019-11-17T19:45:38.057

    @ceilingcat Great idea! I wouldn't have thought to use /, since I was focussed on bitwise operators. – radeklew – 2019-11-30T04:58:50.847

    @ceilingcat Nice! Got it down to 40 and updated the answer. Good idea with the subtraction. – radeklew – 2019-12-02T03:06:19.687

    2

    Keg, -rr, 17 16 14 13 bytes

    $:&1=-&7%2%-
    

    Try it online!

    Simply a port of Adams APL answer.

    Lyxal

    Posted 2019-11-15T00:23:32.470

    Reputation: 5 253

    2

    Ruby, 18 bytes

    ->n{31-n%7%2-2[n]}
    

    Try it online!

    0-based, basically the same formula as Adam, adapted to ruby.

    G B

    Posted 2019-11-15T00:23:32.470

    Reputation: 11 099

    2

    Jelly, 10 bytes

    %7Ḃ31__1⁼$
    

    Try it online!

    Pretty much just a translation of Adám and Kevin Cruijssen's APL and 05ab1e answers, respectively. There's probably some way I could cut out the $.

    Unrelated String

    Posted 2019-11-15T00:23:32.470

    Reputation: 5 300

    2

    Pyth, 10 8 bytes

    0-indexed, February is 29.

    C@.""
    

    Try it online! TIO doesn't seem to like the UTF-8 conjoined character, but it works in the official interpreter. Consider TIO a glorified pastebin for this.

    Previous version, 10 bytes:

    C@."Îï»
    

    Try it online!

    famous1622

    Posted 2019-11-15T00:23:32.470

    Reputation: 451

    2

    J, 19 bytes

    (31-0 2 0,#:330){~]
    

    For fun, here's a J translation of Adam's APL answer (also 12 bytes):

    31-1&=+2|7&|
    

    Jonah's comment saves another 4 bytes, due to:

    1. better use of J's hook: ({...) instead of (...{~])
    2. better choice of starting binary values, adjusting the arithmetic as necessary (30+1 _1,... rather than 31-0 2 0,...):
    | expr    | result               |
    |---------|----------------------|
    | 0,#:330 | 0 1 0 1 0 0 1 0 1 0  |
    | #:693   | 1 0 1 0 1 1 0 1 0 1  |
    

    Try it online!

    hoosierEE

    Posted 2019-11-15T00:23:32.470

    Reputation: 760

    1

    I came up with a similar 15 byte approach ({30+1 _1,#:@693), but it can still be beaten by translating Adam's solution directly into J.

    – Jonah – 2019-11-15T21:11:34.417

    Nice. I tried to translate Adam's to J but failed to make it shorter, probably because I don't quite grok APL yet. – hoosierEE – 2019-11-17T17:50:59.483

    1Aha, got it: 31-1&=+2|7&| Thanks! – hoosierEE – 2019-11-17T17:56:17.480

    That's the one. Nice! – Jonah – 2019-11-17T17:57:51.080

    2

    T-SQL 61 bytes

    declare @ int set @=2print DAY(EOMONTH(DATEFROMPARTS(1,@,1)))
    

    40 bytes if we put the input directly to the query:

    print DAY(EOMONTH(DATEFROMPARTS(1,2,1)))
    

    JuanCa

    Posted 2019-11-15T00:23:32.470

    Reputation: 169

    1

    Pyth, 12 bytes

    --31%%Q7 2q1
    

    Try it online!

    Port of @Adám's answer

    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
    

    frank

    Posted 2019-11-15T00:23:32.470

    Reputation: 941

    1

    Wren, 27 bytes

    -3 bytes thx to Jo King for putting all into a tertiary statement.

    Fn.new{|x|1==x?28:31-x%7%2}
    

    Try it online!

    Wren, 35 bytes

    -4 bytes thx 2 Jo King for noticing that .bytes[x] would work.

    Fn.new{|x|" ".bytes[x]}
    

    Try it online!

    user85052

    Posted 2019-11-15T00:23:32.470

    Reputation:

    For the first, you can move it all into the ternary statment for 27 bytes

    – Jo King – 2019-11-15T09:13:10.283

    1

    C (gcc), 22 bytes

    f(n){n=31-n%7%2-!~-n;}
    

    Try it online!

    Stealing from @Arnaulds / @Adám


    29 26 bytes

    f(x){x=""[x];}
    

    Port of @Embodiment of Ignorance answer

    AZTECCO

    Posted 2019-11-15T00:23:32.470

    Reputation: 2 441

    1

    C# (Visual C# Compiler), 28 bytes

    x=>DateTime.DaysInMonth(1,x)
    

    Try it online!

    Joost K

    Posted 2019-11-15T00:23:32.470

    Reputation: 210

    This is exactly the old revision of Embodiment's C# answer: https://codegolf.stackexchange.com/posts/195901/revisions :(

    – my pronoun is monicareinstate – 2019-11-15T15:16:25.630

    Ohh, I didn't see it in the answers so I assumed no one had posted this yet – Joost K – 2019-11-15T15:17:26.400

    1

    Javascript, 23 bytes

    n=>15662007>>~-n*2&3|28
    

    This is utilizing a binary map 15662007 which is

    111011101111101110110111
    11.10.11.10.11.11.10.11.10.11.01.11
     3. 2. 3. 2. 3. 3. 2. 3. 2. 3. 1. 3
    

    You just add each item to 28 and see that it provides a proper mapping to each month.

    user3335941

    Posted 2019-11-15T00:23:32.470

    Reputation: 41

    0

    Haskell, 27 bytes

    f 1=28;f m=31-mod m 7`mod`2
    

    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.

    Unrelated String

    Posted 2019-11-15T00:23:32.470

    Reputation: 5 300

    0

    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.

    canttalkjustcode

    Posted 2019-11-15T00:23:32.470

    Reputation: 131