aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-003/andrezgz/perl5/ch-1.pl17
-rw-r--r--challenge-003/andrezgz/perl5/ch-2.pl27
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-003/andrezgz/perl5/ch-1.pl b/challenge-003/andrezgz/perl5/ch-1.pl
new file mode 100644
index 0000000000..cec1731d72
--- /dev/null
+++ b/challenge-003/andrezgz/perl5/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-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. https://en.wikipedia.org/wiki/Regular_number
+
+use strict;
+
+my $last = shift || 20;
+
+foreach my $n ( 1 .. $last ) {
+ my $r = $n;
+ for (2,3,5) { $r /= $_ until ($r % $_) }
+ print $n.$/ if ($r == 1);
+}
diff --git a/challenge-003/andrezgz/perl5/ch-2.pl b/challenge-003/andrezgz/perl5/ch-2.pl
new file mode 100644
index 0000000000..3d9d8e208a
--- /dev/null
+++ b/challenge-003/andrezgz/perl5/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-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. https://en.wikipedia.org/wiki/Pascal%27s_triangle
+
+use strict;
+use warnings;
+
+my $rows = $ARGV[0] || 0;
+
+if ($rows < 3) {
+ print "The Pascal Triangle should have at least 3 rows\n";
+ $rows = 3;
+}
+
+my @row = (1);
+
+while ($rows) {
+ print join(' ',@row) .$/;
+ $rows--;
+ @row = map {$row[$_] += $row[$_+1]} 0..@row-2;
+ unshift @row, 1;
+ push @row, 1;
+}