0

I write a program in python to find no of combinations of series

there is one dice which has 6 faces.

user input 2

then the out is shown is as no of count where two is come in combinations

ex if we throw dice for to get 2 as sum the maximum are two dice thrown are required

(1+1) and (2) so count is 2

if i throw for sum of 3, the out-put is

(1+1+1),(1+2),(2+1),(3) so count is 4 enter code here

if i throw for sum of 4 then the out put is

(1+1+1+1),(1+1+2),(1+2+1),(2+1+1),(2+2),(3+1),(1+3),(4) count is 8

I write the code is

# I am considering the Board is horizontal single line

def count_values(values,num):
    for i in range(num):
        print(values[i]," ",end='')
    print('')

def print_list(out_put,values,num,count=0,show=False):
    dice=6
    if num == 0:
        count_values(values,count) 
        out_put[0] += 1
    elif num > 0:
        for k in range(1,dice+1):
            values[count] = k
            print_list(out_put,values,num-k, count+1,show)

n=int(input('Enter A number'))

values=[0]*n
out_put=[0]
print_list(out_put,values,n)
print(out_put)

it shows out put for small inputs likes 10,20,30 but i want the out put for 100 and 500 and 610 like inputs , but is get more time (around 5-6 hours still running) and the count of combination is more than 1145201564 still it is counting any one has solution for this

Any one has any solution. for this

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
Sagar T
  • 89
  • 1
  • 1
  • 11
  • It looks like you're counting [partitions](https://en.wikipedia.org/wiki/Partition_(number_theory)). If you need to generate them as well, see [this question](https://stackoverflow.com/questions/400794/generating-the-partitions-of-a-number) – Patrick Haugh Oct 06 '17 at 16:06
  • Thank you for suggestion. but i got a solution by using numpy library, it give out put very fast – Sagar T Oct 07 '17 at 06:24

1 Answers1

0
import numpy

def findway(m,n,x):
    table = numpy.zeros((2,x+1))
    for j in range(1,x+1):
            table[1][j] = 1

    for j in range(1,x+1):
            for k in range(1,j):
                    table[1,j] += table[1][j-k]

    print table[1][x]

n=input('Enter a number')
findway(6,1,n)

but here is also one problem, i want out put for 600 ,but it shows out-put in format (2.07475778444e+180) but i want in integer format

Sagar T
  • 89
  • 1
  • 1
  • 11