| Σ | Face Values | # |
| 3 | (1,1,1)* | 1 |
| 4 | (1,1,2)+ | 3 |
| 5 | (1,1,3)+ (1,2,2)+ | 6 |
| 6 | (1,1,4)+ (1,2,3)- (2,2,2)* | 10 |
| 7 | (1,1,5)+ (1,2,4)- (1,3,3)+ (2,2,3)+ | 15 |
| 8 | (1,1,6)+ (1,2,5)- (1,3,4)- (2,2,4)+ (2,3,3)+ | 21 |
| 9 | (1,2,6)- (1,3,5)- (1,4,4)+ (2,2,5)+ (2,3,4)- (3,3,3)* | 25 |
| 10 | (1,3,6)- (1,4,5)- (2,2,6)+ (2,3,5)- (2,4,4)+ (3,3,4)+ | 27 |
| 11 | (1,4,6)- (1,5,5)+ (2,3,6)- (2,4,5)- (3,3,5)+ (3,4,4)+ | 27 |
| 12 | (1,5,6)- (2,4,6)- (2,5,5)+ (3,4,5)- (3,3,6)+ (4,4,4)* | 25 |
| 13 | (1,6,6)+ (2,5,6)- (3,4,6)- (3,5,5)+ (4,4,5)+ | 21 |
| 14 | (2,6,6)+ (3,5,6)- (4,4,6)+ (4,5,5)+ | 15 |
| 15 | (3,6,6)+ (4,5,6)- (5,5,5)* | 10 |
| 16 | (4,6,6)+ (5,5,6)+ | 6 |
| 17 | (5,6,6)+ | 3 |
| 18 | (6,6,6)* | 1 |
| TOTAL OUTCOMES | 216 | |
| Keys | * == unique (#1), + == 3! / 2! (#3) , - == 3! (#6) |
import java.util.* ;
int [] sumOfThree = new int[19] ;
void setup() {
// 3 dice summation simulation
for (int d1 = 1 ; d1 < 7 ; d1++) {
for(int d2 = 1 ; d2 < 7 ; d2++) {
for (int d3 = 1 ; d3 < 7 ; d3++) {
int sum = (d1 + d2 + d3) ;
sumOfThree[sum]++ ;
}
}
}
for(int i = 3 ; i < 19 ; i++) {
println("Sum ",i,"# outcomes",sumOfThree[i]) ;
}
// Group sum outcomes together and check if the are equally distrubuted
// Note all these groups should be the same - 6 groups of 36 (216 outcomes - throwing 3 dice)
println("Group 1", sumOfThree[3] + sumOfThree[6] + sumOfThree[9]) ;
println("Group 2",sumOfThree[18] + sumOfThree[15] + sumOfThree[12]) ;
println("Group 3",sumOfThree[4] + sumOfThree[5] + sumOfThree[10]) ;
println("Group 4",sumOfThree[17] + sumOfThree[16] + sumOfThree[11]) ;
println("Group 5",sumOfThree[7] + sumOfThree[8]) ;
println("Group 6",sumOfThree[13] + sumOfThree[14]) ;
// Generate a HashMap which maps sum of 3 dice to a single die throw outcome.
// We have noted that the 3 dice 'summation' outcomes can be split into
// the groups (3,6,9), (4,5,10), (7,8), (13,14) (11,16,17), (12,15,18)
// with each of these SIX groups adding up to 36.
Map<Integer,Integer> singleThrow = new HashMap() ;
// Throw 1
singleThrow.put(3,1) ; singleThrow.put(6,1) ; singleThrow.put(9,1) ;
// Throw 2
singleThrow.put(18,2) ; singleThrow.put(15,2) ; singleThrow.put(12,2) ;
// Throw 3
singleThrow.put(4,3) ; singleThrow.put(5,3) ; singleThrow.put(10,3) ;
// Throw 4
singleThrow.put(17,4) ; singleThrow.put(16,4) ; singleThrow.put(11,4) ;
// Throw 5
singleThrow.put(7,5) ; singleThrow.put(8,5) ;
// Throw 6
singleThrow.put(14,6) ; singleThrow.put(13,6) ;
// We now have a new map which maps the sum of 3 dice to a single die outcome.
// go through all 216 outcomes and make sure that our 'roll' comes out evenly distributed.
int [] roll = new int[7] ;
for (int d1 = 1 ; d1 < 7 ; d1++) {
for(int d2 = 1 ; d2 < 7 ; d2++) {
for (int d3 = 1 ; d3 < 7 ; d3++) {
int sum = (d1 + d2 + d3) ;
int die = singleThrow.get(sum) ;
roll[die - 1]++ ;
}
}
}
for(int i = 0 ; i < 6 ; i++) {
println("Die Face ",(i + 1),"Outcomes of of 216 = ",roll[i], "Pass:", roll[i] == 36) ;
}
exit() ;
}
No comments:
Post a Comment