aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-12 01:12:10 +0000
committerGitHub <noreply@github.com>2021-01-12 01:12:10 +0000
commitdf43e3cc5c295537271b14c59a4e82c03908b162 (patch)
tree8ab366b08f0cf127127feae675277bb1846c591f
parentf223b1cd9a2464a1609bb2076eba3d13304bc0f3 (diff)
parente3c5cd9da79849dfa376e45d5a1dcf9579357363 (diff)
downloadperlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.tar.gz
perlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.tar.bz2
perlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.zip
Merge pull request #3229 from gnustavo/095
095 - Gustavo Chaves solutions
-rwxr-xr-xchallenge-095/gustavo-chaves/is-palindrome.pl11
-rwxr-xr-xchallenge-095/gustavo-chaves/stack.pl53
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-095/gustavo-chaves/is-palindrome.pl b/challenge-095/gustavo-chaves/is-palindrome.pl
new file mode 100755
index 0000000000..dd56d937c9
--- /dev/null
+++ b/challenge-095/gustavo-chaves/is-palindrome.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/
+# TASK #1 › Palindrome Number
+
+use 5.030;
+use warnings;
+
+my $N = shift;
+
+say $N eq reverse($N) ? 1 : 0;
diff --git a/challenge-095/gustavo-chaves/stack.pl b/challenge-095/gustavo-chaves/stack.pl
new file mode 100755
index 0000000000..6ddfaedd7a
--- /dev/null
+++ b/challenge-095/gustavo-chaves/stack.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/
+# TASK #2 › Demo Stack
+
+use 5.030;
+use warnings;
+use List::Util;
+
+package Stack {
+
+ sub new {
+ my $class = shift;
+
+ return bless [], $class;
+ }
+
+ sub push {
+ my ($self, $n) = @_;
+
+ push @$self, $n;
+ return;
+ }
+
+ sub pop {
+ my ($self) = @_;
+
+ return pop @$self;
+ }
+
+ sub top {
+ my ($self) = @_;
+
+ return $self->[-1];
+ }
+
+ sub min {
+ my ($self) = @_;
+
+ return List::Util::min @$self;
+ }
+
+};
+
+
+my $stack = Stack->new;
+$stack->push(2);
+$stack->push(-1);
+$stack->push(0);
+$stack->pop; # removes 0
+say $stack->top; # prints -1
+$stack->push(0);
+say $stack->min; # prints -1