From e3c5cd9da79849dfa376e45d5a1dcf9579357363 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Mon, 11 Jan 2021 21:10:04 -0300 Subject: 095 - Gustavo Chaves solutions --- challenge-095/gustavo-chaves/is-palindrome.pl | 11 ++++++ challenge-095/gustavo-chaves/stack.pl | 53 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 challenge-095/gustavo-chaves/is-palindrome.pl create mode 100755 challenge-095/gustavo-chaves/stack.pl 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 -- cgit