Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Doomsday algorithm

by QM (Parson)
on Sep 07, 2015 at 14:55 UTC ( #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; a function to do this for you would be appropriate, even if it's only used once.

Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^3: Doomsday algorithm
by soonix (Monsignor) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1141262]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-06-19 21:05 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (115 votes). Check out past polls.