aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@frontrangerunner.com>2020-04-13 09:58:55 -0600
committerMark Anderson <mark@frontrangerunner.com>2020-04-13 09:58:55 -0600
commit6d461d96870ef7ac47bcbc651fd129df1f2a6f45 (patch)
tree74ab7b1a745a49126463e1c1d1a37b5b817ee75b
parent68bc79d6cd5d1532cc63b3e08d450c6a5cd6c110 (diff)
downloadperlweeklychallenge-club-6d461d96870ef7ac47bcbc651fd129df1f2a6f45.tar.gz
perlweeklychallenge-club-6d461d96870ef7ac47bcbc651fd129df1f2a6f45.tar.bz2
perlweeklychallenge-club-6d461d96870ef7ac47bcbc651fd129df1f2a6f45.zip
ch-1.pl and ch-1.p6
-rw-r--r--challenge-056/mark-anderson/perl/ch-1.pl19
-rw-r--r--challenge-056/mark-anderson/raku/ch-1.p614
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-056/mark-anderson/perl/ch-1.pl b/challenge-056/mark-anderson/perl/ch-1.pl
new file mode 100644
index 0000000000..046ca91960
--- /dev/null
+++ b/challenge-056/mark-anderson/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use Modern::Perl;
+use Algorithm::Combinatorics 'combinations';
+use List::Util 'all';
+
+# Usage: perl ch-1.pl @N $k
+# Example: perl ch-1.pl 2 7 9 2
+# Output: 2,1
+
+die "Usage: perl ch-1.pl \@N \$k" unless all { /\d/ } @ARGV;
+
+my $k = pop @ARGV;
+
+my $combo = combinations([keys @ARGV], 2);
+
+while (my $indices = $combo->next) {
+ my ($i, $j) = $indices->@*;
+ say "$j,$i" if $ARGV[$j] - $ARGV[$i] == $k;
+}
diff --git a/challenge-056/mark-anderson/raku/ch-1.p6 b/challenge-056/mark-anderson/raku/ch-1.p6
new file mode 100644
index 0000000000..0be5954ab5
--- /dev/null
+++ b/challenge-056/mark-anderson/raku/ch-1.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/env raku
+
+# Usage: perl ch-1.pl @N $k
+# Example: perl ch-1.pl 2 7 9 2
+# Output: 2,1
+
+sub MAIN(*@ARGV where @ARGV.all ~~ /\d/) {
+ my $k = @ARGV.pop;
+
+ for @ARGV.keys.combinations: 2 -> $list {
+ my ($i, $j) = $list;
+ say "$j,$i" if @ARGV[$j] - @ARGV[$i] == $k;
+ }
+}