aboutsummaryrefslogtreecommitdiff
path: root/challenge-095
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-17 01:47:16 +0000
committerGitHub <noreply@github.com>2021-01-17 01:47:16 +0000
commitbd1fbb984c32aa285b93bf30b0bcbd7980302961 (patch)
tree01e1f8b7a11f837a76d618d8b7d9df3d6bef12d8 /challenge-095
parentca7cf00e5118ff8b5736155022cdd301d88dbb8c (diff)
parent9c76a5725f8bbddf9ef933ca792ea587c838b1a7 (diff)
downloadperlweeklychallenge-club-bd1fbb984c32aa285b93bf30b0bcbd7980302961.tar.gz
perlweeklychallenge-club-bd1fbb984c32aa285b93bf30b0bcbd7980302961.tar.bz2
perlweeklychallenge-club-bd1fbb984c32aa285b93bf30b0bcbd7980302961.zip
Merge pull request #3293 from aaronreidsmith/challenge-095
Week 95 - Raku
Diffstat (limited to 'challenge-095')
-rw-r--r--challenge-095/aaronreidsmith/blog.txt1
-rw-r--r--challenge-095/aaronreidsmith/raku/ch-1.raku25
-rw-r--r--challenge-095/aaronreidsmith/raku/ch-2.raku54
3 files changed, 80 insertions, 0 deletions
diff --git a/challenge-095/aaronreidsmith/blog.txt b/challenge-095/aaronreidsmith/blog.txt
new file mode 100644
index 0000000000..9e8e69d622
--- /dev/null
+++ b/challenge-095/aaronreidsmith/blog.txt
@@ -0,0 +1 @@
+https://aaronreidsmith.github.io/blog/perl-weekly-chellanege-095/
diff --git a/challenge-095/aaronreidsmith/raku/ch-1.raku b/challenge-095/aaronreidsmith/raku/ch-1.raku
new file mode 100644
index 0000000000..9ccf1be553
--- /dev/null
+++ b/challenge-095/aaronreidsmith/raku/ch-1.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+sub challenge(Int $N) {
+ ($N.Str.flip eq $N.Str).Int;
+}
+
+multi sub MAIN(Int $N) {
+ say challenge($N);
+}
+
+multi sub MAIN(Bool :$test) {
+ use Test;
+
+ my @tests = (
+ (1221, 1),
+ (-101, 0),
+ (90, 0)
+ );
+
+ for @tests -> ($N, $expected) {
+ is(challenge($N), $expected);
+ }
+
+ done-testing;
+}
diff --git a/challenge-095/aaronreidsmith/raku/ch-2.raku b/challenge-095/aaronreidsmith/raku/ch-2.raku
new file mode 100644
index 0000000000..eacacb12bb
--- /dev/null
+++ b/challenge-095/aaronreidsmith/raku/ch-2.raku
@@ -0,0 +1,54 @@
+#!/usr/bin/env raku
+
+class Stack {
+ has @!internal-state of Int;
+
+ method push(Int $elem --> True) {
+ @!internal-state.push($elem);
+ }
+
+ method pop() returns Int {
+ if @!internal-state.elems == 0 {
+ warn "Cannot pop an empty stack!";
+ } else {
+ @!internal-state.pop;
+ }
+ }
+
+ method top returns Int {
+ if @!internal-state.elems == 0 {
+ warn "Cannot find top of empty stack!";
+ } else {
+ @!internal-state.tail;
+ }
+ }
+
+ method min returns Int {
+ if @!internal-state.elems == 0 {
+ warn "Cannot find minimum of empty stack!";
+ } else {
+ @!internal-state.min;
+ }
+ }
+
+ method Str returns Str {
+ "({@!internal-state.join(', ')}) <-- Top";
+ }
+}
+
+sub MAIN(*@push where all(@push) ~~ Int, Int :$pop = 2) {
+ # Can't put a default on "slurpy" args, so this is our work around
+ @push = @push.elems > 0 ?? @push !! (1, 2, 3, 4);
+
+ my $stack = Stack.new;
+ for @push -> $elem {
+ $stack.push($elem);
+ }
+ say " Stack after pushing: $stack";
+ for ^$pop {
+ $stack.pop();
+ }
+ say " Stack after popping: $stack";
+ say " Top element of stack: {$stack.top}";
+ say "Minimum element of stack: {$stack.min}";
+}