diff options
| -rw-r--r-- | challenge-095/nunovieira220/perl/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-095/nunovieira220/perl/ch-2.pl | 55 |
2 files changed, 72 insertions, 0 deletions
diff --git a/challenge-095/nunovieira220/perl/ch-1.pl b/challenge-095/nunovieira220/perl/ch-1.pl new file mode 100644 index 0000000000..ff76bc3361 --- /dev/null +++ b/challenge-095/nunovieira220/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +# Input +my $num = 1221; + +# Palindrome Number +my $numStr = "$num"; +my $res = 0; + +$res = 1 if($numStr eq reverse $numStr); + +# Output +say($res);
\ No newline at end of file diff --git a/challenge-095/nunovieira220/perl/ch-2.pl b/challenge-095/nunovieira220/perl/ch-2.pl new file mode 100644 index 0000000000..97441a45cc --- /dev/null +++ b/challenge-095/nunovieira220/perl/ch-2.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +# Stack package +{ + package Stack; + + use List::Util; + + sub new { + my $class = shift; + my @arr = (); + + return bless \@arr, $class; + } + + sub push { + my ($self, $elem) = @_; + push @{$self}, $elem; + } + + sub pop { + my ($self) = @_; + return pop @{$self}; + } + + sub top { + my ($self) = @_; + return @{$self}[-1]; + } + + sub min { + my ($self) = @_; + return List::Util::min(@{$self}); + } + + sub toString { + my ($self) = @_; + say ("[", (join ",", @{$self}), "]"); + } +} + +# Input +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 +$stack->toString;
\ No newline at end of file |
