aboutsummaryrefslogtreecommitdiff
path: root/challenge-044
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-01-24 21:45:14 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-01-24 21:45:14 +0000
commitc926febeed866713d723c1d1aeeab62ccb0fce1f (patch)
treef8875920c1ab3492db3d0440950bc4afbb5690bb /challenge-044
parentbac75dac372ec9302702a9afaa6608fc02b35207 (diff)
downloadperlweeklychallenge-club-c926febeed866713d723c1d1aeeab62ccb0fce1f.tar.gz
perlweeklychallenge-club-c926febeed866713d723c1d1aeeab62ccb0fce1f.tar.bz2
perlweeklychallenge-club-c926febeed866713d723c1d1aeeab62ccb0fce1f.zip
- Added solutions by Arne Sommer.
Diffstat (limited to 'challenge-044')
-rw-r--r--challenge-044/arne-sommer/blog.txt0
-rwxr-xr-xchallenge-044/arne-sommer/raku/10033
-rwxr-xr-xchallenge-044/arne-sommer/raku/20052
-rwxr-xr-xchallenge-044/arne-sommer/raku/25613
-rwxr-xr-xchallenge-044/arne-sommer/raku/ch-1.p633
-rwxr-xr-xchallenge-044/arne-sommer/raku/ch-2.p652
-rwxr-xr-xchallenge-044/arne-sommer/raku/ternary810
7 files changed, 193 insertions, 0 deletions
diff --git a/challenge-044/arne-sommer/blog.txt b/challenge-044/arne-sommer/blog.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-044/arne-sommer/blog.txt
diff --git a/challenge-044/arne-sommer/raku/100 b/challenge-044/arne-sommer/raku/100
new file mode 100755
index 0000000000..d05553ffa7
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/100
@@ -0,0 +1,33 @@
+#! /usr/bin/env raku
+
+use MONKEY-SEE-NO-EVAL;
+
+unit sub MAIN (:$verbose, :$all);
+
+my $input = "123456789";
+
+for ^Inf
+{
+ my $ternary = .base(3).fmt('%08d');
+
+ last if $ternary.chars > 8;
+
+ print ": $input ~ $ternary" if $verbose;
+
+ my $string = (roundrobin $input.comb, $ternary.comb.map({ conv($_) })).flat.join;
+
+ say " -> $string" if $verbose;
+
+ if (EVAL $string) == 100
+ {
+ say "100 == $string";
+ exit unless $all;
+ }
+}
+
+sub conv ($char)
+{
+ return "" if $char eq "0";
+ return "+" if $char eq "1";
+ return "-" if $char eq "2";
+}
diff --git a/challenge-044/arne-sommer/raku/200 b/challenge-044/arne-sommer/raku/200
new file mode 100755
index 0000000000..7c2ebecbd9
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/200
@@ -0,0 +1,52 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (:$verbose, :$infinite);
+
+my $lowest-match = Inf;
+
+my %found;
+
+for ^Inf
+{
+ my $binary = .base(2);
+
+ print ": $_ -> $binary " if $verbose;
+
+ my $val = 1;
+ my $path = "";
+
+ for $binary.comb -> $digit
+ {
+ $digit == 1
+ ?? ( $val += $val; $path ~= "*" )
+ !! ( $val += 1; $path ~= "+" );
+
+ last if %found{$path};
+
+ say " | $path -> $val" if $val >= 200 && $verbose;
+
+ if $val == 200
+ {
+ %found{$path} = True;
+ say "Match: $val at { $path.chars } steps (path: $path).";
+ $lowest-match = $path.chars;
+ if $verbose
+ {
+ my $curr = 1;
+ my $step = 1;
+ say ": Initial value: 1";
+ for $path.comb -> $operator
+ {
+ $operator eq "+" ?? ( $curr += 1 ) !! ( $curr += $curr );
+ say ": Step { $step++ }: $operator -> $curr";
+ }
+ }
+ }
+
+ last if $val >= 200;
+
+ exit if !$infinite && $path.chars > $lowest-match;
+ }
+
+ say " | $path -> $val" if $val < 200 && $verbose;
+}
diff --git a/challenge-044/arne-sommer/raku/256 b/challenge-044/arne-sommer/raku/256
new file mode 100755
index 0000000000..cfe80063fe
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/256
@@ -0,0 +1,13 @@
+#! /usr/bin/env raku
+
+my $money = 1;
+
+for 1 .. Inf -> $move
+{
+ $money *= 2;
+ if $money >= 200
+ {
+ say "Amount $money after $move moves.";
+ last;
+ }
+}
diff --git a/challenge-044/arne-sommer/raku/ch-1.p6 b/challenge-044/arne-sommer/raku/ch-1.p6
new file mode 100755
index 0000000000..d05553ffa7
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/ch-1.p6
@@ -0,0 +1,33 @@
+#! /usr/bin/env raku
+
+use MONKEY-SEE-NO-EVAL;
+
+unit sub MAIN (:$verbose, :$all);
+
+my $input = "123456789";
+
+for ^Inf
+{
+ my $ternary = .base(3).fmt('%08d');
+
+ last if $ternary.chars > 8;
+
+ print ": $input ~ $ternary" if $verbose;
+
+ my $string = (roundrobin $input.comb, $ternary.comb.map({ conv($_) })).flat.join;
+
+ say " -> $string" if $verbose;
+
+ if (EVAL $string) == 100
+ {
+ say "100 == $string";
+ exit unless $all;
+ }
+}
+
+sub conv ($char)
+{
+ return "" if $char eq "0";
+ return "+" if $char eq "1";
+ return "-" if $char eq "2";
+}
diff --git a/challenge-044/arne-sommer/raku/ch-2.p6 b/challenge-044/arne-sommer/raku/ch-2.p6
new file mode 100755
index 0000000000..7c2ebecbd9
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/ch-2.p6
@@ -0,0 +1,52 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (:$verbose, :$infinite);
+
+my $lowest-match = Inf;
+
+my %found;
+
+for ^Inf
+{
+ my $binary = .base(2);
+
+ print ": $_ -> $binary " if $verbose;
+
+ my $val = 1;
+ my $path = "";
+
+ for $binary.comb -> $digit
+ {
+ $digit == 1
+ ?? ( $val += $val; $path ~= "*" )
+ !! ( $val += 1; $path ~= "+" );
+
+ last if %found{$path};
+
+ say " | $path -> $val" if $val >= 200 && $verbose;
+
+ if $val == 200
+ {
+ %found{$path} = True;
+ say "Match: $val at { $path.chars } steps (path: $path).";
+ $lowest-match = $path.chars;
+ if $verbose
+ {
+ my $curr = 1;
+ my $step = 1;
+ say ": Initial value: 1";
+ for $path.comb -> $operator
+ {
+ $operator eq "+" ?? ( $curr += 1 ) !! ( $curr += $curr );
+ say ": Step { $step++ }: $operator -> $curr";
+ }
+ }
+ }
+
+ last if $val >= 200;
+
+ exit if !$infinite && $path.chars > $lowest-match;
+ }
+
+ say " | $path -> $val" if $val < 200 && $verbose;
+}
diff --git a/challenge-044/arne-sommer/raku/ternary8 b/challenge-044/arne-sommer/raku/ternary8
new file mode 100755
index 0000000000..c1e04c3fb4
--- /dev/null
+++ b/challenge-044/arne-sommer/raku/ternary8
@@ -0,0 +1,10 @@
+#! /usr/bin/env raku
+
+for ^Inf
+{
+ my $value = .base(3).fmt('%08d');
+
+ last if $value.chars > 8;
+
+ say $value;
+} \ No newline at end of file