Algorithm suggestion -


i'm looking best way accomplish following tasks:

given 4 non-repeatable numbers between 1 , 9.
given 2 numbers between 1 , 6.

adding 2 numbers (1 6), check see if there way make same number using 4 non-repeatable numbers (1 9), plus may not have use 4 numbers.

example:
4 non-repeatable (1 9) numbers are: 2, 4, 6, , 7
2 numbers between 1 , 6 are: 3 , 3

the total 2 numbers 3 + 3 = 6.

looking @ 4 non-repeatable (1 9) numbers, can make 6 in 2 different ways:
2 + 4 = 6
6 = 6

so, example returns "yes, there possible solution".

how accomplish task in efficient, cleanest way possible, algorithmic-ally.

enter code heresince number of elements here 4 should not worry efficiency. loop on 0 15 , use bit mask check valid results can generated. here code in python give idea.

a = [2,4,6,7] in range(16):     x =     ans = 0     j in range(4):         if(x%2):             ans += a[j]         x /= 2     print ans, 

0 2 4 6 6 8 10 12 7 9 11 13 13 15 17 19


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -