diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-10 14:34:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-10 14:34:08 +0100 |
| commit | f5ed12716c54f5f1db42bf241f728534ab7fb282 (patch) | |
| tree | e677b0384e9b175a5551057636631e13f3c463b9 | |
| parent | db79192d2c62c4680c6fda0f0ef3b65c41581e01 (diff) | |
| parent | 32c32666715099eac36f3fa29db48ac17348b7ef (diff) | |
| download | perlweeklychallenge-club-f5ed12716c54f5f1db42bf241f728534ab7fb282.tar.gz perlweeklychallenge-club-f5ed12716c54f5f1db42bf241f728534ab7fb282.tar.bz2 perlweeklychallenge-club-f5ed12716c54f5f1db42bf241f728534ab7fb282.zip | |
Merge pull request #4053 from fluca1978/pwc112
Pwc112
| -rw-r--r-- | challenge-112/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-112/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-112/luca-ferrari/raku/ch-1.p6 | 14 | ||||
| -rw-r--r-- | challenge-112/luca-ferrari/raku/ch-2.p6 | 26 |
4 files changed, 42 insertions, 0 deletions
diff --git a/challenge-112/luca-ferrari/blog-1.txt b/challenge-112/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..60c0a57573 --- /dev/null +++ b/challenge-112/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/05/10/PerlWeeklyChallenge112.html#task1 diff --git a/challenge-112/luca-ferrari/blog-2.txt b/challenge-112/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..89da990e83 --- /dev/null +++ b/challenge-112/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/05/10/PerlWeeklyChallenge112.html#task2 diff --git a/challenge-112/luca-ferrari/raku/ch-1.p6 b/challenge-112/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..b984a31b28 --- /dev/null +++ b/challenge-112/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,14 @@ +#!raku + +sub MAIN( Str :$path ) { + + my @results; + for $path.split( '/' ) { + next if ! $_ || $_ ~~ '.'; + @results.push: $_ if ( $_ !~~ '..' ); + @results = @results[ 0 .. * - 2 ] if $_ ~~ '..'; + + } + + ('/' ~ @results.join( '/' )).say; +} diff --git a/challenge-112/luca-ferrari/raku/ch-2.p6 b/challenge-112/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..c735eb0a1a --- /dev/null +++ b/challenge-112/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,26 @@ +#!raku + +sub MAIN( Int $top where { $top > 1 } ) { + my @solutions; + @solutions.push: 1 xx $top; + + my $current-solution = 1 x $top; + while ( $current-solution ~~ / 1 ** 2 / ) { + $current-solution ~~ s/ 1 ** 2 / 2 /; + $current-solution = $current-solution.split( ' ', :skip-empty ).join( '' ); + @solutions.push: $_ for $current-solution.split( '', :skip-empty ).permutations.unique( as => { .Str.trim } ); + + + } + + + for @solutions -> @current-solution { + say "\nPossible solution:"; + "%d step%s ".sprintf( $_, $_ > 1 ?? 's' !! '' ).print if $_ > 0 for @current-solution; + + } + + say ""; + +} + |
