diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-16 21:18:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-16 21:18:34 +0100 |
| commit | ab006a3e8a0ffcf4efee84744165d0a8d27c2899 (patch) | |
| tree | ef6121c9ced5ecea4d3bd5594f45b76c2acd24ba /challenge-112 | |
| parent | ab724d005cc0cd0041ccbe254ef8fcae5cdb9d43 (diff) | |
| parent | 2af847b4283e1707ff2c99b9feeb45692c875924 (diff) | |
| download | perlweeklychallenge-club-ab006a3e8a0ffcf4efee84744165d0a8d27c2899.tar.gz perlweeklychallenge-club-ab006a3e8a0ffcf4efee84744165d0a8d27c2899.tar.bz2 perlweeklychallenge-club-ab006a3e8a0ffcf4efee84744165d0a8d27c2899.zip | |
Merge pull request #4088 from mimosinnet/branch-for-challenge-112
Solutions for challenge 112
Diffstat (limited to 'challenge-112')
| -rw-r--r-- | challenge-112/mimosinnet/raku/ch-1.raku | 34 | ||||
| -rw-r--r-- | challenge-112/mimosinnet/raku/ch-2.raku | 47 |
2 files changed, 81 insertions, 0 deletions
diff --git a/challenge-112/mimosinnet/raku/ch-1.raku b/challenge-112/mimosinnet/raku/ch-1.raku new file mode 100644 index 0000000000..3c368f87bc --- /dev/null +++ b/challenge-112/mimosinnet/raku/ch-1.raku @@ -0,0 +1,34 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-112/ + +sub challenge( Str $path ) { + return IO::Spec::Unix.canonpath($path, :parent); +} + +multi sub MAIN( Str $path ) { + say 'Input: "',$path,'"'; + say 'Output: "',challenge($path),"\"\n"; +} + +multi sub MAIN( 'challenge' ) { + my @challenge = < /a /a/b//c/ /a/b/c/../.. >; + + for @challenge -> $a { + MAIN($a); + } +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + my @test = ( + </a /a>, + </a/b//c/ /a/b/c>, + </a/b/c/../.. /a> + ); + + for @test -> ($a, $b) { + is challenge($a), $b; + } + + done-testing; +} diff --git a/challenge-112/mimosinnet/raku/ch-2.raku b/challenge-112/mimosinnet/raku/ch-2.raku new file mode 100644 index 0000000000..23e94990a9 --- /dev/null +++ b/challenge-112/mimosinnet/raku/ch-2.raku @@ -0,0 +1,47 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-112/ + +sub challenge( $top ) { + my $steps = 1 x $top; + my $number_steps = 1; + while $steps ~~ /11/ { + $steps = $steps.subst('11','2'); + $number_steps += $steps.split('', :skip-empty).permutations.unique(:with(&[eqv])).elems; + } + return $number_steps; +} + +sub write_steps( $top ) { + my $steps = 1 x $top; + my @options; + @options.push: $steps.split('', :skip-empty); + while $steps ~~ /11/ { + $steps = $steps.subst('11','2'); + @options.append: $steps.split('', :skip-empty).permutations.unique(:with(&[eqv])); + } + return @options; +} + +multi sub MAIN( $top ) { + say "\nInput: \$n = ",$top; + say 'Output: ',challenge($top); + my $i; + for write_steps($top) -> @steps { + say ' Option ',++$i,': ',@steps.join('').subst('1','1 step + ', :g).subst('2','2 steps + ', :g).chop(3); + } +} + +multi sub MAIN( 'challenge' ) { + MAIN(3); + MAIN(4); +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + is challenge(3),3; + is challenge(4),5; + is challenge(10),89; + + done-testing; + +} |
