aboutsummaryrefslogtreecommitdiff
path: root/challenge-211/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-04-09 19:01:48 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2023-04-09 19:01:48 +0100
commitc5c9938bcabccd143a967d74a9fc135beeee8002 (patch)
treeeb3fd8e67019cea8e1a1b30c8147478292025796 /challenge-211/sgreen/python/ch-2.py
parentf03ec2c10499edf8b77ea0c3831728853c20e983 (diff)
parent4890cd1addbde634e231ba6eb4656f7eb59085e9 (diff)
downloadperlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.tar.gz
perlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.tar.bz2
perlweeklychallenge-club-c5c9938bcabccd143a967d74a9fc135beeee8002.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-211/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-211/sgreen/python/ch-2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-211/sgreen/python/ch-2.py b/challenge-211/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..57226ad4bf
--- /dev/null
+++ b/challenge-211/sgreen/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+from itertools import combinations
+import sys
+
+
+def main(n):
+ # Calculate average
+ avg = sum(n) / len(n)
+
+ # A single element is always true
+ if len(n) == 1:
+ print('true')
+ return
+
+ # Consider combination of size 1 to half the length
+ for i in range(1, len(n)//2+1):
+ # Work through each combination
+ for c in combinations(n, i):
+ # If combination average is same, the remaining items also will be
+ if sum(c) / i == avg:
+ print('true')
+ return
+
+ print('false')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)