From ef60f41180fee0e36c1aa2ddd4f315738c2156f0 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 13 Jan 2021 00:49:06 +0000 Subject: Add nunovieira220 perl solution to challenge 095 --- challenge-095/nunovieira220/perl/ch-1.pl | 17 ++++++++++ challenge-095/nunovieira220/perl/ch-2.pl | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 challenge-095/nunovieira220/perl/ch-1.pl create mode 100644 challenge-095/nunovieira220/perl/ch-2.pl 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 -- cgit From 0b4ca439c671315dd9f9bfae6e0f57f7469569f2 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 13 Jan 2021 00:49:18 +0000 Subject: Add nunovieira220 js solution to challenge 095 --- challenge-095/nunovieira220/js/ch-1.js | 9 +++++++++ challenge-095/nunovieira220/js/ch-2.js | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 challenge-095/nunovieira220/js/ch-1.js create mode 100644 challenge-095/nunovieira220/js/ch-2.js diff --git a/challenge-095/nunovieira220/js/ch-1.js b/challenge-095/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..9b1f3141e5 --- /dev/null +++ b/challenge-095/nunovieira220/js/ch-1.js @@ -0,0 +1,9 @@ +// Input +const num = 1221; + +// Palindrome Number +const numStr = `${num}`; +const res = numStr === numStr.split('').reverse().join('') ? 1 : 0; + +// Output +console.log(res); \ No newline at end of file diff --git a/challenge-095/nunovieira220/js/ch-2.js b/challenge-095/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..cb08c08503 --- /dev/null +++ b/challenge-095/nunovieira220/js/ch-2.js @@ -0,0 +1,37 @@ +// Stack class +class Stack { + constructor() { + this.stack = []; + } + + push(elem) { + this.stack.push(elem); + } + + pop() { + return this.stack.pop(); + } + + top() { + return this.stack[this.stack.length - 1]; + } + + min() { + return Math.min(...this.stack); + } + + toString() { + console.log(this.stack); + } +} + +// Input +const stack = new Stack(); +stack.push(2); +stack.push(-1); +stack.push(0); +stack.pop(); // removes 0 +console.log(stack.top()); // prints -1 +stack.push(0); +console.log(stack.min()); // prints -1 +stack.toString(); \ No newline at end of file -- cgit