aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-123/dave-jacoby/blog2.txt1
-rw-r--r--challenge-123/dave-jacoby/perl/ch-1.pl22
2 files changed, 14 insertions, 9 deletions
diff --git a/challenge-123/dave-jacoby/blog2.txt b/challenge-123/dave-jacoby/blog2.txt
new file mode 100644
index 0000000000..29cd3c9ddb
--- /dev/null
+++ b/challenge-123/dave-jacoby/blog2.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2021/07/28/as-richard-thompson-sang-i-misunderstood.html \ No newline at end of file
diff --git a/challenge-123/dave-jacoby/perl/ch-1.pl b/challenge-123/dave-jacoby/perl/ch-1.pl
index 5b61a4aadc..4707fbb6c5 100644
--- a/challenge-123/dave-jacoby/perl/ch-1.pl
+++ b/challenge-123/dave-jacoby/perl/ch-1.pl
@@ -15,20 +15,24 @@ GetOptions( 'n=i' => \$n, );
carp 'Bad Input' unless $n > 0;
my $u = get_ugly($n);
-say "Input: \$n = $n";
-say "Output: $u";
+say "Input: \$n = $n Output: $u";
sub get_ugly ( $n ) {
- return 1 if $n == 1;
- my $c = 1;
+ my $c = 0;
my $u = 0;
while (1) {
$u++;
- my $f = 0;
- $f = 1 if $u % 2 == 0;
- $f = 1 if $u % 3 == 0;
- $f = 1 if $u % 5 == 0;
- $c++ if $f;
+ my $f = is_ugly($u) ? 1 : 0;
+ $c++ if $f;
return $u if $n == $c;
}
}
+
+sub is_ugly( $n ) {
+ for my $i ( 2, 3, 5 ) {
+ while ( $n % $i == 0 ) {
+ $n /= $i;
+ }
+ }
+ return $n == 1 ? 1 : 0;
+}