aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;