Project Euler #240: Top Dice

Sort by

recency

|

15 Discussions

|

  • + 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 ?

  • + 0 comments

    I don't understand. The example is working fine, but all of the other tests fails when I submit. What am I missing?