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
27
Reading
1 min
Listen
Play
6y

hehe, I think you made a similar copy&paste mistake than me :D
328 should be 382

You can use random.sample then you don't need to check for duplicates:

from random import sample
nums = [373, 135, 30, 375,
        126, 411, 416, 64,
        73, 382, 66, 128,
        418, 21, 23, 425]

sel = []
while sum(sel) != 1000:
    sel = sample(nums, 5)

print(sorted(sel))
@minus-pi: hehe, I think | Ecency