diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-07-23 16:36:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-23 16:36:49 +0100 |
| commit | 7f28350e48d142797690586e281ffdfe843c3442 (patch) | |
| tree | 0a5e78ca4e5209dc8e0bdf1aa3a043f2915881d0 | |
| parent | 4476908812fcbfb24c965795f8ed079497cc2bb7 (diff) | |
| parent | 69769e0caa51662233bcfb8ac1e0311b83a2918f (diff) | |
| download | perlweeklychallenge-club-7f28350e48d142797690586e281ffdfe843c3442.tar.gz perlweeklychallenge-club-7f28350e48d142797690586e281ffdfe843c3442.tar.bz2 perlweeklychallenge-club-7f28350e48d142797690586e281ffdfe843c3442.zip | |
Merge pull request #1973 from fluca1978/pwc-70
Pwc 70
| -rw-r--r-- | challenge-070/luca-ferrari/blog-1,txt | 1 | ||||
| -rw-r--r-- | challenge-070/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-070/luca-ferrari/raku/ch-1.p6 | 18 | ||||
| -rw-r--r-- | challenge-070/luca-ferrari/raku/ch-2.p6 | 23 |
4 files changed, 43 insertions, 0 deletions
diff --git a/challenge-070/luca-ferrari/blog-1,txt b/challenge-070/luca-ferrari/blog-1,txt new file mode 100644 index 0000000000..af39af813a --- /dev/null +++ b/challenge-070/luca-ferrari/blog-1,txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2020/07/23/PerlWeeklyChallenge70.html#task1
\ No newline at end of file diff --git a/challenge-070/luca-ferrari/blog-2.txt b/challenge-070/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..b2cf696624 --- /dev/null +++ b/challenge-070/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2020/07/23/PerlWeeklyChallenge70.html#task2 diff --git a/challenge-070/luca-ferrari/raku/ch-1.p6 b/challenge-070/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..f3d3c3adf0 --- /dev/null +++ b/challenge-070/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,18 @@ +#!raku + + +sub MAIN( Str $S, + Int $C where { $C >= 1 }, + Int $O where { $O >= 1 && $O >= $C && ( $C + $O ) <= $S.chars } ) { + my $N = $S.chars; + + say "$S with $N chars, swap counter $C and offset $O"; + + my @chars = $S.split( '', :skip-empty ); + for 1 .. $C { + my ( $index-left, $index-right ) = $_ % $N, ( $_ + $O ) % $N; + ( @chars[ $index-left ], @chars[ $index-right ] ) = @chars[ $index-right ], @chars[ $index-left ]; + } + + @chars.join.say; +} diff --git a/challenge-070/luca-ferrari/raku/ch-2.p6 b/challenge-070/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..1e433fb123 --- /dev/null +++ b/challenge-070/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,23 @@ +#!raku + + +sub MAIN( Int $N where { 2 <= $N <= 5 } ) { + say "Grey sequence with width $N"; + + my @sequence; + @sequence[ 0 ] = 0.base( 2 ); + @sequence[ 1 ] = 1.base( 2 ); + + for 2 .. $N { + # duplicate the sequence + @sequence.push: | @sequence.reverse; + + # add the zero or one to the elements + for 0 ..^ @sequence.elems -> $mirroring { + @sequence[ $mirroring ] = ( $mirroring >= @sequence.elems / 2 ?? '1' !! '0' ) ~ @sequence[ $mirroring ]; + } + + } + + @sequence.map( *.parse-base( 2 ) ).say; +} |
