diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-04-07 02:46:40 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-04-07 02:46:40 +0100 |
| commit | c2b6029560590d89d87180533fc1187b1d6b476e (patch) | |
| tree | 058aa4065e82f23ba2c465cae5b5d278491f0ae8 /challenge-211/robert-dicicco/python | |
| parent | 846906295422d9dd845c61fdf8ae589d60306e90 (diff) | |
| download | perlweeklychallenge-club-c2b6029560590d89d87180533fc1187b1d6b476e.tar.gz perlweeklychallenge-club-c2b6029560590d89d87180533fc1187b1d6b476e.tar.bz2 perlweeklychallenge-club-c2b6029560590d89d87180533fc1187b1d6b476e.zip | |
- Added solutions by Luca Ferrari.
- Added solutions by Mark Anderson.
- Added solutions by Paulo Custodio.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
- Added solutions by Robbie Hatley.
- Added solutions by Jorg Sommrey.
- Added solutions by Roger Bell_West.
- Added solutions by Leo Manfredi.
- Added solutions by Arne Sommer.
- Added solutions by James Smith.
- Added solutions by Peter Meszaros.
- Added solutions by Ulrich Rieke.
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-211/robert-dicicco/python')
| -rw-r--r-- | challenge-211/robert-dicicco/python/ch-2.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/challenge-211/robert-dicicco/python/ch-2.py b/challenge-211/robert-dicicco/python/ch-2.py new file mode 100644 index 0000000000..9da6c150b6 --- /dev/null +++ b/challenge-211/robert-dicicco/python/ch-2.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +''' +---------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-04-04 +Challenge 211 Split Same Average ( Python ) +---------------------------------------- +''' +from itertools import combinations +import functools +import operator + +nums = [1,2,3,4,5,6,7,8] +flag = 0 + +for ndx in range(1,5): + print("Set size = ",ndx) + print("Input: @nums = ", nums) + mycheck = False + Set1 = set(nums) + for s2 in combinations(Set1,ndx): + Set2 = ((s2)) + Set3 = Set1.difference(Set2) + s2 = functools.reduce(operator.add, Set2)/len(Set2) + s3 = functools.reduce(operator.add, Set3)/len(Set3) + if s2 == s3: + print(Set2,' ',Set3,' ',s2,' ',s3) + flag = 1 + print("Output: true") if (flag==1) else print("output: false") + flag = 0 + + print('') + +''' +---------------------------------------- +SAMPLE OUTPUT +python .\SplitSame.py +Set size = 1 +Input: @nums = [1, 2, 3, 4, 5, 6, 7, 8] +output: false + +Set size = 2 +Input: @nums = [1, 2, 3, 4, 5, 6, 7, 8] +(1, 8) {2, 3, 4, 5, 6, 7} 4.5 4.5 +(2, 7) {1, 3, 4, 5, 6, 8} 4.5 4.5 +(3, 6) {1, 2, 4, 5, 7, 8} 4.5 4.5 +(4, 5) {1, 2, 3, 6, 7, 8} 4.5 4.5 +Output: true + +Set size = 3 +Input: @nums = [1, 2, 3, 4, 5, 6, 7, 8] +output: false + +Set size = 4 +Input: @nums = [1, 2, 3, 4, 5, 6, 7, 8] +(1, 2, 7, 8) {3, 4, 5, 6} 4.5 4.5 +(1, 3, 6, 8) {2, 4, 5, 7} 4.5 4.5 +(1, 4, 5, 8) {2, 3, 6, 7} 4.5 4.5 +(1, 4, 6, 7) {2, 3, 5, 8} 4.5 4.5 +(2, 3, 5, 8) {1, 4, 6, 7} 4.5 4.5 +(2, 3, 6, 7) {1, 4, 5, 8} 4.5 4.5 +(2, 4, 5, 7) {1, 3, 6, 8} 4.5 4.5 +(3, 4, 5, 6) {1, 2, 7, 8} 4.5 4.5 +Output: true +---------------------------------------- + + + +''' + + |
