diff options
| author | David Ferrone <zapwai@gmail.com> | 2025-06-16 12:29:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-16 12:29:34 -0400 |
| commit | f4686f0610b73acf50534fc0e141da4bc1d2c595 (patch) | |
| tree | 90176ea659c2c71d61b2ca54757a93beba9ae5ed | |
| parent | 26cfae99bb0a2fdf9710bcc51e8abc8d7ed627f6 (diff) | |
| download | perlweeklychallenge-club-f4686f0610b73acf50534fc0e141da4bc1d2c595.tar.gz perlweeklychallenge-club-f4686f0610b73acf50534fc0e141da4bc1d2c595.tar.bz2 perlweeklychallenge-club-f4686f0610b73acf50534fc0e141da4bc1d2c595.zip | |
Week 326
| -rw-r--r-- | challenge-326/zapwai/perl/ch-1.pl | 42 | ||||
| -rw-r--r-- | challenge-326/zapwai/perl/ch-2.pl | 27 |
2 files changed, 69 insertions, 0 deletions
diff --git a/challenge-326/zapwai/perl/ch-1.pl b/challenge-326/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..a6bd72882f --- /dev/null +++ b/challenge-326/zapwai/perl/ch-1.pl @@ -0,0 +1,42 @@ +use v5.38; + +sub is_leap($yr) { + if ($yr % 400 == 0) { + return 1; + } elsif ($yr % 100 == 0) { + return 0; + } elsif ($yr % 4 == 0) { + return 1; + } else { + return 0; + } +} + +sub tally_months($m, $month) { + my @m = @$m; + my $total = 0; + my $end = int($month) - 2; + for my $i (0 .. $end) { + $total += $m[$i]; + } + $total +} + +sub proc($date) { + say "Input: \$date = $date"; + my @m = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + my ($year, $month, $day) = split("-", $date); + $m[1]++ if (is_leap($year)); + my $cnt = int($day); + unless($month eq "01") { + $cnt += tally_months(\@m, $month); + } + say "Output: $cnt"; +} + +my $date = '2025-02-02'; +proc($date); +$date = '2025-04-10'; +proc($date); +$date = '2025-09-07'; +proc($date); diff --git a/challenge-326/zapwai/perl/ch-2.pl b/challenge-326/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..82a2226808 --- /dev/null +++ b/challenge-326/zapwai/perl/ch-2.pl @@ -0,0 +1,27 @@ +use v5.38; + +sub proc(@ints) { + say "Input: \@ints = @ints"; + my (@e, @o); + for my $i (0 .. $#ints) { + if ($i % 2 == 0) { + push @e, $ints[$i]; + } else { + push @o, $ints[$i]; + } + } + my @l; + for my $i (0 .. $#e) { + my $len = $e[$i]; + my $val = $o[$i]; + push @l, $val for (1 .. $len); + } + say "Output: @l"; +} + +my @ints = (1,3,2,4); +proc(@ints); +@ints = (1,1,2,2); +proc(@ints); +@ints = (3,1,3,2); +proc(@ints); |
