aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Hood <hood@panix.com>2020-11-23 21:06:48 -0500
committerPhilip Hood <hood@panix.com>2020-11-23 21:06:48 -0500
commit3c80dfb0fbe6adb3e1ee5ca9df4cf1fd858279ce (patch)
treea0072b76068776c525c7b3932eecb947c0dd57e3
parenta36f58dcbcc932577398a98e53e7c445cff7bd0f (diff)
downloadperlweeklychallenge-club-3c80dfb0fbe6adb3e1ee5ca9df4cf1fd858279ce.tar.gz
perlweeklychallenge-club-3c80dfb0fbe6adb3e1ee5ca9df4cf1fd858279ce.tar.bz2
perlweeklychallenge-club-3c80dfb0fbe6adb3e1ee5ca9df4cf1fd858279ce.zip
challenges 1 & 2 in raku ...
-rwxr-xr-xchallenge-088/pkmnx/raku/ch-1.raku29
-rwxr-xr-xchallenge-088/pkmnx/raku/ch-2.raku80
2 files changed, 109 insertions, 0 deletions
diff --git a/challenge-088/pkmnx/raku/ch-1.raku b/challenge-088/pkmnx/raku/ch-1.raku
new file mode 100755
index 0000000000..a96fe31f36
--- /dev/null
+++ b/challenge-088/pkmnx/raku/ch-1.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env rakudo
+
+#
+# ex: ./ch-1.raku 5 2 1 4 3
+#
+
+sub MAIN ( *@N where @N.elems >2 && all(@N) ~~ Int ) {
+
+ my %h;
+ ( (^@N.elems) X (^@N.elems) ).grep(-> ($x,$y) { $x != $y }).map( -> ($x, $y) { %h{$x}.push( @N[$y] ) });
+
+ "Input: ".say;
+ print "@N = (";
+ print @N.join(", ");
+ print ")\n";
+
+ my @output = %h.keys.sort.map(-> $k {
+ my @v = @(%h{$k}); my $prd = ([*] @v); ('$M[' ~ $k ~ '] = ' ~ @v.join(' x ') ~ ' = ' ~ $prd, $prd )
+ });
+
+ "Output: ".say;
+ print "@M = (";
+ print @output.map( -> ($k,$v) { $v }).join(", ");
+ print ")\n\n";
+
+ @output.map( -> ($k,$v) {
+ $k.say;
+ });
+}
diff --git a/challenge-088/pkmnx/raku/ch-2.raku b/challenge-088/pkmnx/raku/ch-2.raku
new file mode 100755
index 0000000000..496888a5da
--- /dev/null
+++ b/challenge-088/pkmnx/raku/ch-2.raku
@@ -0,0 +1,80 @@
+#!/usr/bin/env rakudo
+#
+# ex. ./ch-2.raku < input.txt # where input is rectangular shaped data block of numbers
+#
+
+sub MAIN () {
+
+ my $d = verifyInput();
+
+ "Input:".say;
+ $d.join("\n").say;
+
+ my $output;
+
+ while ($d) {
+ my $f = $d.shift;
+
+ $output.push($f);
+ if ($d) {
+ my $l = $d.pop.reverse;
+
+ my $leftCnt = 0;
+ my $tmp;
+ while ($d) {
+ my $t = shift $d;
+ if ( $t.elems ) {
+ my $tl = pop $t;
+ $output.push($tl);
+ $tmp.push($t);
+ }
+ $leftCnt++;
+ }
+
+ if ( $l ) {
+ $output.push($l);
+ $l = Nil;
+ }
+
+ while ( $leftCnt >0 ) {
+ my $t = pop $tmp;
+ if ( $t.elems ) {
+ my $tf = shift $t;
+ $output.push($tf);
+ if ( $d ) {
+ $d.unshift( ($t) );
+ } else {
+ $d = [$t];
+ }
+ }
+ $leftCnt--;
+ }
+
+ }
+
+ }
+
+ "".say;
+ "Output:".say;
+ $output.List.flat.join(", ").say;
+}
+
+sub verifyInput() {
+
+ my $data;
+ my $lcnt = 0;
+ my $dsz = 0;
+
+ for $*IN.lines() -> $l {
+ my @d = $l.comb(/\d+/);
+ if ( $dsz == 0 ) { $dsz = @d.elems; }
+ if ( $dsz != @d.elems ) { die "Input must be in rectangular format."; }
+ $data.push( @d );
+ $lcnt++;
+ }
+
+ if ( $lcnt < 2 ) { die "there must be at least 2 lines of input."; }
+ if ( $dsz < 2 ) { die "line length must be greater than 1."; }
+
+ return $data;
+}