diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-03-23 09:44:00 +0000 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-03-23 09:44:00 +0000 |
| commit | 2b32380c48492ce9b835a149e937a4ae7050bbf5 (patch) | |
| tree | 14cdee95b0e289bc6762fe2b70faa824515cebb5 /challenge-053/simon-proctor | |
| parent | b5a5a106e7d51a1bdb4289e51ac72e00e5aba1cf (diff) | |
| download | perlweeklychallenge-club-2b32380c48492ce9b835a149e937a4ae7050bbf5.tar.gz perlweeklychallenge-club-2b32380c48492ce9b835a149e937a4ae7050bbf5.tar.bz2 perlweeklychallenge-club-2b32380c48492ce9b835a149e937a4ae7050bbf5.zip | |
Challenge 53 in the bag.
Diffstat (limited to 'challenge-053/simon-proctor')
| -rw-r--r-- | challenge-053/simon-proctor/raku/ch-1.p6 | 32 | ||||
| -rw-r--r-- | challenge-053/simon-proctor/raku/ch-2.p6 | 48 |
2 files changed, 80 insertions, 0 deletions
diff --git a/challenge-053/simon-proctor/raku/ch-1.p6 b/challenge-053/simon-proctor/raku/ch-1.p6 new file mode 100644 index 0000000000..7572117c5e --- /dev/null +++ b/challenge-053/simon-proctor/raku/ch-1.p6 @@ -0,0 +1,32 @@ +#!/usr/bin/env raku + +use v6; + +subset Rotation of Int where * ~~ 0|90|180|270; + +#| Rotate the 3x3 matrix of 1 to 9 through 0, 90, 180 or 270 degrees clockwise +sub MAIN ( + Rotation $rotate is copy, #= Degrees to rotate clockwise through, 0, 90, 180 or 270 +) { + my @matrix = + [ + [1,2,3], + [4,5,6], + [7,8,9] + ]; + + while $rotate > 0 { + $rotate -= 90; + @matrix = rotate-matrix( @matrix ); + }; + + @matrix.map( *.join( " " ) ).join("\n").say; +} + +sub rotate-matrix ( @m ) { + [ + [@m[2][0], @m[1][0], @m[0][0]], + [@m[2][1], @m[1][1], @m[0][1]], + [@m[2][2], @m[1][2], @m[0][2]] + ] +} diff --git a/challenge-053/simon-proctor/raku/ch-2.p6 b/challenge-053/simon-proctor/raku/ch-2.p6 new file mode 100644 index 0000000000..f68bb6f615 --- /dev/null +++ b/challenge-053/simon-proctor/raku/ch-2.p6 @@ -0,0 +1,48 @@ +#!/usr/bin/env raku + +use v6; + +#| Given a number between 1 and 5 return all the strings made of vowels following this rule : +#| ‘a’ can only be followed by ‘e’ and ‘i’. +#| ‘e’ can only be followed by ‘i’. +#| ‘i’ can only be followed by ‘a’, ‘e’, ‘o’, and ‘u’. +#| ‘o’ can only be followed by ‘a’ and ‘u’. +#| ‘u’ can only be followed by ‘o’ and ‘e’. +sub MAIN ( + UInt $count is copy where 1 <= * <= 5; +) { + my @strings = (''); + while $count > 0 { + $count--; + my @next = (); + for @strings -> $string { + @next.push( |valid-next( $string ) ); + } + @strings = @next; + } + .say for @strings; +} + +multi sub valid-next( '' ) { + <a e i o u>; +} + +multi sub valid-next( Str $x where * ~~ /'a'$/ ) { + ("{$x}e", "{$x}i"); +} + +multi sub valid-next( Str $x where * ~~ /'e'$/ ) { + ("{$x}i"); +} + +multi sub valid-next( Str $x where * ~~ /'i'$/ ) { + ("{$x}a", "{$x}e", "{$x}o", "{$x}u"); +} + +multi sub valid-next( Str $x where * ~~ /'o'$/ ) { + ("{$x}a", "{$x}u"); +} + +multi sub valid-next( Str $x where * ~~ /'u'$/ ) { + ("{$x}o", "{$x}e"); +} |
