RE: RE: Maths Brain Teasers 62:: Adding up to 1k - Can You Solve iT?
You are viewing a single comment's thread from:

RE: Maths Brain Teasers 62:: Adding up to 1k - Can You Solve iT?

Words
58
Reading
1 min
Listen
Play
6y

Wrote a quick script in Python to find all of the possible solutions:

(21, 64, 126, 373, 416)
and
(64, 66, 126, 328, 416)

EDIT: only (21, 64, 126, 373, 416) because I misread/mistyped 382 as 328 in my code. Thanks for spotting that minus-pi@minus-pi


Not my best code, but if you are curious, here it is

import itertools
numbers = [373,135,30,375,126,411,416,64,73,382,66,128,418,21,23,425] 

def hasDuplicate(list):
    existingNums = []
    for num in list:
        if num in existingNums:
            return True
        else:
            existing_nums.append(num)
    return False


ways = []
for choice in itertools.product(numbers, repeat=5):
    if sum(choice) == 1000:
        if not hasDuplicate(choice):
            if sorted(choice) not in ways:
                print(sorted(choice))
                ways.append(sorted(choice))

@roboticmind: Wrote a quick | Ecency