diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-07-21 17:28:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-21 17:28:48 +0100 |
| commit | e5686f4efa5b5289bdf8ad94e1d5c47889b0a1b0 (patch) | |
| tree | e0cd8492ed0a263803344d20d5f5fec11f2b3caa | |
| parent | 2512c3fe9d10232065a1db639d302ca17712a21a (diff) | |
| parent | 25c3b922e82ddb7e31f6a6e98a0deef047b81182 (diff) | |
| download | perlweeklychallenge-club-e5686f4efa5b5289bdf8ad94e1d5c47889b0a1b0.tar.gz perlweeklychallenge-club-e5686f4efa5b5289bdf8ad94e1d5c47889b0a1b0.tar.bz2 perlweeklychallenge-club-e5686f4efa5b5289bdf8ad94e1d5c47889b0a1b0.zip | |
Merge pull request #1965 from Scimon/master
Oooop
| -rw-r--r-- | challenge-069/simon-proctor/raku/ch-1.raku | 35 | ||||
| -rw-r--r-- | challenge-069/simon-proctor/raku/ch-2.raku | 15 | ||||
| -rw-r--r-- | challenge-070/simon-proctor/raku/ch-1.raku | 20 | ||||
| -rw-r--r-- | challenge-070/simon-proctor/raku/ch-2.raku | 18 |
4 files changed, 88 insertions, 0 deletions
diff --git a/challenge-069/simon-proctor/raku/ch-1.raku b/challenge-069/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..643ea2c262 --- /dev/null +++ b/challenge-069/simon-proctor/raku/ch-1.raku @@ -0,0 +1,35 @@ +#!/usr/bin/env raku + +#| Calculate the Strobogrammatic Numbers between $A and $B +sub MAIN ( + UInt $A, #= Start point + UInt $B where { $A <= $B <= 10**15 } , #= End point +) { + for (1..15) -> $length { + for strobogrammatic($length) -> $s { + next if $s < $A; + exit if $s > $B; + say $s; + } + } +} + +multi sub rev( 6 ) { 9 } +multi sub rev( 8 ) { 8 } +multi sub rev( 9 ) { 6 } + +multi sub strobogrammatic( 1 ) { ("8",) } + +multi sub strobogrammatic( $length where { 1 < $length <= 3 } ) { + my @base = [(6,),(8,),(9,)]; + make-strob( @base, $length ); +} + +multi sub strobogrammatic( $length ) { + my @base = [X] ((6,8,9) xx ($length div 2)); + make-strob(@base,$length); +} + +sub make-strob(@base,$length) { + @base.map( -> @start { |@start, |( $length %% 2 ?? () !! (8,) ), |@start.reverse.map( { rev($_) } ) } ).map( *.join("") ); +} diff --git a/challenge-069/simon-proctor/raku/ch-2.raku b/challenge-069/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..1023bf20c8 --- /dev/null +++ b/challenge-069/simon-proctor/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +#| Calculate S1000 where see https://perlweeklychallenge.org/blog/perl-weekly-challenge-069/ +multi sub MAIN ( UInt $S = 30 ) { + my @ret = []; + my $count = 0; + while $S > $count { + @ret .= push( "0", @ret.hyper.reverse.map(*.trans(<0 1> => <1 0>)).Slip ); + $count++; + } + say @ret.join(""); +} + + + diff --git a/challenge-070/simon-proctor/raku/ch-1.raku b/challenge-070/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..4ce551bfc6 --- /dev/null +++ b/challenge-070/simon-proctor/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +use v6 + +#| Given a string, swap count and offset swap characters in the string +sub MAIN ( + Str $S, #= String to manipulate + UInt $C, #= Swap count + UInt $O where { $C <= $O && $C + $O <= $S.codes }, #= Offset +) { + my @swaps = $S.comb; + my $N = $S.codes; + for 1..$C -> $i { + my $x = $i % $N; + my $y = ($i+$O) % $N; + @swaps[$x,$y] = @swaps[$y,$x]; + } + + @swaps.join("").say; +} diff --git a/challenge-070/simon-proctor/raku/ch-2.raku b/challenge-070/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..b32eef2438 --- /dev/null +++ b/challenge-070/simon-proctor/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/usr/bin/env raku + +use v6; + +#| Generate ther Gray Code of length N +sub MAIN ( + Int $N where 2 <= * <= 5 #= Length of Gray code sequence to generate +){ + say gray-bins( $N ).map( *.parse-base(2) ); +} + +multi sub gray-bins ( 1 ) { [ "0", "1" ] } + +multi sub gray-bins ( Int $n ) { + my @prev = gray-bins( $n - 1 ); + + [ |@prev.map({ "0{$_}" }), |@prev.reverse.map({"1{$_}"}) ]; +} |
