aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2023-10-23 12:44:04 -0400
committerDave Jacoby <jacoby.david@gmail.com>2023-10-23 12:44:04 -0400
commitbc7ba222cd6a91bf181bc8c571ffa873f79a34af (patch)
treed3871a4bcf863c8f5a5d91f8d2a8263d4c4340e2
parent67310476fd1daa9d74365ca666f4f6d9a0932d50 (diff)
downloadperlweeklychallenge-club-bc7ba222cd6a91bf181bc8c571ffa873f79a34af.tar.gz
perlweeklychallenge-club-bc7ba222cd6a91bf181bc8c571ffa873f79a34af.tar.bz2
perlweeklychallenge-club-bc7ba222cd6a91bf181bc8c571ffa873f79a34af.zip
DAJ 240
-rw-r--r--challenge-240/dave-jacoby/perl/ch-1.pl28
-rw-r--r--challenge-240/dave-jacoby/perl/ch-2.pl36
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-240/dave-jacoby/perl/ch-1.pl b/challenge-240/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..a983dd259a
--- /dev/null
+++ b/challenge-240/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 = (
+
+ { str => [ "Perl", "Python", "Pascal" ], chk => "ppp", },
+ { str => [ "Perl", "Raku" ], chk => "rp", },
+ { str => [ "Oracle", "Awk", "C" ], chk => "oac", },
+);
+
+for my $e (@examples) {
+ my $output = acronym($e);
+ my $str = join ', ', map { qq{"$_"} } $e->{str}->@*;
+ my $chk = $e->{chk};
+ say <<~"END";
+ Input: \@str = ($str)
+ \$chk = "$chk"
+ Output: $output
+ END
+}
+
+sub acronym ($input) {
+ my $work = lc join '', map { substr $_, 0, 1 } $input->{str}->@*;
+ return $work eq $input->{chk} ? 'true' : 'false' ;
+}
diff --git a/challenge-240/dave-jacoby/perl/ch-2.pl b/challenge-240/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..5a31994e2b
--- /dev/null
+++ b/challenge-240/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use Algorithm::Permute;
+
+my @examples = (
+
+ [ 0, 2, 1, 5, 3, 4 ],
+ [ 5, 0, 1, 2, 3, 4 ],
+);
+for my $e (@examples) {
+ my @output = build_array( $e->@* );
+ my @input = $e->@*;
+ my $output = join ', ', @output;
+ my $input = join ', ', @input;
+ say <<~"END";
+ Input: \@int = ($input)
+ Output: ($output)
+ END
+}
+
+sub build_array (@int) {
+ my $len = -1 + scalar @int;
+ my @copy = @int;
+ my $p = Algorithm::Permute->new( \@copy );
+OUTER: while ( my @res = $p->next ) {
+ for my $i ( 0 .. $len ) {
+ next OUTER unless $res[$i] == $int[ $int[$i] ];
+ }
+ return @res;
+ }
+ return ();
+}