diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-02-22 10:59:43 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-02-22 10:59:43 +0100 |
| commit | 71a208ec3da5563438ccae7fe88e680d8bac5efe (patch) | |
| tree | 4eb511a322f414a6d647a64f6d158eb07c3458b0 /challenge-048 | |
| parent | d459492fdd0525806d026f85bbff80be0e58d76c (diff) | |
| download | perlweeklychallenge-club-71a208ec3da5563438ccae7fe88e680d8bac5efe.tar.gz perlweeklychallenge-club-71a208ec3da5563438ccae7fe88e680d8bac5efe.tar.bz2 perlweeklychallenge-club-71a208ec3da5563438ccae7fe88e680d8bac5efe.zip | |
Challenges 48 Python
Diffstat (limited to 'challenge-048')
| -rw-r--r-- | challenge-048/lubos-kolouch/python/ch-1.py | 52 | ||||
| -rw-r--r-- | challenge-048/lubos-kolouch/python/ch-2.py | 33 |
2 files changed, 85 insertions, 0 deletions
diff --git a/challenge-048/lubos-kolouch/python/ch-1.py b/challenge-048/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..2f3e0090e6 --- /dev/null +++ b/challenge-048/lubos-kolouch/python/ch-1.py @@ -0,0 +1,52 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.py +# +# USAGE: ./ch-1.py +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-048/ +# +# Survivor +# +# There are 50 people standing in a circle in position 1 to 50. The person standing at position 1 has a sword. He kills the next person i.e. standing at position 2 and pass on the sword to the immediate next i.e. person standing at position 3. Now the person at position 3 does the same and it goes on until only one survives. +# +# Write a script to find out the survivor. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 02/21/2020 09:15:59 PM +# REVISION: --- +#=============================================================================== + +from collections import deque + +def get_last_man_standing(count): + + people = deque(range(count)) + killed = 0 + switch = 0 + + while killed < count-1: + if switch == 0: + switch = 1 + people.rotate(-1) + else: + switch = 0 + people.popleft() + killed += 1 + + return people.popleft()+1 + +print(get_last_man_standing(50)) + +# TESTS + +assert(get_last_man_standing(50) == 37) +assert(get_last_man_standing(2) == 1) +assert(get_last_man_standing(3) == 3) diff --git a/challenge-048/lubos-kolouch/python/ch-2.py b/challenge-048/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..064cd8c831 --- /dev/null +++ b/challenge-048/lubos-kolouch/python/ch-2.py @@ -0,0 +1,33 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-2.py +# +# USAGE: ./ch-2.py +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-048/ +# +# Palindrome Dates +# +# Write a script to print all Palindrome Dates between 2000 and 2999. The format of date is mmddyyyy. For example, the first one was on October 2, 2001 as it is represented as 10022001. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: YOUR NAME (), +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 02/22/2020 10:11:25 AM +# REVISION: --- +#=============================================================================== + +from datetime import date, timedelta + +dt = date(2000,1,1) + +while dt.year < 3000: + dt += timedelta(days=1) + if dt.strftime("%m%d%Y") == dt.strftime("%m%d%Y")[::-1]: + print(dt) + |
