Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How do you remember the number of days in each month?

by wrog (Friar)
on Sep 18, 2014 at 00:36 UTC ( [id://1100985]=note: print w/replies, xml ) Need Help??


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.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1100985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found