diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-11-16 22:53:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-16 22:53:41 +0000 |
| commit | a7a6da3cf3664d65ae3ff3ef9856fcb30b5b972d (patch) | |
| tree | 574a4d300f71a0653a0f81f38638c8ebf8e7013e | |
| parent | 7e691939f19a10cad0c856065872e4ae74cdf4cc (diff) | |
| parent | 027c247a80ab6c8a7732437f797d5c7c0c38e708 (diff) | |
| download | perlweeklychallenge-club-a7a6da3cf3664d65ae3ff3ef9856fcb30b5b972d.tar.gz perlweeklychallenge-club-a7a6da3cf3664d65ae3ff3ef9856fcb30b5b972d.tar.bz2 perlweeklychallenge-club-a7a6da3cf3664d65ae3ff3ef9856fcb30b5b972d.zip | |
Merge pull request #2782 from stuart-little/stuart-little_031-032-048
initial commit on 031,032,048
| -rw-r--r-- | challenge-031/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-031/stuart-little/raku/ch-1.p6 | 11 | ||||
| -rwxr-xr-x | challenge-031/stuart-little/raku/ch-2.p6 | 11 | ||||
| -rw-r--r-- | challenge-032/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-032/stuart-little/raku/ch-1.p6 | 22 | ||||
| -rwxr-xr-x | challenge-032/stuart-little/raku/ch-2.p6 | 24 | ||||
| -rw-r--r-- | challenge-048/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-048/stuart-little/raku/ch-1.p6 | 15 | ||||
| -rwxr-xr-x | challenge-048/stuart-little/raku/ch-2.p6 | 6 |
9 files changed, 92 insertions, 0 deletions
diff --git a/challenge-031/stuart-little/README b/challenge-031/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-031/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-031/stuart-little/raku/ch-1.p6 b/challenge-031/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..55288764c8 --- /dev/null +++ b/challenge-031/stuart-little/raku/ch-1.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 +use v6; + +try { + say @*ARGS[0].Real/@*ARGS[1].Real; +} + +($!) && say "Tried to divide by 0, eh?" + +# run as <script> <numerator> <denominator> + diff --git a/challenge-031/stuart-little/raku/ch-2.p6 b/challenge-031/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..350f958e82 --- /dev/null +++ b/challenge-031/stuart-little/raku/ch-2.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 +use v6; + +my $name = "\$@*ARGS[0]"; +spurt 'MySymbols.pm6', "use v6; unit module MySymbols; my $name = \'@*ARGS[1]\'; say \"\\$name = $name\""; +use lib '.'; +require MySymbols; +unlink 'MySymbols.pm6'; + +# run as <script> <variable name> <variable value> +# ref: https://stackoverflow.com/questions/47332941/how-to-define-variable-names-dynamically-in-perl-6 diff --git a/challenge-032/stuart-little/README b/challenge-032/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-032/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-032/stuart-little/raku/ch-1.p6 b/challenge-032/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..9961930fcd --- /dev/null +++ b/challenge-032/stuart-little/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS=:named-anywhere,; +sub MAIN( + Bool :c(:$csv), + *@FILES, + ) { + + sub freq(@a,$cflag) { + my @bg=@a.Bag.sort({$^b.value leg $^a.value}); + (! $cflag) ?? + (@bg) !! + (@bg.map({ $_.key ~ ',' ~ $_.value })) + } + + my @a=(! @FILES) + ?? ($*IN.lines) + !! (@FILES.map({ $_.IO.lines }).flat); + for freq(@a,$csv) {.say}; +} + diff --git a/challenge-032/stuart-little/raku/ch-2.p6 b/challenge-032/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..79743021c9 --- /dev/null +++ b/challenge-032/stuart-little/raku/ch-2.p6 @@ -0,0 +1,24 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS=:named-anywhere,; +sub MAIN( + Str :b(:$by) ="values", + *@ARGS, + ) { + + sub chrt(%h, Str $by) { + %h.sort({ ($by eq "labels") && $_.key + || ($by eq "values") && -$_.value }) + .map({ sprintf("%10s", $_.key) ~ ' | ' ~ '#' x $_.value }) + } + + my %h=@ARGS; + for chrt(%h.map({$_.key => $_.value.Int}).Hash,$by) {.say}; +} + +sub USAGE() { + print Q:c:to/EOH/; + Usage: <script> [hash passed as key value key value ..] [-b|--by=values(default)|labels] +EOH +} diff --git a/challenge-048/stuart-little/README b/challenge-048/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-048/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-048/stuart-little/raku/ch-1.p6 b/challenge-048/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..25a4cd51bd --- /dev/null +++ b/challenge-048/stuart-little/raku/ch-1.p6 @@ -0,0 +1,15 @@ +#!/usr/bin/env perl6 +use v6; + +sub surv(@a where *.elems >= 1) { + given @a.elems { + when * <= 2 {@a[0]} + default { + (|@a[2..*], @a[0]).&surv + } + } +} + +say (1..@*ARGS[0].Int).&surv.base(2) + +# run as <script> <number of players> diff --git a/challenge-048/stuart-little/raku/ch-2.p6 b/challenge-048/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..d863cafea0 --- /dev/null +++ b/challenge-048/stuart-little/raku/ch-2.p6 @@ -0,0 +1,6 @@ +#!/usr/bin/env perl6 +use v6; + +say (Date.new(2000, 1, 1)..Date.new(2200, 12, 31)).grep({ $_.day == 2 || $_.day == 12 }).grep({ ($_.year %% 10) && (! $_.year %% 100) || ($_.year % 100 == (1,11,21).any ) }).map({ sprintf("%02d", $_.month) ~ sprintf("%02d", $_.day) ~ $_.year }).grep({ $_ eq $_.flip }) + +# run as <script> |
