We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #240: Top Dice
Project Euler #240: Top Dice
Sort by
recency
|
16 Discussions
|
Please Login in order to post a comment
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))
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):
for i in product(l, repeat= n1):
print (c)
Is it guranteed to be resolved in slow Python?
See code below
As a general question - is it guaranteed that this can be solved using Python without timing out?
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 ?