help converting algorithm to python code -


New in Python and I'm having trouble converting a script to another effective algorithm.

Here is the Python Code: #! / Usr / bin / env dragon import itertools target_sum = 10 a = 1b = 2 c = 4 a_range = range (0, target_sum + 1, a) b_range = range (0, target_sum + 1, b) c_range = range (0 , Target_sum + 1, c) itertools.product (a_range, b_range, c_range) for i, j, if i + j + k == 10: print a, ':', i / a, ',', b , ':', J / B, ',', 'C', ':', K / C

(This only makes 3 variables for example, but I end up having thousands I want to use it on the variable).

Here is the result that I see (all combo results are 10):

  1: 0, 2: 1, 4: 2 1: 0, 2: 3, 4: 1 1: 0, 2: 5, 4: 0 1: 2, 2: 0, 4: 2 1: 2, 2: 2, 4: 1 1: 2, 2: 4, 4: 0 1: 4, 2: 1, 4: 1 1: 4, 2: 3, 4: 0 1: 6, 2: 0, 4: 1 1: 6, 2: 2, 4: 0 1: 8, 2 A better algorithm was suggested in the question: 1, 4: 0 1: 10, 2: 0, 4: 0   

But the hard times in implementing logic inside the python Used to be. New test code: Convert # logic to # for i = 1 from k = z to z = 0: # for z = z / x_i: # if t [ Z - c * x_i] [i - 1] is true: there is no problem in creating tables ... not sure ifs matrix # set t [z] [i] to correct #set variable totals = 10 data = [1, 2, 4] # Trying to find all the different methods of combining data (I (data)) for the amount equal to: print (i) if i == 0: Z in zodiac (zodiac) A release: boundary for C. (z / i): print ("*" * 15) print ('z is equal to:', z) print ('c is equal to:', c) print ('i is equal to : ', I) print (z - c * i) print (' i - 1: ', (i - 1)) if (z - c * i) == (i - 1): print ("(z - C * I) * (i - 1) match! "Print (z, i)

sorry it is clearly very messy, I do not know how the table in the section Prepare:

  If T [z - c * x_i] [i - 1] is true: set t [z] [i] true   

While algo alters in other places, I have more problems It was because 'or I = 1 was changed in Python in lines like Kashmir, it tells me an error,' type error: 'int object is not doz' ''

Any help or suggestion is surprising I have learned syntax in Python but have not done anything with algorithms yet (so please sow with me).

Thanks in advance.

You can get the block that creates a table for dynamic programming in this way:

  will be default # t [x, i] It is true that if 'x' can be resolved by a linear combination of # [: i + 1] t = default detection (BULL) # All values ​​are incorrect T [0, 0] = true # Calculation in Figures i, x for base case: #I have index, range in x (zodiac + 1) Data is for [i]: boundary in C (S / X + 1): If T [S - C * x, I]: T [S, I + 1] = True   < / Div> 

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -