Groovy web console

subscribe to the feed Subscribe
to this
site
hitos dice probability (via #groovywebconsole)
tweet this snippet Tweet
this
script

hitos dice probability

Published 5 months ago by leno with tags dice;proba
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
Map count = [:].withDefault{0}
int iter= 0
(1..10).each{ i ->
(1..10).each{ j ->
(1..10).each{ k ->
    int[] diceRoll = [i,j,k].sort()
    count[diceRoll[1]]++
    iter++
}}}
count.each{ result, nb ->
    int p = Math.round(100*nb/iter)
    println "${result}".padRight(2)+":"+"${p}% ".padLeft(5)+"".padLeft(p, '+')
}
println "CHECKSUM: ${count.values().sum()}/${iter} dice combinations : ${count}"