This is a Project Euler question, so no spoilers :]
I was going to try to solve it by first finding how many ways a certain sum can be acquired from a number of dice using IntegerPartitions
. For example, using two 6-sided dice, there is only one way to get a sum of 2.
IntegerPartitions[2, {2}, {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6}]
I expected the answer to be {1,1}
, but the output was {{1,1},{1,1},{1,1}}
. I'm really confused now. Am I not using the function properly? If so, is there some other way that I could achieve the required result?
Bam XD
s = 0; For[i = 9, i <= 36, i++, n1 = Length@ Flatten[(Permutations /@ IntegerPartitions[i, {9}, Range[4]]), 1]; For[j = 6, j < i, j++, n2 = Length@ Flatten[(Permutations /@ IntegerPartitions[j, {6}, Range[6]]), 1]; p = n1/4^9*n2/6^6; s = s + p]]; N[s]
IntegerPartitions[2, {2}, Range[6]]
? $\endgroup$IntegerPartitions[2, {3}, Range[6]]
does give{}
as required. $\endgroup$IntegerPartitions
is the right tool for this. Have you tried a brute force approach yet? $\endgroup$Tally
, which I what I used five years ago when I solved it. (I can't believe it's been so long!) You now have access to the forum solutions and many wonderful methods. I am partial to the coefficient based methods which as I recall I learned as a result of this problem or one like it. $\endgroup$