diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-13 00:51:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-13 00:51:16 +0000 |
| commit | e7f0aa1bf68abe377e5ca87e82cfbd55c4488c6a (patch) | |
| tree | cf31fd1b7c079fc10d41e35133a36c5e6c83f95a | |
| parent | 39a5e6f0a632a7da892affffeb83dd1c94f6bc47 (diff) | |
| parent | 0b4ca439c671315dd9f9bfae6e0f57f7469569f2 (diff) | |
| download | perlweeklychallenge-club-e7f0aa1bf68abe377e5ca87e82cfbd55c4488c6a.tar.gz perlweeklychallenge-club-e7f0aa1bf68abe377e5ca87e82cfbd55c4488c6a.tar.bz2 perlweeklychallenge-club-e7f0aa1bf68abe377e5ca87e82cfbd55c4488c6a.zip | |
Merge pull request #3239 from nunovieira220/challenge-095
Add solution to challenge 095
| -rw-r--r-- | challenge-095/nunovieira220/js/ch-1.js | 9 | ||||
| -rw-r--r-- | challenge-095/nunovieira220/js/ch-2.js | 37 | ||||
| -rw-r--r-- | challenge-095/nunovieira220/perl/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-095/nunovieira220/perl/ch-2.pl | 55 |
4 files changed, 118 insertions, 0 deletions
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 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 |
