diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2021-02-19 23:33:37 -0500 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2021-02-19 23:33:37 -0500 |
| commit | 0dd3d7133993d85c7126e28d2b0e601a3a417425 (patch) | |
| tree | 84d33d660aedd379b2f9b786423d969d406db4e5 | |
| parent | fd74e66af1b93c344ce8bc4076760538bc1d0651 (diff) | |
| download | perlweeklychallenge-club-0dd3d7133993d85c7126e28d2b0e601a3a417425.tar.gz perlweeklychallenge-club-0dd3d7133993d85c7126e28d2b0e601a3a417425.tar.bz2 perlweeklychallenge-club-0dd3d7133993d85c7126e28d2b0e601a3a417425.zip | |
Challenge 95 by Jaldhar H. Vyas
| -rw-r--r-- | challenge-095/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-095/jaldhar-h-vyas/perl/ch-1.sh | 1 | ||||
| -rwxr-xr-x | challenge-095/jaldhar-h-vyas/perl/ch-2.pl | 115 | ||||
| -rwxr-xr-x | challenge-095/jaldhar-h-vyas/raku/ch-1.sh | 1 | ||||
| -rwxr-xr-x | challenge-095/jaldhar-h-vyas/raku/ch-2.raku | 35 |
5 files changed, 153 insertions, 0 deletions
diff --git a/challenge-095/jaldhar-h-vyas/blog.txt b/challenge-095/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..ce98bf45af --- /dev/null +++ b/challenge-095/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2021/02/perl_weekly_challenge_week_95.html diff --git a/challenge-095/jaldhar-h-vyas/perl/ch-1.sh b/challenge-095/jaldhar-h-vyas/perl/ch-1.sh new file mode 100755 index 0000000000..e5564254dc --- /dev/null +++ b/challenge-095/jaldhar-h-vyas/perl/ch-1.sh @@ -0,0 +1 @@ +perl -E 'say $ARGV[0] eq reverse($ARGV[0]) ? 1 : 0;' $@
\ No newline at end of file diff --git a/challenge-095/jaldhar-h-vyas/perl/ch-2.pl b/challenge-095/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..48ee16664d --- /dev/null +++ b/challenge-095/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,115 @@ +#!/usr/bin/perl + +=head1 NAME + +Data::Stack - A Stack Demo + +=cut + +package Data::Stack; +use Moo; +use List::Util; +use namespace::clean; + +=head1 VERSION + +Version 0.1 + +=cut + +our $VERSION = '0.1'; + +=head1 SYNOPSIS + + my $stack = Data::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 + +=head1 DESCRIPTION + +This is a simple implementation of a stack. A stack is a data structure where +the items are added and removed in Last In First Out (LIFO) order. + +=cut + +has _stack => ( + is => 'rw', + default => sub { [] } +); + +=head2 METHODS + +=head3 push($value) + + Adds C<$value> onto the top of the stack. + +=cut + +sub push { + my ($self, $value) = @_; + + return push @{$self->_stack}, $value; +} + +=head3 pop() + + removes the value on top of the stack. + +=cut + +sub pop { + my ($self) = @_; + + return pop @{$self->_stack}; +} + +=head3 top() + + returns the top element in the stack without removing it. + +=cut + +sub top { + my ($self) = @_; + + return $self->_stack->[-1]; +} + +=head3 min() + + returns the minimum element in the stack. + +=cut + +sub min { + my ($self) = @_; + + return List::Util::min( @{$self->_stack} ); +} + +=head1 DEPENDENCIES + +L<List::Util>, L<Moo> + +=head1 BUGS + +None yet. + +=head1 AUTHOR + +Jaldhar H. Vyas, C<< <jaldhar at braincells.com> >> + +=head1 LICENSE AND COPYRIGHT + +Copyright 2021, Consolidated Braincells Inc. + +"Do what thou wilt" shall be the whole of the license. + +=cut + +1; diff --git a/challenge-095/jaldhar-h-vyas/raku/ch-1.sh b/challenge-095/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..bc76f94058 --- /dev/null +++ b/challenge-095/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1 @@ +raku -e 'say @*ARGS[0] eq @*ARGS[0].flip ?? 1 !! 0;' $@ diff --git a/challenge-095/jaldhar-h-vyas/raku/ch-2.raku b/challenge-095/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..677975029f --- /dev/null +++ b/challenge-095/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,35 @@ +#!/usr/bin/raku + +class Data::Stack { + + has Int @!stack = (); + + method push(Any $n) { + @!stack.push($n); + } + + method pop() { + return @!stack.pop; + } + + method top() { + return @!stack.tail; + } + + method min() { + return @!stack.min; + } +} + +# some random operations +sub MAIN() { + + my $stack = Data::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 +} |
