aboutsummaryrefslogtreecommitdiff
path: root/challenge-003
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-25 20:07:40 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-26 00:06:54 +0000
commit3fa58628535d4041c7cc648c005080ca88f18c18 (patch)
tree336fe3cc14f518f05e871ab974cc86a09a2fd8f6 /challenge-003
parent3d3900a2f0f69c54a34683e4e1b5da007b4af9d9 (diff)
downloadperlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.gz
perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.bz2
perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.zip
Replace tabs by spaces so that indentation looks correct
Diffstat (limited to 'challenge-003')
-rw-r--r--challenge-003/paulo-custodio/perl/ch-1.pl36
-rw-r--r--challenge-003/paulo-custodio/perl/ch-2.pl34
-rw-r--r--challenge-003/paulo-custodio/test.pl8
3 files changed, 39 insertions, 39 deletions
diff --git a/challenge-003/paulo-custodio/perl/ch-1.pl b/challenge-003/paulo-custodio/perl/ch-1.pl
index d51b7115af..6301db9a04 100644
--- a/challenge-003/paulo-custodio/perl/ch-1.pl
+++ b/challenge-003/paulo-custodio/perl/ch-1.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Challenge 003
-#
+#
# Challenge #1
# Create a script to generate 5-smooth numbers, whose prime divisors are less or equal to 5. They are also called Hamming/Regular/Ugly numbers. For more information, please check this wikipedia.
@@ -10,28 +10,28 @@ use warnings;
use 5.030;
use List::Util 'min';
-# return an iterator to generate the sequence
+# return an iterator to generate the sequence
# the sequence is a merge of all multiples of 2, 3 and 5
sub hamming_gen {
- # sequences of hamming numbers 2*n, 3*n, 5*n
- my @seq = ([1], [1], [1]);
- my @base = (2, 3, 5);
-
- return sub {
- # get the smallest of the multiples
- my $n = min($seq[0][0], $seq[1][0], $seq[2][0]);
- for my $i (0..2) {
- # shift used multiples
- shift @{$seq[$i]} if $seq[$i][0] == $n;
- # push next multiple
- push @{$seq[$i]}, $n*$base[$i];
- }
- return $n;
- }
+ # sequences of hamming numbers 2*n, 3*n, 5*n
+ my @seq = ([1], [1], [1]);
+ my @base = (2, 3, 5);
+
+ return sub {
+ # get the smallest of the multiples
+ my $n = min($seq[0][0], $seq[1][0], $seq[2][0]);
+ for my $i (0..2) {
+ # shift used multiples
+ shift @{$seq[$i]} if $seq[$i][0] == $n;
+ # push next multiple
+ push @{$seq[$i]}, $n*$base[$i];
+ }
+ return $n;
+ }
}
my($n) = @ARGV;
my $hamming = hamming_gen();
for (1 .. $n) {
- say $hamming->();
+ say $hamming->();
}
diff --git a/challenge-003/paulo-custodio/perl/ch-2.pl b/challenge-003/paulo-custodio/perl/ch-2.pl
index 132a230e03..4612edcd09 100644
--- a/challenge-003/paulo-custodio/perl/ch-2.pl
+++ b/challenge-003/paulo-custodio/perl/ch-2.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Challenge 003
-#
+#
# Challenge #2
# Create a script that generates Pascal Triangle. Accept number of rows from the command line. The Pascal Triangle should have at least 3 rows. For more information about Pascal Triangle, check this wikipedia page.
@@ -14,21 +14,21 @@ my($rows) = @ARGV;
draw_pascal($rows);
sub draw_pascal {
- my($rows) = @_;
- my @row = (1);
- say " " x $rows, "@row";
- for my $row (1 .. $rows-1) {
- # compute next row
- my @next = (1);
- for my $i (0 .. $#row-1) {
- push @next, $row[$i]+$row[$i+1];
- }
- push @next, 1;
- @row = @next;
-
- say " " x ($rows-$row), "@row";
- }
+ my($rows) = @_;
+ my @row = (1);
+ say " " x $rows, "@row";
+ for my $row (1 .. $rows-1) {
+ # compute next row
+ my @next = (1);
+ for my $i (0 .. $#row-1) {
+ push @next, $row[$i]+$row[$i+1];
+ }
+ push @next, 1;
+ @row = @next;
+
+ say " " x ($rows-$row), "@row";
+ }
}
-
- \ No newline at end of file
+
+
diff --git a/challenge-003/paulo-custodio/test.pl b/challenge-003/paulo-custodio/test.pl
index 8c00c3b3c1..9dea6b866c 100644
--- a/challenge-003/paulo-custodio/test.pl
+++ b/challenge-003/paulo-custodio/test.pl
@@ -45,8 +45,8 @@ END
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;
}