Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Algorithm

Name: Anonymous 2010-10-21 11:53

There's a n-element array of integers- 1 or 2.
We have to find subsequence which sum equals x.
How to do that ? I have no fucking idea.
Inb4 bruteforce

Name: Anonymous 2010-10-27 5:53

import random

def subsum(n, x):
    while True:
        pick = []
        for i in n:
            if random.randint(0, 1):
                pick.append(i)
        if sum(pick) == x:
            return pick


Best case O(n) algorithm!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List