Project Euler #240: Top Dice

Sort by

recency

|

16 Discussions

|

  • + 0 comments

    Tricky problem. The most tricky part is to efficiently count the number of sums with given length knowing that each element must be bigger than smallest value (sv) in the top sum and every element must not be greater than maximum number on dice. Having calculated the number of these sums the rest is rather easy as the count for given length (gl) of elements greater than the smallest value in the top sum.

    number_of_sums * C(n, gl) * (C(n-k, 0) * (sv - 1)^0 + C(n-k, 1) * (sv- 1)^1 + C(n-k, 2) * (sv-1)^2 + ... + C(n-k, n - k) * (sv-1)^(n-k))

  • + 0 comments

    My program is giving correct output but the run time gets exceeded, please help in optimizing the code :)

    from itertools import product

    n1, n2, n3, n4 = map(int,input().split())

    l=[]

    c=0

    for i in range (n2):

    l.append(i+1)
    

    for i in product(l, repeat= n1):

    if (sum(sorted(i, reverse= True) [:n3]) == n4):
    
        c+=1
    

    print (c)

  • + 0 comments

    Is it guranteed to be resolved in slow Python?

    See code below

    string = input()
    n, d, m, s = tuple(map(int, string.split()))
    
    x = [l for l in range(1,d+1)]
    m = m * (-1) - 1
    z = [p for p in itertools.product(x, repeat=n) if sum(sorted(p)[:m:-1]) == s]
    print(len(z) % (10**9+7))
    
  • + 0 comments

    As a general question - is it guaranteed that this can be solved using Python without timing out?

  • + 0 comments

    My code working good in VSCODE but it is showing runtime error in the hacker rank editor. The answer for 'test case 0' is same i am getting by my code.

    Do we need to do all the import OS, file .write ....., and all ?