aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2021-01-11 09:04:13 +0100
committerAndrew Shitov <andy@shitov.ru>2021-01-11 09:04:13 +0100
commit5b590d0f8bce7dfed83c720148bff305b23a011b (patch)
treedcd03b854cfb41012b9fa47e5b8183b9b5219382
parent5ab993f243ab1a835d8f30aa6c97b2d3b99496af (diff)
downloadperlweeklychallenge-club-5b590d0f8bce7dfed83c720148bff305b23a011b.tar.gz
perlweeklychallenge-club-5b590d0f8bce7dfed83c720148bff305b23a011b.tar.bz2
perlweeklychallenge-club-5b590d0f8bce7dfed83c720148bff305b23a011b.zip
ash 095
-rw-r--r--challenge-095/ash/raku/ch-1.raku8
-rw-r--r--challenge-095/ash/raku/ch-2.raku30
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-095/ash/raku/ch-1.raku b/challenge-095/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..af959ff4f1
--- /dev/null
+++ b/challenge-095/ash/raku/ch-1.raku
@@ -0,0 +1,8 @@
+#!/usr/bin/env raku
+#
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/
+
+unit sub MAIN(Int $n);
+
+say +($n.flip eq $n);
diff --git a/challenge-095/ash/raku/ch-2.raku b/challenge-095/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..4ad212a893
--- /dev/null
+++ b/challenge-095/ash/raku/ch-2.raku
@@ -0,0 +1,30 @@
+#!/usr/bin/env raku
+#
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/
+
+# The taks is to demonstrate stack _operations_, not _imlementaion_.
+
+class Stack {
+ has @!stack;
+
+ method push($n) { @!stack.push($n) }
+ method pop { @!stack.pop }
+ method top { @!stack[*-1] }
+ method min { @!stack.min }
+
+ method empty { !@!stack }
+}
+
+my $s = Stack.new;
+# $s.stack; # is unreachable
+
+for ^10 {
+ my $n = 10.rand.Int;
+ say "push($n)";
+ $s.push($n);
+
+ say "\ttop = {$s.top}, min = {$s.min}";
+}
+
+say "pop() = {$s.pop}" while !$s.empty;