aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-053/dave-jacoby/node/ch-1.js35
-rw-r--r--challenge-053/dave-jacoby/perl/ch-1.pl45
-rw-r--r--challenge-053/dave-jacoby/perl/ch-2.pl86
-rw-r--r--challenge-053/dave-jacoby/perl/rotate_matrix.pl86
-rw-r--r--challenge-053/dave-jacoby/rust/ch-1.rs51
5 files changed, 303 insertions, 0 deletions
diff --git a/challenge-053/dave-jacoby/node/ch-1.js b/challenge-053/dave-jacoby/node/ch-1.js
new file mode 100644
index 0000000000..b0cd5fa3c6
--- /dev/null
+++ b/challenge-053/dave-jacoby/node/ch-1.js
@@ -0,0 +1,35 @@
+#!/usr/bin/env node
+
+vowel_strings(2);
+
+function vowel_strings(max_len, str = '') {
+ if (str.length === max_len) {
+ console.log(str);
+ return;
+ }
+ var next = [];
+ var last = '';
+
+ if (str.length > 0) {
+ last = str.substring(-1, 1);
+ }
+
+ if (str === '') {
+ next = ['a', 'e', 'i', 'o', 'u'];
+ } else if (last === 'a') {
+ next = ['e', 'i'];
+ } else if (last === 'e') {
+ next = ['i'];
+ } else if (last === 'i') {
+ next = ['a', 'e', 'o', 'u'];
+ } else if (last === 'o') {
+ next = ['a', 'u'];
+ } else if (last === 'u') {
+ next = ['e', 'o'];
+ }
+
+ const iter = next.values();
+ for (const i of iter) {
+ vowel_strings(max_len, str + i);
+ }
+}
diff --git a/challenge-053/dave-jacoby/perl/ch-1.pl b/challenge-053/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..0e9992e4c2
--- /dev/null
+++ b/challenge-053/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental::postderef experimental::signatures };
+
+my $l = 2;
+if ( scalar @ARGV && int $ARGV[0] > 0 ) { $l = int $ARGV[0] }
+
+my @strings = vowel_strings($l);
+say join "\n", @strings;
+
+sub vowel_strings ( $l, $string = '' ) {
+ if ( length $string == $l ) {
+ return $string;
+ }
+ my @next;
+ my $m = length $string == 0 ? '' : substr $string, -1;
+ if ( $string eq '' ) {
+ @next = qw{ a e i o u};
+ }
+ elsif ( $m eq 'a' ) {
+ @next = qw{ e i };
+ }
+ elsif ( $m eq 'e' ) {
+ @next = qw{ i };
+ }
+ elsif ( $m eq 'i' ) {
+ @next = qw{ a o u e };
+ }
+ elsif ( $m eq 'o' ) {
+ @next = qw{ a u };
+ }
+ elsif ( $m eq 'u' ) {
+ @next = qw{ o e };
+ }
+
+ my @output;
+ for my $n (@next) {
+ push @output, vowel_strings( $l, $string . $n );
+ }
+ return @output;
+
+}
diff --git a/challenge-053/dave-jacoby/perl/ch-2.pl b/challenge-053/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..a81a4ab62d
--- /dev/null
+++ b/challenge-053/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental::postderef experimental::signatures };
+
+use JSON;
+my $json = JSON->new;
+
+my $array = [ [ 1 .. 3 ], [ 4 .. 6 ], [ 7 .. 9 ] ];
+
+my $a90 = rotate_90($array);
+my $a180a = rotate_90($a90);
+my $a270a = rotate_90($a180a);
+my $a360a = rotate_90($a270a);
+
+my $a180b = rotate_180($array);
+my $a270b = rotate_270($array);
+
+say $json->encode($array);
+say '';
+say $json->encode($a90);
+say '';
+say $json->encode($a180a);
+say $json->encode($a180b);
+say '';
+say $json->encode($a270a);
+say $json->encode($a270b);
+say '';
+say $json->encode($a360a);
+
+sub rotate_90( $array ) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $y - $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+sub rotate_180( $array ) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $x - $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $y - $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+sub rotate_270($array) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $x - $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+__DATA__
+
+1 2 3
+4 5 6
+7 8 9
+
+7 4 1
+8 5 2
+9 6 3
+
+so 0,0 = 2,0
+ 0,1 = 3,0
diff --git a/challenge-053/dave-jacoby/perl/rotate_matrix.pl b/challenge-053/dave-jacoby/perl/rotate_matrix.pl
new file mode 100644
index 0000000000..a81a4ab62d
--- /dev/null
+++ b/challenge-053/dave-jacoby/perl/rotate_matrix.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental::postderef experimental::signatures };
+
+use JSON;
+my $json = JSON->new;
+
+my $array = [ [ 1 .. 3 ], [ 4 .. 6 ], [ 7 .. 9 ] ];
+
+my $a90 = rotate_90($array);
+my $a180a = rotate_90($a90);
+my $a270a = rotate_90($a180a);
+my $a360a = rotate_90($a270a);
+
+my $a180b = rotate_180($array);
+my $a270b = rotate_270($array);
+
+say $json->encode($array);
+say '';
+say $json->encode($a90);
+say '';
+say $json->encode($a180a);
+say $json->encode($a180b);
+say '';
+say $json->encode($a270a);
+say $json->encode($a270b);
+say '';
+say $json->encode($a360a);
+
+sub rotate_90( $array ) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $y - $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+sub rotate_180( $array ) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $x - $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $y - $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+sub rotate_270($array) {
+ my $x = -1 + scalar $array->@*;
+ my $y = -1 + scalar $array->[0]->@*;
+ my $output = [];
+ for my $i ( 0 .. $x ) {
+ my $jj = $x - $i;
+ for my $j ( 0 .. $y ) {
+ my $ii = $j;
+ $output->[$i][$j] = int $array->[$ii][$jj];
+ }
+ }
+ return $output;
+}
+
+__DATA__
+
+1 2 3
+4 5 6
+7 8 9
+
+7 4 1
+8 5 2
+9 6 3
+
+so 0,0 = 2,0
+ 0,1 = 3,0
diff --git a/challenge-053/dave-jacoby/rust/ch-1.rs b/challenge-053/dave-jacoby/rust/ch-1.rs
new file mode 100644
index 0000000000..086987ff5b
--- /dev/null
+++ b/challenge-053/dave-jacoby/rust/ch-1.rs
@@ -0,0 +1,51 @@
+fn main() {
+ let my_str = "".to_string();
+ vowel_strings(2,my_str);
+}
+
+fn vowel_strings ( max_len:i32 , my_str:String) -> bool {
+ let rts_ym : String = my_str.chars().rev().collect();
+ let my_len = my_str.len();
+ let mut last = "";
+ let mut vnext : Vec<String> = Vec::new();
+
+ if max_len as usize == my_len {
+ println!("{}",my_str);
+ return true
+ }
+
+ if my_len > 0 {
+ last = &rts_ym[0..1];
+ }
+
+ if last == "a" {
+ vnext.push("e".to_string());
+ vnext.push("i".to_string());
+ } else if last == "e" {
+ vnext.push("i".to_string());
+ } else if last == "i" {
+ vnext.push("a".to_string());
+ vnext.push("e".to_string());
+ vnext.push("o".to_string());
+ vnext.push("u".to_string());
+ } else if last == "o" {
+ vnext.push("a".to_string());
+ vnext.push("o".to_string());
+ } else if last == "u" {
+ vnext.push("e".to_string());
+ vnext.push("o".to_string());
+ } else {
+ vnext.push("a".to_string());
+ vnext.push("e".to_string());
+ vnext.push("i".to_string());
+ vnext.push("o".to_string());
+ vnext.push("u".to_string());
+
+ }
+
+ for next in &vnext {
+ let next_str = format!("{}{}",my_str,next);
+ vowel_strings(max_len,next_str);
+ }
+ true
+} \ No newline at end of file