Created
July 13, 2012 20:38
-
-
Save xsawyerx/3107320 to your computer and use it in GitHub Desktop.
Finding Friday the 13th
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use DateTime; | |
| my $dt = DateTime->new( | |
| day => 13, | |
| year => 2012, | |
| ); | |
| my $count = 0; | |
| while ( my $next_dt = $dt->add( months => 1 ) ) { | |
| if ( $next_dt->day_name eq 'Friday' ) { | |
| my $date = $next_dt->dmy('/'); | |
| print "Friday the 13th on: $date\n"; | |
| } | |
| # stop after 5 years | |
| $count++ == ( 12 * 5 ) and last; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use DateTime; | |
| foreach my $year ( 2012 .. 2020 ) { | |
| foreach my $month ( 1 .. 12 ) { | |
| my $dt = DateTime->new( | |
| day => 13, month => $month, year => $year | |
| ); | |
| if ( $dt->day_name eq 'Friday' ) { | |
| print $dt->dmy('/'), "\n"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment