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

Re^2: Doomsday algorithm

by QM (Parson)
on Sep 07, 2015 at 14:55 UTC ( [id://1141262]=note: print w/replies, xml ) Need Help??


in reply to Re: Doomsday algorithm
in thread Doomsday algorithm

To prove your point, when(5) duplicates "sunday".

And you probably want something like:

@anchor_day_week = qw(tuesday wednesday thursday friday saturday sunda +y monday) [$year_anchor_day+1..6,0..$year_anchor_day];

...though I dislike repeating $year_anchor_day. This just changes the repetition:

push @anchor_day_week, splice @anchor_day_week, 0, $year_anchor_day;

...so a function to do this for you would be appropriate, even if it's only used once.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^3: Doomsday algorithm
by soonix (Canon) on Sep 07, 2015 at 15:19 UTC
    Yes, that's what I meant with "more elegant solution". The next step would be to further "normalize" that $nbdays such that Sunday is the usual 0 or 7 (like in strftime %u or %w) by calculating
    my $nbdays = ($diff_to_doomsdates + $year_anchor_day + 2) % 7; # or -5

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1141262]
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: (3)
As of 2024-04-20 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found