aboutsummaryrefslogtreecommitdiff
path: root/challenge-069
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2020-12-06 00:04:20 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2020-12-06 00:04:20 -0500
commit9b41fb82f362f7df6752eb4ba04618dc59e25427 (patch)
tree4a426efac1eeb8a09f8a159631669e1138e094b1 /challenge-069
parentd19b0f983bbefca06f6139624711c079ac18eb6e (diff)
downloadperlweeklychallenge-club-9b41fb82f362f7df6752eb4ba04618dc59e25427.tar.gz
perlweeklychallenge-club-9b41fb82f362f7df6752eb4ba04618dc59e25427.tar.bz2
perlweeklychallenge-club-9b41fb82f362f7df6752eb4ba04618dc59e25427.zip
1st commit on 069
Diffstat (limited to 'challenge-069')
-rw-r--r--challenge-069/stuart-little/README1
-rwxr-xr-xchallenge-069/stuart-little/raku/ch-1.p633
-rwxr-xr-xchallenge-069/stuart-little/raku/ch-2.p612
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-069/stuart-little/README b/challenge-069/stuart-little/README
new file mode 100644
index 0000000000..78439907de
--- /dev/null
+++ b/challenge-069/stuart-little/README
@@ -0,0 +1 @@
+Solutions by Stuart Little
diff --git a/challenge-069/stuart-little/raku/ch-1.p6 b/challenge-069/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..6d3e947e6e
--- /dev/null
+++ b/challenge-069/stuart-little/raku/ch-1.p6
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run as <script> <lower bound> <upper bound>
+
+sub left_half_strb(Int $digits where * > 0) {
+ my @digits=(0,1,6,8,9);
+ $digits==1 && return @digits[1..*-1];
+ return (@digits[1..*-1], |(@digits xx ($digits-1))).reduce(&infix:<X>).map(*.join)
+}
+
+sub strb(Int $digits where * > 0) {
+ given $digits {
+ when 1 { (1,8) }
+ my @halves=left_half_strb($digits div 2);
+ when * %% 2 { @halves Z~ @halves.map(*.flip.trans('69'=>'96')) }
+ default { (@halves X~ (0,1,8)).map({ $_ ~ $_.substr(0,($digits div 2)).flip.trans('69'=>'96') }) }
+ }
+}
+
+multi sub strb_bd($low, $high where *.chars==$low.chars) {
+ my $digits=$low.chars;
+ strb($digits).grep({ $low le $_ le $high })
+}
+
+multi sub strb_bd($low, $high) {
+ my @low=strb($low.chars).grep({ $low le $_ });
+ my @mid=($low.chars^..^$high.chars).map({ |strb($_) });
+ my @high=strb($high.chars).grep({ $_ le $high });
+ (|@low, |@mid, |@high)
+}
+
+say strb_bd(|@*ARGS[0,1].map(*.Int))
diff --git a/challenge-069/stuart-little/raku/ch-2.p6 b/challenge-069/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..45d755ce99
--- /dev/null
+++ b/challenge-069/stuart-little/raku/ch-2.p6
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl6
+use v6;
+
+my $s='';
+
+for (1..((@*ARGS) ?? @*ARGS[0].Int !! 10)) {
+ $s ~= ('0' ~ $s.trans('01' => '10').flip )
+}
+
+say $s
+
+# run as <script> <number of iterations (a positive integer; defaults to 10)>