diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2020-11-29 10:00:44 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2020-11-29 10:00:44 -0500 |
| commit | 276194786b6decdb08bd065205e399dcafa0ed62 (patch) | |
| tree | ab62447b02566af4481900fcfaad2af5ddbbd88e /challenge-017 | |
| parent | e5f5309fd45b7e190c3bf574304d3b9b42ce185a (diff) | |
| download | perlweeklychallenge-club-276194786b6decdb08bd065205e399dcafa0ed62.tar.gz perlweeklychallenge-club-276194786b6decdb08bd065205e399dcafa0ed62.tar.bz2 perlweeklychallenge-club-276194786b6decdb08bd065205e399dcafa0ed62.zip | |
1st commit on 017-020
Diffstat (limited to 'challenge-017')
| -rw-r--r-- | challenge-017/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-017/stuart-little/raku/ch-1.p6 | 13 | ||||
| -rwxr-xr-x | challenge-017/stuart-little/raku/ch-2.p6 | 31 |
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-017/stuart-little/README b/challenge-017/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-017/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-017/stuart-little/raku/ch-1.p6 b/challenge-017/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..1519a9e698 --- /dev/null +++ b/challenge-017/stuart-little/raku/ch-1.p6 @@ -0,0 +1,13 @@ +#!/usr/bin/env perl6 +use v6; + +multi sub A(0,Int $n) { $n + 1 } +multi sub A(1,Int $n) { $n + 2 } +multi sub A(2,Int $n) { 2*$n + 3 } +multi sub A(3,Int $n) { 2 ** ($n + 3) -3 } +multi sub A(Int $m,0) { A($m-1,1) } +multi sub A(Int $m,Int $n) { A($m-1,A($m,$n-1)) } + +say A(|@*ARGS[0,1].map(*.Int)) + +# run as <script> <m n> to compute A(m,n) diff --git a/challenge-017/stuart-little/raku/ch-2.p6 b/challenge-017/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..b41f2a9a6c --- /dev/null +++ b/challenge-017/stuart-little/raku/ch-2.p6 @@ -0,0 +1,31 @@ +#!/usr/bin/env perl6 +use v6; + +grammar URL { + regex TOP { <scheme>':'(\/\/<authority>)?<path>(\?<query>)?('#'<fragment>)? } + regex scheme { .+? } + + regex authority { (<userinfo>'@')?<host>(':'<port>)? } + regex userinfo { .+ } + regex host { <-[:]>+ } + regex port { \d+ } + + regex path { <-[?]>* } + regex query { .+? } + regex fragment { .+ } +} + +URL.parse(@*ARGS[0]); +my $res = qq:to/END/; + +scheme: $/.<scheme> +userinfo: $/.[0].<authority>.[0].<userinfo> +host: $/.[0].<authority>.<host> +port: $/.[0].<authority>.[1].<port> +path: $/.<path> +query: $/.[1].<query> +fragment: $/.[2].<fragment> +END +say $res; + +# run as <script> <string to validate as URL> |
