There is a certain game based in a D&D mechanics in which the player throws 4 perfect dices and sums the three bigger values to obtain his score. Which is the average value to be obtained after this game was played an infinity number of times?
I made a JAVA algorithm to solve with brute force. I obtained this:
+------------------------+ |Total average: 12.244598| +------------------------+ | Sum : Occurrence | | 1 : 0 | | 2 : 0 | | 3 : 1 | | 4 : 4 | | 5 : 10 | | 6 : 21 | | 7 : 38 | | 8 : 62 | | 9 : 91 | | 10 : 122 | | 11 : 148 | | 12 : 167 | | 13 : 172 | | 14 : 160 | | 15 : 131 | | 16 : 94 | | 17 : 54 | | 18 : 21 | +------------------------+
Code:
public class Test{ public static void main(String[] args) { float sum = 0; int[] results = new int[18]; for(int i=1;i<=6;i++) for(int j=1;j<=6;j++) for(int k=1;k<=6;k++) for(int l=1;l<=6;l++){ int result = i + j + k + l - Math.min(i, Math.min(j, Math.min(k, l))); sum += result; results[result-1]++; } System.out.println("+------------------------+"); System.out.println("|Total average: "+sum/(6*6*6*6)+"|"); System.out.println("+------------------------+"); System.out.println(" "+"Sum : Occurrence"); for(int i=0;i
But this method of resolution is computational inelegant. Can anyone solve it without the need of calculating all items from the tree of possibilities?
Computational method idea suggested by Matthew Conroy.