diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-04-26 09:15:20 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-04-26 09:15:20 +0100 |
| commit | 03f28cae3ddea3b08a671dd3f20f3d32777aa4db (patch) | |
| tree | 7aea1f86e706cf8233d89d704ac2342a0c63d059 /challenge-109/abigail/python/ch-2.py | |
| parent | 46b8aecc9397c6211a1e97a7f0638833726294a2 (diff) | |
| parent | 1ff197d81f941c3dd35d77bec8a0326807e8d2b1 (diff) | |
| download | perlweeklychallenge-club-03f28cae3ddea3b08a671dd3f20f3d32777aa4db.tar.gz perlweeklychallenge-club-03f28cae3ddea3b08a671dd3f20f3d32777aa4db.tar.bz2 perlweeklychallenge-club-03f28cae3ddea3b08a671dd3f20f3d32777aa4db.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-109/abigail/python/ch-2.py')
| -rw-r--r-- | challenge-109/abigail/python/ch-2.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/challenge-109/abigail/python/ch-2.py b/challenge-109/abigail/python/ch-2.py new file mode 100644 index 0000000000..c17ac94211 --- /dev/null +++ b/challenge-109/abigail/python/ch-2.py @@ -0,0 +1,66 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +SIZE = 7 + +fmt = "{:d} {:d} {:d} {:d} {:d} {:d} {:d}" + +# +# Brute forcing all possiblities, with an early return +# +for line in fileinput . input (): + numbers = list (map (lambda x: int (x), line . split ())) + + for a_i in range (0, SIZE): + for b_i in range (0, SIZE): + if a_i == b_i: + continue + target = numbers [a_i] + numbers [b_i] + + for c_i in range (0, SIZE): + if c_i == a_i or c_i == b_i: + continue + + for d_i in range (0, SIZE): + if d_i == a_i or d_i == b_i or d_i == c_i: + continue + + if target != numbers [b_i] + numbers [c_i] + numbers [d_i]: + continue + + for e_i in range (0, SIZE): + if e_i == a_i or e_i == b_i or e_i == c_i or \ + e_i == d_i: + continue + + for f_i in range (0, SIZE): + if f_i == a_i or f_i == b_i or f_i == c_i or \ + f_i == d_i or f_i == e_i: + continue + if target != numbers [d_i] + numbers [e_i] + \ + numbers [f_i]: + continue + + for g_i in range (0, SIZE): + if g_i == a_i or g_i == b_i or g_i == c_i or \ + g_i == d_i or g_i == e_i or g_i == f_i: + continue + if target != numbers [f_i] + numbers [g_i]: + continue + + print (fmt . format (numbers [a_i], + numbers [b_i], + numbers [c_i], + numbers [d_i], + numbers [e_i], + numbers [f_i], + numbers [g_i])) |
