From 2b32380c48492ce9b835a149e937a4ae7050bbf5 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 23 Mar 2020 09:44:00 +0000 Subject: Challenge 53 in the bag. --- challenge-053/simon-proctor/raku/ch-1.p6 | 32 +++++++++++++++++++++ challenge-053/simon-proctor/raku/ch-2.p6 | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 challenge-053/simon-proctor/raku/ch-1.p6 create mode 100644 challenge-053/simon-proctor/raku/ch-2.p6 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( '' ) { + ; +} + +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"); +} -- cgit