17/03/05 11:59:20.94 h/zPOUa4.net
>>134 Squeak/Pharo Smalltalk
| dice |
dice := [:x :y |
| bag |
bag := Bag new.
(1 to: x) asDigitsToPower: y do: [:ary | bag add: ary sum].
bag sortedElements collect: [:kv | {kv key. kv value. kv value / bag size * 100s2}]
].
dice value: 6 value: 3
"=> {
{3 . 1 . 0.46s2}.
{4 . 3 . 1.38s2}.
{5 . 6 . 2.77s2}.
{6 . 10 . 4.62s2}.
{7 . 15 . 6.94s2}.
{8 . 21 . 9.72s2}.
{9 . 25 . 11.57s2}.
{10 27 12.50s2}.
{11 27 12.50s2}.
{12 . 25 . 11.57s2}.
{13 . 21 . 9.72s2}.
{14 . 15 . 6.94s2}.
{15 . 10 . 4.62s2}.
{16 . 6 . 2.77s2}.
{17 . 3 . 1.38s2}.
{18 . 1 . 0.46s2}
} "