aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/abigail/python/ch-2.py
blob: c17ac942118281a4a00c7eb27be8a4a7f594ff0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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]))