aboutsummaryrefslogtreecommitdiff
path: root/challenge-202/spadacciniweb/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-02-06 18:29:49 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-02-06 18:29:49 +0800
commit0f18fa3badcf6e6ddc58e793c868ce041054a496 (patch)
treead0b6ebe9b4b6b896475079163a282aec6b3fee3 /challenge-202/spadacciniweb/python/ch-1.py
parentb99b26aef8b033642ff3794f0fddf6deb3234b43 (diff)
parentf92e84261b474f81c014f4982268d6e2797b66d9 (diff)
downloadperlweeklychallenge-club-0f18fa3badcf6e6ddc58e793c868ce041054a496.tar.gz
perlweeklychallenge-club-0f18fa3badcf6e6ddc58e793c868ce041054a496.tar.bz2
perlweeklychallenge-club-0f18fa3badcf6e6ddc58e793c868ce041054a496.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-202/spadacciniweb/python/ch-1.py')
-rw-r--r--challenge-202/spadacciniweb/python/ch-1.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-202/spadacciniweb/python/ch-1.py b/challenge-202/spadacciniweb/python/ch-1.py
new file mode 100644
index 0000000000..ad098089c6
--- /dev/null
+++ b/challenge-202/spadacciniweb/python/ch-1.py
@@ -0,0 +1,44 @@
+# Task 1: Consecutive Odds
+# You are given an array of integers.
+# Write a script to print 1 if there are THREE consecutive odds in the given array otherwise print 0.
+#
+# Example 1
+# Input: @array = (1,5,3,6)
+# Output: 1
+#
+# Example 2
+# Input: @array = (2,6,3,5)
+# Output: 0
+#
+# Example 3
+# Input: @array = (1,2,3,4)
+# Output: 0
+#
+# Example 4
+# Input: @array = (2,3,5,7)
+# Output: 1
+
+import re
+import sys
+
+def is_odd(val):
+ if (int(val) % 2):
+ return 1
+ else:
+ return 0
+
+if __name__ == "__main__":
+ input = sys.argv[1:]
+ if (len(input) < 3 or
+ len(list(filter(lambda x: re.search(r'\D', x), input))) > 0 ):
+ sys.exit("Input error\n")
+
+ output = 0;
+ for i in range(len(input)-2):
+ if (is_odd(input[i]) and
+ is_odd(input[i+1]) and
+ is_odd(input[i+2])):
+ output = 1
+ break
+
+ print("Output: {:d}".format(output));