aboutsummaryrefslogtreecommitdiff
path: root/challenge-048/user-person/python
diff options
context:
space:
mode:
authoruser-person <usermanperson+github@gmail.com>2020-02-22 18:07:44 -0500
committeruser-person <usermanperson+github@gmail.com>2020-02-22 18:07:44 -0500
commit9762f99660c3ac6bd21ad8e6a1ee28d558ef127f (patch)
tree507616c097d470225759635d1853f7f7412b56f7 /challenge-048/user-person/python
parent5538168ffe1104ff3b90a97f0ba6b66eb2af8cd8 (diff)
downloadperlweeklychallenge-club-9762f99660c3ac6bd21ad8e6a1ee28d558ef127f.tar.gz
perlweeklychallenge-club-9762f99660c3ac6bd21ad8e6a1ee28d558ef127f.tar.bz2
perlweeklychallenge-club-9762f99660c3ac6bd21ad8e6a1ee28d558ef127f.zip
.DS_Store unnecessary.
Diffstat (limited to 'challenge-048/user-person/python')
-rwxr-xr-xchallenge-048/user-person/python/ch-1.py61
-rwxr-xr-xchallenge-048/user-person/python/ch-2.py74
2 files changed, 135 insertions, 0 deletions
diff --git a/challenge-048/user-person/python/ch-1.py b/challenge-048/user-person/python/ch-1.py
new file mode 100755
index 0000000000..11f9da380e
--- /dev/null
+++ b/challenge-048/user-person/python/ch-1.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+###########################################################################
+# script name: ch-1.py #
+# Tue Feb 18 21:13:07 2020 | 1582078387 #
+# jtangele+python@gmail.com #
+# #
+# 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. #
+# #
+###########################################################################
+
+from optparse import OptionParser
+
+parser = OptionParser()
+
+parser.add_option("-v","--verbose",action="store_true", dest="verbose")
+(options, args) = parser.parse_args()
+
+circle = list(range(1,51))
+
+i = 1
+
+while len(circle) > 1:
+
+ if options.verbose:
+ print ("i : ",i)
+
+ victim = circle.pop(i)
+
+ if options.verbose:
+ print(circle[i-1], " killed ", victim)
+ print(*circle, sep =" ")
+ print()
+
+ # When the end of the array is reached,
+ # roll back the index to go back around the circle for another iteration.
+ # In odd cases the next victim will be 0. In even cases it will be 1.
+ # These have to be adjusted due to the for loop's incrementing -1 for odd, 0 for even.
+
+ if (len(circle)-1) - i == 0:
+ i = -1
+
+ elif (len(circle)-1) - i == -1 :
+ i = 0
+
+ i += 1
+
+print(*circle, " survives")
+
+# output:
+#
+# 37 survives
diff --git a/challenge-048/user-person/python/ch-2.py b/challenge-048/user-person/python/ch-2.py
new file mode 100755
index 0000000000..e7d287ee4d
--- /dev/null
+++ b/challenge-048/user-person/python/ch-2.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+
+###########################################################################
+# script name: ch-2.py #
+# Tue Feb 18 23:48:19 2020 | 1582087699 #
+# jtangele+python@gmail.com #
+# #
+# #
+# 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. #
+# #
+###########################################################################
+
+# M M D D Y Y Y Y
+# [01][*][012][2][2][012][*][01]
+# k j i i j k
+#
+# k - Months can only begin with 0 or 1.
+# j - The second months digit needs all numbers e.g. January 01 to October 10 (and of course beyond).
+# i - Days begin with 0,1,2,3, However all years begin with 2 so the corresponding number
+# means all days end in 2. 32 is not a valid day so the 3 is not needed.
+
+for i in range(3):
+ for j in range(10):
+ for k in range(2):
+ if (k == 1 and j > 2) or (k == 0 and j == 0):
+ continue
+ print(k,j,"-",i,"2-2",i,j,k,sep='')
+ k += 1
+ j += 1
+ i += 1
+
+# output:
+#
+# 10-02-2001
+# 01-02-2010
+# 11-02-2011
+# 02-02-2020
+# 12-02-2021
+# 03-02-2030
+# 04-02-2040
+# 05-02-2050
+# 06-02-2060
+# 07-02-2070
+# 08-02-2080
+# 09-02-2090
+# 10-12-2101
+# 01-12-2110
+# 11-12-2111
+# 02-12-2120
+# 12-12-2121
+# 03-12-2130
+# 04-12-2140
+# 05-12-2150
+# 06-12-2160
+# 07-12-2170
+# 08-12-2180
+# 09-12-2190
+# 10-22-2201
+# 01-22-2210
+# 11-22-2211
+# 02-22-2220
+# 12-22-2221
+# 03-22-2230
+# 04-22-2240
+# 05-22-2250
+# 06-22-2260
+# 07-22-2270
+# 08-22-2280
+# 09-22-2290