aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-149/dave-jacoby/blog1.txt1
-rw-r--r--challenge-149/dave-jacoby/perl/ch-1.pl39
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-149/dave-jacoby/blog1.txt b/challenge-149/dave-jacoby/blog1.txt
new file mode 100644
index 0000000000..0a39b52da7
--- /dev/null
+++ b/challenge-149/dave-jacoby/blog1.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2022/01/27/weekly-challenge-149-and-a-fix-maybe-to-148.html
diff --git a/challenge-149/dave-jacoby/perl/ch-1.pl b/challenge-149/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..3be997a486
--- /dev/null
+++ b/challenge-149/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental };
+
+use Getopt::Long;
+use List::Util qw{ sum0 max };
+
+my $N = 20;
+GetOptions( 'n=i' => \$N, );
+
+my @fib = first_60_fib();
+my %fib = map { $_ => 1 } @fib;
+my @x;
+
+my $n = 0;
+while ( scalar @x < $N ) {
+ my $sd = sum_of_digits($n);
+ my $f = $fib{$sd} || 0;
+ push @x, $n if $f;
+ $n++;
+}
+say join ' ', @x;
+
+sub first_60_fib() {
+ my @n;
+ push @n, 0;
+ push @n, 1;
+ while ( scalar @n < 60 ) {
+ push @n, $n[-1] + $n[-2];
+ }
+ return @n;
+}
+
+sub sum_of_digits ( $n ) {
+ return sum0 split //, $n;
+}