aboutsummaryrefslogtreecommitdiff
path: root/challenge-019
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-25 20:07:40 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-25 20:07:40 +0000
commitc402c40f216b437ab1aba13793d493eb25cbfd14 (patch)
tree957f61c2428b4dc71ff703b10fecc17700824d0b /challenge-019
parentfcad77840d011bba81e63bb4b76adfdcf06fc96f (diff)
downloadperlweeklychallenge-club-c402c40f216b437ab1aba13793d493eb25cbfd14.tar.gz
perlweeklychallenge-club-c402c40f216b437ab1aba13793d493eb25cbfd14.tar.bz2
perlweeklychallenge-club-c402c40f216b437ab1aba13793d493eb25cbfd14.zip
Replace tabs by spaces so that indentation looks correct
Diffstat (limited to 'challenge-019')
-rw-r--r--challenge-019/paulo-custodio/perl/ch-1.pl40
-rw-r--r--challenge-019/paulo-custodio/perl/ch-2.pl38
-rw-r--r--challenge-019/paulo-custodio/test.pl12
3 files changed, 45 insertions, 45 deletions
diff --git a/challenge-019/paulo-custodio/perl/ch-1.pl b/challenge-019/paulo-custodio/perl/ch-1.pl
index e522f7b624..c1efb08557 100644
--- a/challenge-019/paulo-custodio/perl/ch-1.pl
+++ b/challenge-019/paulo-custodio/perl/ch-1.pl
@@ -3,7 +3,7 @@
# Challenge 019
#
# Task #1
-# Write a script to display months from the year 1900 to 2019 where you find
+# Write a script to display months from the year 1900 to 2019 where you find
# 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.
#
# Solution: 4 weeks are 28 days, to have 5 week-ends we need additional 3 days (29,30,31),
@@ -15,40 +15,40 @@ use 5.030;
use constant Sunday => 7;
sub is_leap {
- my($year) = @_;
- return ((($year % 4)==0 && ($year % 100)!=0) || ($year % 400)==0) ? 1 : 0;
+ my($year) = @_;
+ return ((($year % 4)==0 && ($year % 100)!=0) || ($year % 400)==0) ? 1 : 0;
}
sub days_in_month {
- my($year, $month) = @_;
- my @dom = (31, 28+is_leap($year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
- return $dom[$month-1];
+ my($year, $month) = @_;
+ my @dom = (31, 28+is_leap($year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+ return $dom[$month-1];
}
sub day_of_year {
- my($year, $month, $day) = @_;
- my $dayno = $day;
- $dayno += days_in_month($year, $_) for (1 .. $month-1);
- return $dayno;
+ my($year, $month, $day) = @_;
+ my $dayno = $day;
+ $dayno += days_in_month($year, $_) for (1 .. $month-1);
+ return $dayno;
}
# return 1..7 <=> Monday..Sunday
sub day_of_week {
- my($year, $month, $day) = @_;
- my $dayno = day_of_year($year, $month, $day);
- my $wdnog = ($dayno + $year + int(($year-1)/4) - int(($year-1)/100)
- + int(($year-1)/400) - 2) % 7 + 1;
- return $wdnog;
+ my($year, $month, $day) = @_;
+ my $dayno = day_of_year($year, $month, $day);
+ my $wdnog = ($dayno + $year + int(($year-1)/4) - int(($year-1)/100)
+ + int(($year-1)/400) - 2) % 7 + 1;
+ return $wdnog;
}
for my $year (1900 .. 2019) {
- for my $month (1 .. 12) {
- say sprintf("%04d-%02d", $year, $month) if five_weekends($year, $month);
- }
+ for my $month (1 .. 12) {
+ say sprintf("%04d-%02d", $year, $month) if five_weekends($year, $month);
+ }
}
sub five_weekends {
- my($year, $month) = @_;
- return days_in_month($year, $month)==31 && day_of_week($year, $month, 31)==Sunday;
+ my($year, $month) = @_;
+ return days_in_month($year, $month)==31 && day_of_week($year, $month, 31)==Sunday;
}
diff --git a/challenge-019/paulo-custodio/perl/ch-2.pl b/challenge-019/paulo-custodio/perl/ch-2.pl
index ab0adf688d..0c9cc1ecc3 100644
--- a/challenge-019/paulo-custodio/perl/ch-2.pl
+++ b/challenge-019/paulo-custodio/perl/ch-2.pl
@@ -11,28 +11,28 @@ use 5.030;
my $text = "";
while (<>) {
- $text .= $_;
+ $text .= $_;
}
print wrap($text, 72);
sub wrap {
- my($text, $column) = @_;
- $column ||= 72;
-
- my $output = "";
- my $sep = "";
- my $pos = 0;
- for my $word (split(' ', $text)) {
- if ($pos + length($sep) + length($word) >= $column) {
- $output .= "\n";
- $sep = "";
- $pos = 0;
- }
- $output .= $sep . $word;
- $pos += length($sep) + length($word);
- $sep = " ";
- }
- $output .= "\n";
- return $output;
+ my($text, $column) = @_;
+ $column ||= 72;
+
+ my $output = "";
+ my $sep = "";
+ my $pos = 0;
+ for my $word (split(' ', $text)) {
+ if ($pos + length($sep) + length($word) >= $column) {
+ $output .= "\n";
+ $sep = "";
+ $pos = 0;
+ }
+ $output .= $sep . $word;
+ $pos += length($sep) + length($word);
+ $sep = " ";
+ }
+ $output .= "\n";
+ return $output;
}
diff --git a/challenge-019/paulo-custodio/test.pl b/challenge-019/paulo-custodio/test.pl
index 468b65a361..16841dbd77 100644
--- a/challenge-019/paulo-custodio/test.pl
+++ b/challenge-019/paulo-custodio/test.pl
@@ -129,10 +129,10 @@ is capture("perl perl/ch-1.pl"), <<END;
END
path("input.txt")->spew(<<END);
-In the beginning God created the heavens and the earth. Now the earth was formless and empty,
+In the beginning God created the heavens and the earth. Now the earth was formless and empty,
darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.
And God said, "Let there be light," and there was light. God saw that the light was good, and
-he separated the light from the darkness. God called the light "day," and the darkness he called "night."
+he separated the light from the darkness. God called the light "day," and the darkness he called "night."
And there was evening, and there was morning-the first day.
END
@@ -151,8 +151,8 @@ unlink "input.txt";
done_testing;
sub capture {
- my($cmd) = @_;
- my $out = `$cmd`;
- $out =~ s/[ \t\v\f\r]*\n/\n/g;
- return $out;
+ my($cmd) = @_;
+ my $out = `$cmd`;
+ $out =~ s/[ \t\v\f\r]*\n/\n/g;
+ return $out;
}