aboutsummaryrefslogtreecommitdiff
path: root/challenge-069/ash
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2020-07-13 22:56:41 +0200
committerAndrew Shitov <andy@shitov.ru>2020-07-13 22:56:41 +0200
commit0734211c4d87710d42fd8fa3b577c1fcad28d70a (patch)
treecad4f71a474342b1eba5a191247c43e1b5138177 /challenge-069/ash
parent2ac7f88427945cdf702b60010dc795aedcdce579 (diff)
downloadperlweeklychallenge-club-0734211c4d87710d42fd8fa3b577c1fcad28d70a.tar.gz
perlweeklychallenge-club-0734211c4d87710d42fd8fa3b577c1fcad28d70a.tar.bz2
perlweeklychallenge-club-0734211c4d87710d42fd8fa3b577c1fcad28d70a.zip
ash 069 1 and 2
Diffstat (limited to 'challenge-069/ash')
-rw-r--r--challenge-069/ash/README4
-rw-r--r--challenge-069/ash/blog.txt2
-rw-r--r--challenge-069/ash/raku/ch-1.raku13
-rw-r--r--challenge-069/ash/raku/ch-2-bits.raku19
-rw-r--r--challenge-069/ash/raku/ch-2.cpp24
-rw-r--r--challenge-069/ash/raku/ch-2.raku18
6 files changed, 76 insertions, 4 deletions
diff --git a/challenge-069/ash/README b/challenge-069/ash/README
index c5f4656b17..318b1bfb41 100644
--- a/challenge-069/ash/README
+++ b/challenge-069/ash/README
@@ -1,3 +1 @@
-Solution by Andrew Shitov
-
-Comments to the task 1: https://andrewshitov.com/2020/07/06/raku-challenge-week-68/
+Solutions by Andrew Shitov
diff --git a/challenge-069/ash/blog.txt b/challenge-069/ash/blog.txt
index 9b0874eab9..ea031fb968 100644
--- a/challenge-069/ash/blog.txt
+++ b/challenge-069/ash/blog.txt
@@ -1 +1,3 @@
https://andrewshitov.com/2020/07/13/raku-challenge-week-69-issue-1/
+
+https://andrewshitov.com/2020/07/13/raku-challenge-week-69-issue-2/ \ No newline at end of file
diff --git a/challenge-069/ash/raku/ch-1.raku b/challenge-069/ash/raku/ch-1.raku
index ddc2fe12cf..0b92eb72db 100644
--- a/challenge-069/ash/raku/ch-1.raku
+++ b/challenge-069/ash/raku/ch-1.raku
@@ -1,8 +1,19 @@
+#!/usr/bin/env raku
+
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-069/
+
+# Comments: https://andrewshitov.com/2020/07/13/raku-challenge-week-69-issue-1/
+
my $a = 0;
-my $b = 2000;
+my $b = 200;
put grep {
$_ ~~ / ^ <[01689]>+ $ / &&
$_ eq $_.trans('69' => '96').flip
},
$a..$b;
+
+# Output:
+
+# 0 1 8 11 69 88 96 101 111 181
diff --git a/challenge-069/ash/raku/ch-2-bits.raku b/challenge-069/ash/raku/ch-2-bits.raku
new file mode 100644
index 0000000000..16d199b9a6
--- /dev/null
+++ b/challenge-069/ash/raku/ch-2-bits.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-069/
+
+# Comments: https://andrewshitov.com/2020/07/13/raku-challenge-week-69-issue-2/
+
+my @bits of int;
+@bits.push(0);
+
+for ^7 -> $n {
+ my $size = @bits.elems;
+ print "S{$n+2} = ";
+ @bits.push(0);
+ @bits.push(@bits[$size - $_] ?? 0 !! 1) for 1 .. $size;
+
+ .print for @bits;
+ ''.say;
+}
diff --git a/challenge-069/ash/raku/ch-2.cpp b/challenge-069/ash/raku/ch-2.cpp
new file mode 100644
index 0000000000..74cae7876b
--- /dev/null
+++ b/challenge-069/ash/raku/ch-2.cpp
@@ -0,0 +1,24 @@
+// Compile as: g++ -std=c++17 ch-2.cpp
+
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+int main() {
+ vector<bool> bits;
+ bits.push_back(0);
+
+ for (int n = 2; n <= 8; n++) {
+ int size = bits.size();
+ bits.push_back(0);
+
+ cout << 'S' << n << " = ";
+
+ for (int m = 1; m <= size; m++)
+ bits.push_back(!bits[size - m]);
+
+ for (auto x : bits) cout << x;
+ cout << endl;
+ }
+}
diff --git a/challenge-069/ash/raku/ch-2.raku b/challenge-069/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..bbdcfd97c8
--- /dev/null
+++ b/challenge-069/ash/raku/ch-2.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-069/
+
+# Comments: https://andrewshitov.com/2020/07/13/raku-challenge-week-69/
+
+multi sub S(0) {''}
+multi sub S(1) {'0'}
+multi sub S($n) {
+ my $prev = S($n - 1);
+ $prev ~ '0' ~ $prev.flip.trans('01' => '10')
+}
+
+# S($_) for ^25;
+say "S$_ = {S($_)}" for ^9;
+
+# say S(1000);