aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo L. de M. Chaves <gustavo@cpqd.com.br>2021-01-11 21:10:04 -0300
committerGustavo L. de M. Chaves <gustavo@cpqd.com.br>2021-01-11 21:10:04 -0300
commite3c5cd9da79849dfa376e45d5a1dcf9579357363 (patch)
treed4a0dbe89422e2fb3875cace2ea3d3a0ac0ae3ab
parent5ab993f243ab1a835d8f30aa6c97b2d3b99496af (diff)
downloadperlweeklychallenge-club-e3c5cd9da79849dfa376e45d5a1dcf9579357363.tar.gz
perlweeklychallenge-club-e3c5cd9da79849dfa376e45d5a1dcf9579357363.tar.bz2
perlweeklychallenge-club-e3c5cd9da79849dfa376e45d5a1dcf9579357363.zip
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