aboutsummaryrefslogtreecommitdiff
path: root/challenge-172/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-10 11:49:38 +0100
committerGitHub <noreply@github.com>2022-07-10 11:49:38 +0100
commitbd27693f67067b9fab3a7de9b8b51848b41ab0c7 (patch)
tree4602df187521d15dc110d26f0f0462ddf127397f /challenge-172/sgreen/python/ch-2.py
parentcc8580c1e95075ef7098044a075b037762ffd09a (diff)
parent72aca2620e73ef772c725fd927e56960ef2fa964 (diff)
downloadperlweeklychallenge-club-bd27693f67067b9fab3a7de9b8b51848b41ab0c7.tar.gz
perlweeklychallenge-club-bd27693f67067b9fab3a7de9b8b51848b41ab0c7.tar.bz2
perlweeklychallenge-club-bd27693f67067b9fab3a7de9b8b51848b41ab0c7.zip
Merge pull request #6412 from simongreen-net/master
sgreen solutions to challenge 172
Diffstat (limited to 'challenge-172/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-172/sgreen/python/ch-2.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-172/sgreen/python/ch-2.py b/challenge-172/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..c9162d1604
--- /dev/null
+++ b/challenge-172/sgreen/python/ch-2.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+import sys
+
+
+def get_value(l, quart):
+ # Calculate the position of the value we require
+ pos = (len(l)-1) * quart / 100
+ i = int(pos)
+
+ if i == pos:
+ # It is a single value
+ return l[i]
+
+ # We need the average of two numbers
+ val = (l[i] + l[i+1]) / 2
+ return int(val) if int(val) == val else val
+
+
+def main(l):
+
+ # Sort the list
+ l = sorted([int(x) for x in l])
+ solution = []
+
+ # Calculate the five values
+ for quart in range(0, 101, 25):
+ solution.append(get_value(l, quart))
+
+ print(*solution, sep=', ')
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])