aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-095/pavel_kuptsov/perl/ch-1.pl48
-rw-r--r--challenge-095/pavel_kuptsov/perl/ch-2.pl93
2 files changed, 141 insertions, 0 deletions
diff --git a/challenge-095/pavel_kuptsov/perl/ch-1.pl b/challenge-095/pavel_kuptsov/perl/ch-1.pl
new file mode 100644
index 0000000000..2929681dc3
--- /dev/null
+++ b/challenge-095/pavel_kuptsov/perl/ch-1.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More;
+=head2
+TASK #1 › Palindrome Number
+Submitted by: Mohammad S Anwar
+You are given a number $N.
+
+Write a script to figure out if the given number is Palindrome. Print 1 if true otherwise 0.
+
+Example 1:
+Input: 1221
+Output: 1
+Example 2:
+Input: -101
+Output: 0, since -101 and 101- are not the same.
+Example 3:
+Input: 90
+Output: 0
+
+=cut
+
+=head2 is_palindrome_number($N)
+
+
+
+=cut
+sub is_palindrome_number
+{
+ my $n = shift;
+ return 0 if $n < 0;
+ return 1 if ($n == reverse $n);
+ return 0;
+}
+
+for my $p( qw(0 1221 3443 5665) )
+{
+ ok(is_palindrome_number($p) == 1 );
+}
+
+for my $p( qw(-101 1234 5678 90) )
+{
+ ok(is_palindrome_number($p) == 0 );
+}
+
+done_testing(8); \ No newline at end of file
diff --git a/challenge-095/pavel_kuptsov/perl/ch-2.pl b/challenge-095/pavel_kuptsov/perl/ch-2.pl
new file mode 100644
index 0000000000..cfd9e7067b
--- /dev/null
+++ b/challenge-095/pavel_kuptsov/perl/ch-2.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use feature qw(say);
+use List::Util qw();
+use Test::More;
+
+=head2
+TASK #2 › Demo Stack
+Submitted by: Mohammad S Anwar
+Write a script to demonstrate Stack operations like below:
+
+push($n) - add $n to the stack
+pop() - remove the top element
+top() - get the top element
+min() - return the minimum element
+
+my $stack = Stack->new;
+$stack->push(2);
+$stack->push(-1);
+$stack->push(0);
+$stack->pop; # removes 0
+print $stack->top; # prints -1
+$stack->push(0);
+print $stack->min; # prints -1
+
+=cut
+
+
+my @stack = ();
+
+=head2 push($N)
+
+push($n) - add $n to the stack
+
+=cut
+sub push
+{
+ CORE::push @stack, $_[0];
+}
+
+
+=head2 pop($N)
+
+pop() - remove the top element
+
+=cut
+sub pop
+{
+ return CORE::pop @stack;
+}
+
+
+=head2 top($N)
+
+top() - get the top element
+
+=cut
+sub top
+{
+ return $stack[-1];
+}
+
+
+=head2 min($N)
+
+min() - return the minimum element
+
+=cut
+sub min
+{
+ return List::Util::min @stack;
+}
+
+main::push 10;
+main::push -1;
+main::push 0;
+
+ok( scalar @stack == 3 );
+
+main::pop;
+
+ok( scalar @stack == 2 );
+ok( $stack[-1] == -1 );
+ok( main::top == -1 );
+
+main::push 0;
+
+ok( main::min == -1 );
+
+
+done_testing(5); \ No newline at end of file