Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - calculate die rolls and count doubles
    text
    copied!<p>The problem: I need to roll 3 dice. If two (or three) of the dice return the same number, stop. If the 3 dice are all unique (e.g. 2, 4, and 6) then roll again. Perform this either until doubles/triples are rolled, or 7 times, whichever comes first. </p> <p>Note: I'm a python newb. </p> <p>Here is what I have so far, but all this does is actually generate the 216 possible combinations: </p> <pre><code>import itertools all_possible = list(itertools.permutations([1,2,3,4,5,6],3)) input = raw_input() print all_possible </code></pre> <p>That generates this type of output: </p> <p><code>[(1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 2, 6), (1, 3, 2), (1, 3, 4), (1, 3, 5), (1, 3, 6), (1, 4, 2), (1, 4, 3), (1, 4, 5), (1, 4, 6), (1, 5, 2), (1, 5, 3), (1, 5, 4), (1, 5, 6), (1, 6, 2), (1, 6, 3), (1, 6, 4), (1, 6, 5), (2, 1, 3), (2, 1, 4), (2, 1, 5), (2, 1, 6), (2, 3, 1), (2, 3, 4), (2, 3, 5), (2, 3, 6), (2, 4, 1), (2, 4, 3), (2, 4, 5), (2, 4, 6), (2, 5, 1), (2, 5, 3), (2, 5, 4), (2, 5, 6), (2, 6, 1), (2, 6, 3), (2, 6, 4), (2, 6, 5), (3, 1, 2), (3, 1, 4), (3, 1, 5), (3, 1, 6), (3, 2, 1), (3, 2, 4), (3, 2, 5), (3, 2, 6), (3, 4, 1), (3, 4, 2), (3, 4, 5), (3, 4, 6), (3, 5, 1), (3, 5, 2), (3, 5, 4), (3, 5, 6), (3, 6, 1), (3, 6, 2), (3, 6, 4), (3, 6, 5), (4, 1, 2), (4, 1, 3), (4, 1, 5), (4, 1, 6), (4, 2, 1), (4, 2, 3), (4, 2, 5), (4, 2, 6), (4, 3, 1), (4, 3, 2), (4, 3, 5), (4, 3, 6), (4, 5, 1), (4, 5, 2), (4, 5, 3), (4, 5, 6), (4, 6, 1), (4, 6, 2), (4, 6, 3), (4, 6, 5), (5, 1, 2), (5, 1, 3), (5, 1, 4), (5, 1, 6), (5, 2, 1), (5, 2, 3), (5, 2, 4), (5, 2, 6), (5, 3, 1), (5, 3, 2), (5, 3, 4), (5, 3, 6), (5, 4, 1), (5, 4, 2), (5, 4, 3), (5, 4, 6), (5, 6, 1), (5, 6, 2), (5, 6, 3), (5, 6, 4), (6, 1, 2), (6, 1, 3), (6, 1, 4), (6, 1, 5), (6, 2, 1), (6, 2, 3), (6, 2, 4), (6, 2, 5), (6, 3, 1), (6, 3, 2), (6, 3, 4), (6, 3, 5), (6, 4, 1), (6, 4, 2), (6, 4, 3), (6, 4, 5), (6, 5, 1), (6, 5, 2), (6, 5, 3), (6, 5, 4)]</code></p> <p>Which isn't really good either, because it only generates NO doubles or triples--everything, as far as I can see, is just unique combinations only. </p> <p>----------Update----------- OK--I took this one and expanded it a little bit by peeling each value from the array and summing them (probably in the least efficient way possible). It works, and if there are multiple sets generated before the break, they all print. What I'm looking to do now is to sum. So:</p> <pre><code>def gen_random_termagants(): for _ in range(7): # instead of three separate variables, we use a list here # the nice thing is, that you can freely vary the number of # 'parallel' dice rolls this way dice = [random.randint(1, 6) for _ in range(3)] # this is more general and will break as soon as there are # duplicate (die) values in the list (meaning, break, if not all elements # are different) first_die = dice[0] second_die = dice[1] third_die = dice[2] total_term = first_die + second_die + third_die print "Total: %s" % total_term if len(dice) &gt; len(set(dice)): break </code></pre> <p>And here's the output sample:</p> <pre><code>How many tervigons? ::&gt;3 Let's calculate some termagants based on 3 tervigons... You'll get a minimum of 9 termagants per turn. You'll get a maximum of 54 termagants per turn. minimums: 5 turns [45] :: 6 turns [54] :: 7 turns [63] averages: 5 turns [157] :: 6 turns [189] :: 7 turns [220] maximums: 5 turns [270] :: 6 turns [324] :: 7 turns [378] Total: 9 Total: 8 </code></pre> <p>So in this example, I want it to return 17 (i.e. 9 + 8). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload