Sum of roll of N dice
|
06-23-2018, 09:36 PM
Post: #43
|
|||
|
|||
RE: Sum of roll of N dice
(05-02-2018 07:01 AM)Jim Horn Wrote: So, just find a random number from 0 to (6^N)-1, convert to base 6, add the sum of its digits plus N (to correct the "subtract 1 from each digit") and there you go: the sum of the six rolled dice with only one random number generation. We don't really need to convert to base 6 if we only want the sum of the digits. Here's a small program for the HP-42S: Code: 6 The program works similar to the Base Conversion but instead of multiplying the digits by powers of 10 they are just added. Let's assume we want to calculate the digits of the number 13710 = 3456. So we divide 137 consecutively by 6 and get 22 and then 3. This allows to represent the digits as: Code: 5 = 137 - 6 · 22 Code: 5 + 4 + 3 = 137 - 5 · 22 - 5 · 3 = 137 - 5(22 + 3) = 12 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)