0

I want to work out all the permutations of three dice rolls where sum is over 7.

This is still a work in progress but efforts to calculate sets don't work.

import pandas as pd
import random

count = 0 
digits = [roll for roll in range(1,7)]
digits

digits_all = [random.sample(digits, 2) for d in digits]

def dice_role(r = digits_all):
    count =0 
    digits_all_roll_1 = r
    digits_all_roll_2 = r
    digits_all_roll_3 = r
    #return digits_all_roll_1, digits_all_roll_2, digits_all_roll_3
    data = []
    for d in digits_all_roll_1:
        data.append(tuple(d))   
        for e in digits_all_roll_2:
            data.append(tuple(e))
            for f in digits_all_roll_3:
                data.append(tuple(f))
    return data

results = dice_role()

Results

[(3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (3, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 2),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (5, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (6, 5),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1),
 (2, 1),
 (3, 1),
 (6, 5),
 (5, 2),
 (5, 1),
 (6, 5),
 (2, 1)]
)
1

What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
elksie5000
  • 7,084
  • 12
  • 57
  • 87
  • 1
    Please better define “efforts to calculate sets don't work.” by updating the question. – S3DEV Jul 10 '22 at 13:09
  • To calculate it reliable the random creation seems being strange, instead I'd process all possible combinations systematically. – David Jul 10 '22 at 13:10
  • 1
    Assume your method works as expected. Your issue is to form a set of the list `data` or `results` which contains tuples, right? Please clarify your issue and research for set-creation. – hc_dev Jul 10 '22 at 13:11
  • Does this answer your question? [Removing duplicates in lists](https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists) – hc_dev Jul 10 '22 at 13:13
  • What is the expected output? shouldn't you have 3 numbers in each tuple? – Guy Jul 10 '22 at 13:14

1 Answers1

4

If I understand the problem correctly, you could do it like this:

from itertools import combinations_with_replacement as CWR
result = {t for t in CWR(range(1, 7), 3) if sum(t) > 7}
print(result)

Output:

{(3, 5, 6), (1, 6, 6), (2, 2, 5), (4, 4, 4), (1, 2, 5), (4, 5, 6), (3, 3, 5), (1, 3, 6), (3, 4, 4), (1, 4, 5), (5, 5, 6), (2, 4, 5), (2, 3, 3), (2, 3, 6), (1, 1, 6), (1, 5, 6), (2, 2, 4), (3, 5, 5), (4, 4, 6), (4, 5, 5), (2, 5, 6), (4, 6, 6), (6, 6, 6), (1, 4, 4), (5, 5, 5), (3, 4, 6), (3, 3, 4), (1, 3, 5), (3, 6, 6), (2, 3, 5), (2, 4, 4), (1, 5, 5), (5, 6, 6), (2, 2, 6), (2, 5, 5), (1, 2, 6), (2, 6, 6), (4, 4, 5), (1, 4, 6), (1, 3, 4), (3, 3, 3), (3, 3, 6), (3, 4, 5), (2, 3, 4), (2, 4, 6)}
DarkKnight
  • 19,739
  • 3
  • 6
  • 22