diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-10-10 14:59:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-10 14:59:54 +0100 |
| commit | 22566e43bfb9dc2f516422abdeeb8baf55829daf (patch) | |
| tree | cde9bfe54b593efc52c170aeb75df1d8fb9fd59a | |
| parent | 5a8e33b8bdb8c303981d4d0b7ef3a7e671ecdaf2 (diff) | |
| parent | 3836c2699de4c708b32fc6bd59770463cc00eeec (diff) | |
| download | perlweeklychallenge-club-22566e43bfb9dc2f516422abdeeb8baf55829daf.tar.gz perlweeklychallenge-club-22566e43bfb9dc2f516422abdeeb8baf55829daf.tar.bz2 perlweeklychallenge-club-22566e43bfb9dc2f516422abdeeb8baf55829daf.zip | |
Merge pull request #8844 from jacoby/master
DAJ 238
| -rw-r--r-- | challenge-238/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-238/dave-jacoby/perl/ch-1.pl | 28 | ||||
| -rw-r--r-- | challenge-238/dave-jacoby/perl/ch-2.pl | 43 |
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 +} |
