DEV Community


Weekly Challenge 095

simongreennet profile image Simon Green ・1 min read

Challenge 095

TASK #1 › Palindrome Number

You are given a number $N.

Write a script to figure out if the given number is Palindrome. Print 1 if true otherwise 0.

My solution

This seems pretty straight forward. Check the input is a number, then say 1 if $N and reverse($N) are the same, otherwise 0.

There are probably some edge cases should be thought about if this was the real world. For example, would you consider '121.0' palindromic, because 121 is?


» ./ 1221

» ./ -101

» ./ 90

» ./ 12.21
Enter fullscreen mode Exit fullscreen mode

TASK #2 › Demo Stack

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 solution

As someone who has written a fair amount of object orientated Perl, this task was also pretty straight forward. I have a stock standard class where new blesses the object and defines the $self->{stack} variable to hold the stack.

I then have methods for the four functions (push, pop, top and min) that do what you would expect them to do.


» ./
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Editor guide