SHARE
TWEET

Easter calculator, Italian

a guest Mar 26th, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env perl
  2.  
  3. my $year = shift(@ARGV);
  4. my $april = 'Aprile';
  5. my $march = 'Marzo';
  6.  
  7. print "Uso: easter.pl ANNO\n" if ($year < 1000);
  8. print "Calendario gregoriano: " . easter($year, 1) ."\n";
  9. print "Calendario giuliano:   " . easter($year, 0) ."\n";
  10.  
  11. sub easter {
  12.     my ($year, $gregorian) = @_;
  13.  
  14.     my $a = $year % 19;
  15.     my $b = $year % 4;
  16.     my $c = $year % 7;
  17.     my $M = 15;
  18.     my $N = 6;
  19.     if ($gregorian > 0) {
  20.         if    ($year > 1582 and $year <= 1699) { $M = 22; $N = 2; }
  21.         elsif ($year >= 1700 and $year <= 1799){ $M = 23; $N = 3; }
  22.         elsif ($year >= 1800 and $year <= 1899){ $M = 23; $N = 4; }
  23.         elsif ($year >= 1900 and $year <= 2099){ $M = 24; $N = 5; }
  24.         elsif ($year >= 2100 and $year <= 2199){ $M = 24; $N = 6; }
  25.         elsif ($year >= 2200 and $year <= 2299){ $M = 25; $N = 0; }
  26.         elsif ($year >= 2300 and $year <= 2399){ $M = 26; $N = 1; }
  27.         elsif ($year >= 2400 and $year <= 2499){ $M = 25; $N = 1; }
  28.         else { return "<anno fuori range (1582-2499)>"; }
  29.     }
  30.  
  31.     my $d = (19 * $a + $M) % 30;
  32.     my $e = (2*$b + 4*$c + 6*$d + $N) % 7;
  33.  
  34.     if ( ($d + $e) < 10) {
  35.         my $day = $d + $e + 22;
  36.         return "$day $march";
  37.     } else {
  38.         my $day = $d + $e - 9;
  39.         return "$day $april";
  40.     }
  41. }
RAW Paste Data
Top