diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2021-01-16 10:56:15 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2021-01-16 10:56:15 +0100 |
| commit | 4b33fafb8879536097affca8624f1a901793fea6 (patch) | |
| tree | 8f75d4ede8cda049eb5749b9143d029a5035831f /challenge-095/lubos-kolouch/python | |
| parent | abca1675f01662e3888446898e0a327f46f27afa (diff) | |
| download | perlweeklychallenge-club-4b33fafb8879536097affca8624f1a901793fea6.tar.gz perlweeklychallenge-club-4b33fafb8879536097affca8624f1a901793fea6.tar.bz2 perlweeklychallenge-club-4b33fafb8879536097affca8624f1a901793fea6.zip | |
Python solutions
Diffstat (limited to 'challenge-095/lubos-kolouch/python')
| -rw-r--r-- | challenge-095/lubos-kolouch/python/ch-1.py | 30 | ||||
| -rw-r--r-- | challenge-095/lubos-kolouch/python/ch-2.py | 70 |
2 files changed, 100 insertions, 0 deletions
diff --git a/challenge-095/lubos-kolouch/python/ch-1.py b/challenge-095/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..f6795dc1b2 --- /dev/null +++ b/challenge-095/lubos-kolouch/python/ch-1.py @@ -0,0 +1,30 @@ +#!env python +""" +# =============================================================================== +# +# FILE: ch_2.py +# +# USAGE: ./ch_2.py +# +# DESCRIPTION: Perl Weekly Challenge #095 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/ +# Palindrome Number +# +# AUTHOR: Lubos Kolouch +# CREATED: 01/13/2021 02:39:16 PM +#=============================================================================== +""" + + +def is_palindrome(what: int): + """ test the palindrome """ + + # the 0+ is to avoid situations like 0000123 + return str(what+0) == str(what+0)[::-1] + + +def test_numbers(): + """ Tests """ + assert is_palindrome(1221) == 1 + assert is_palindrome(-101) == 0 + assert is_palindrome(90) == 0 diff --git a/challenge-095/lubos-kolouch/python/ch-2.py b/challenge-095/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..8be6bda569 --- /dev/null +++ b/challenge-095/lubos-kolouch/python/ch-2.py @@ -0,0 +1,70 @@ +#!env python +""" +# =============================================================================== +# +# FILE: ch_2.py +# +# USAGE: ./ch_2.py +# +# DESCRIPTION: Perl Weekly Challenge #095 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/ +# Demo Stack +# +# AUTHOR: Lubos Kolouch +# CREATED: 01/13/2021 02:39:16 PM +#=============================================================================== +""" + + +class Stack: + """ Class to the stack """ + + def __init__(self): + self.stack = [] + + def push(self, value: int): + """ Demostrate push """ + self.stack.insert(0, value) + + @property + def pop(self): + """ Demonstrate pop """ + + try: + return self.stack.pop(0) + except IndexError: + return None + + @property + def top(self): + """ Demonstrate top """ + + return self.stack[0] + + @property + def stack_min(self): + """ Demostrate min """ + + return min(self.stack) + + +def test_cases(): + """ Test cases """ + + stack = Stack() + assert stack.pop == None + + stack.push(2) + assert stack.top == 2 + + stack.push(-1) + assert stack.top == -1 + + stack.push(0) + assert stack.top == 0 + + assert stack.pop == 0 + assert stack.top == -1 + + stack.push(0) + assert stack.stack_min == -1 |
