in reply to How do you remember the number of days in each month?

30+(3+ (3*$_+3)%5 - (3*$_+1)%5)/5

works for March (3) through January (13).

Or to put it another way, you add 1 to the month and then multiply by 3 and if subtracting 2 from that crosses through a mod-5 boundary then you have a 30 day month, otherwise you have a 31 day month

So May (6*3=18 —→ 16) has 31, while June (21 —→ 19) has 30.

Yeah, that's how I remember this.

Replies are listed 'Best First'.
Re^2: How do you remember the number of days in each month?
by LanX (Saint) on Sep 18, 2014 at 13:40 UTC
    TIMTOWTDI! =)

    DB<105> print 30+($_+($_>7))%2 for 1..12 31 30 31 30 31 30 31 31 30 31 30 31 DB<106> print 30+($_+($_>7))%2-2*($_==2) for 1..12 31 28 31 30 31 30 31 31 30 31 30 31 DB<113> print ((30,31,28)[($_+($_>7))%2-($_==2)]) for 1..12 31 28 31 30 31 30 31 31 30 31 30 31 30 31

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re^2: How do you remember the number of days in each month?
by choroba (Cardinal) on Sep 18, 2014 at 08:21 UTC
    Interesting.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ