[ create a new paste ] login | about

Link: http://codepad.org/rdSirAkD    [ raw code | output | fork ]

Ruby, pasted on Oct 10:
# greplin challenge problem 3
# by g0

set = 3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99

# Count subsets
def find(sq, sum, start=0)
    nos=0
    return 0 if sum < sq[0]
    nos = 1 if sq.include?(sum)

    for item in sq[start..-1] do
        break if item >= sum/2 # pegion hole
        start +=1
        nos += find(sq, sum-item, start)
    end
    return nos
end

count = 0

for i in set do
    count += (find(set, i) - 1)
end

puts count


Output:
1
179


Create a new paste based on this one


Comments: