diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2020-03-23 19:41:11 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2020-03-23 19:41:11 -0400 |
| commit | 7bb009b65541c03e71468b4917b9a098f1fbbba7 (patch) | |
| tree | 8c812d0717e4be254d74370f5eb4bab2b91cda4c | |
| parent | 4c1c768bd12a75480fa4d4c5cfe70ac861b21e9b (diff) | |
| download | perlweeklychallenge-club-7bb009b65541c03e71468b4917b9a098f1fbbba7.tar.gz perlweeklychallenge-club-7bb009b65541c03e71468b4917b9a098f1fbbba7.tar.bz2 perlweeklychallenge-club-7bb009b65541c03e71468b4917b9a098f1fbbba7.zip | |
I solved task 2 first and got confused
| -rw-r--r-- | challenge-053/dave-jacoby/node/ch-2.js | 35 | ||||
| -rw-r--r-- | challenge-053/dave-jacoby/perl/ch-1.pl | 103 | ||||
| -rw-r--r-- | challenge-053/dave-jacoby/perl/ch-2.pl | 103 | ||||
| -rw-r--r-- | challenge-053/dave-jacoby/rust/ch-2.rs | 51 |
4 files changed, 189 insertions, 103 deletions
diff --git a/challenge-053/dave-jacoby/node/ch-2.js b/challenge-053/dave-jacoby/node/ch-2.js new file mode 100644 index 0000000000..b0cd5fa3c6 --- /dev/null +++ b/challenge-053/dave-jacoby/node/ch-2.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 index 0e9992e4c2..a81a4ab62d 100644 --- a/challenge-053/dave-jacoby/perl/ch-1.pl +++ b/challenge-053/dave-jacoby/perl/ch-1.pl @@ -5,41 +5,82 @@ 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] } +use JSON; +my $json = JSON->new; -my @strings = vowel_strings($l); -say join "\n", @strings; +my $array = [ [ 1 .. 3 ], [ 4 .. 6 ], [ 7 .. 9 ] ]; -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 $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; +} - my @output; - for my $n (@next) { - push @output, vowel_strings( $l, $string . $n ); +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; + 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/ch-2.pl b/challenge-053/dave-jacoby/perl/ch-2.pl index a81a4ab62d..0e9992e4c2 100644 --- a/challenge-053/dave-jacoby/perl/ch-2.pl +++ b/challenge-053/dave-jacoby/perl/ch-2.pl @@ -5,82 +5,41 @@ use warnings; use feature qw{ say postderef signatures state }; no warnings qw{ experimental::postderef experimental::signatures }; -use JSON; -my $json = JSON->new; +my $l = 2; +if ( scalar @ARGV && int $ARGV[0] > 0 ) { $l = int $ARGV[0] } -my $array = [ [ 1 .. 3 ], [ 4 .. 6 ], [ 7 .. 9 ] ]; +my @strings = vowel_strings($l); +say join "\n", @strings; -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]; - } +sub vowel_strings ( $l, $string = '' ) { + if ( length $string == $l ) { + return $string; } - 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]; - } + my @next; + my $m = length $string == 0 ? '' : substr $string, -1; + if ( $string eq '' ) { + @next = qw{ a e i o u}; } - 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]; - } + 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 }; } - return $output; -} - -__DATA__ - -1 2 3 -4 5 6 -7 8 9 -7 4 1 -8 5 2 -9 6 3 + my @output; + for my $n (@next) { + push @output, vowel_strings( $l, $string . $n ); + } + return @output; -so 0,0 = 2,0 - 0,1 = 3,0 +} diff --git a/challenge-053/dave-jacoby/rust/ch-2.rs b/challenge-053/dave-jacoby/rust/ch-2.rs new file mode 100644 index 0000000000..086987ff5b --- /dev/null +++ b/challenge-053/dave-jacoby/rust/ch-2.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 |
