aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2023-10-09 17:41:11 -0400
committerDave Jacoby <jacoby.david@gmail.com>2023-10-09 17:41:11 -0400
commit7cccf2f51d1a1ad5027dcdf2fb9058cd7804808f (patch)
tree3ee5489d77ffb13e94aac2c29c38a719ca31f59f
parent5b5fa6ebff4fa4ad64963ad7432f7ebf8a18cab5 (diff)
downloadperlweeklychallenge-club-7cccf2f51d1a1ad5027dcdf2fb9058cd7804808f.tar.gz
perlweeklychallenge-club-7cccf2f51d1a1ad5027dcdf2fb9058cd7804808f.tar.bz2
perlweeklychallenge-club-7cccf2f51d1a1ad5027dcdf2fb9058cd7804808f.zip
DAJ 238
-rw-r--r--challenge-238/dave-jacoby/blog.txt1
-rw-r--r--challenge-238/dave-jacoby/perl/ch-1.pl28
-rw-r--r--challenge-238/dave-jacoby/perl/ch-2.pl43
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-238/dave-jacoby/blog.txt b/challenge-238/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..3c53d53a96
--- /dev/null
+++ b/challenge-238/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2023/10/09/you-cant.html
diff --git a/challenge-238/dave-jacoby/perl/ch-1.pl b/challenge-238/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..fb07484a53
--- /dev/null
+++ b/challenge-238/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+my @examples = (
+
+ [ 1, 2, 3, 4, 5 ],
+ [ 1, 1, 1, 1, 1 ],
+ [ 0, -1, 1, 2 ],
+);
+
+for my $e (@examples) {
+ my @output = running_sum( $e->@* );
+ my $input = join ', ', $e->@*;
+ my $output = join ', ', @output;
+ say <<~"END";
+ Input: \@int = ($input)
+ Output: ($output)
+ END
+}
+
+sub running_sum (@int) {
+ my $c = 0;
+ my @output = map { $c += $_; $c } @int;
+ return @output;
+}
diff --git a/challenge-238/dave-jacoby/perl/ch-2.pl b/challenge-238/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..8b47668fa9
--- /dev/null
+++ b/challenge-238/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use Algorithm::Permute;
+use List::Util qw{ product };
+
+my @examples = (
+
+ [ 15, 99, 1, 34 ],
+ [ 50, 25, 33, 22 ],
+);
+
+for my $e (@examples) {
+ my @int = $e->@*;
+ my $int = join ', ', @int;
+ my @output = persistence_sort(@int);
+ my $output = join ', ', @output;
+ say <<~"END";
+ Input: \@int = ($int)
+ Output: ($output)
+ END
+}
+
+sub persistence_sort (@nums) {
+ my @output =
+ map { $_->[0] }
+ sort { $a->[1] <=> $b->[1] }
+ map { [ $_, munge($_) ] } sort @nums;
+ return @output;
+}
+
+sub munge ($i) {
+ my $c = 0;
+ while (1) {
+ return $c if $i < 10;
+ $i = product split //, $i;
+ $c++;
+ }
+ return -1; # just in case
+}