aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2020-12-14 18:51:26 -0500
committerDave Jacoby <jacoby.david@gmail.com>2020-12-14 18:51:26 -0500
commite108de310f13cb428d7657e1efedc8ad5f4ca150 (patch)
tree65a1736729a7b4c9fcac837e48ee89dca5148c84
parent3c0c4f283ed81e3cbeae88d75b0dbc80a8a081b8 (diff)
downloadperlweeklychallenge-club-e108de310f13cb428d7657e1efedc8ad5f4ca150.tar.gz
perlweeklychallenge-club-e108de310f13cb428d7657e1efedc8ad5f4ca150.tar.bz2
perlweeklychallenge-club-e108de310f13cb428d7657e1efedc8ad5f4ca150.zip
Challenge 91
-rw-r--r--challenge-091/dave-jacoby/blog.txt1
-rw-r--r--challenge-091/dave-jacoby/perl/ch-1.pl33
-rw-r--r--challenge-091/dave-jacoby/perl/ch-2.pl22
3 files changed, 56 insertions, 0 deletions
diff --git a/challenge-091/dave-jacoby/blog.txt b/challenge-091/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..da91abc05f
--- /dev/null
+++ b/challenge-091/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2020/12/14/perl-challenge-91-jumping-numbers-and-counting-numbers.html \ No newline at end of file
diff --git a/challenge-091/dave-jacoby/perl/ch-1.pl b/challenge-091/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..75178dd1fe
--- /dev/null
+++ b/challenge-091/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+my @examples = qw{1122234 2333445 12345 90125 };
+
+for my $example (@examples) {
+ my $output = count_number($example);
+ my $o2 = count_number2($example);
+ say ' input: ' . $example;
+ say ' output: ' . $output;
+ say 'output2: ' . $o2;
+ say '';
+}
+
+sub count_number( $input ) {
+ my $output = '';
+ for my $i ( 0 .. 9 ) {
+ my $x = () = $input =~ /($i)/gmx;
+ $output .= $x . $i if $x;
+ }
+ return $output;
+}
+
+sub count_number2( $input ) {
+ return join '', map {
+ my $x = () = $input =~ /($_)/g;
+ $x . $_; }
+ grep { $input =~ /$_/ } 0 .. 9;
+}
diff --git a/challenge-091/dave-jacoby/perl/ch-2.pl b/challenge-091/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..271c4345b1
--- /dev/null
+++ b/challenge-091/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+say jump_game( 1, 2, 1, 2 );
+say jump_game( 2, 1, 1, 0, 2 );
+say jump_game( 1, 9, 9, 2 );
+
+sub jump_game( @n ) {
+ say join ' ', ' ', @n;
+ my $i = 0;
+ while (1) {
+ if ( !defined $n[$i] ) { last }
+ if ( $n[$i] == 0 ) { last }
+ if ( defined $n[$i] && !defined $n[ $i + 1 ] ) { return 1 }
+ $i += $n[$i];
+ }
+ return 0;
+}