3
I am doing a 3-data sample space probability work (one on 4 sides, one on 6 sides and the other on 8 sides)
I know that the sample space, without repetition between the data, is 4*6*8 = 192.
I saw in a theme here the following script:
from itertools import product
caracteres = [0, 1, 2]
permsList = []
genComb = product(caracteres, repeat=2) # aqui e onde tens de especificar o numero de chars que cada combinacao tenha
for subset in genComb:
print(subset) # tuple retornado com uma combinacao por loop
permsList.append(subset)
print(permsList) # [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
Where the product command generates all possible combinations, including repeated characters
But only two things were missing:
- possible combinations not to be repeated
- the data were from 1 to their faces.
For example:
[(4,6,8); (3,6,8) ; (4,5,8) ; (4,6,7) ; (2,6,8) ; . . . ]
Someone could help me?
Edit (solved) I wrote a scrip, with the help of those involved here, and you can make a sample space for as many data as you want, up to 5, with as many desired faces in each:
from itertools import product
if(A==1 or A==2 or A==3 or A==4 or A==5):
if(A==1):
a=input("Quantas faces possui o dado 1?: ")
print(list(product(range(1, a+1))))
if(A==2):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
print(list(product(range(1, a+1), range(1, b+1))))
if(A==3):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
print(list(product(range(1, a+1), range(1, b+1), range(1, c+1))))
if(A==4):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
d=int(input("Quantas faces possui o dado 4?: "))
print(list(product(range(1, a+1), range(1, b+1), range(1, c+1), range(1, d+1))))
if(A==5):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
d=int(input("Quantas faces possui o dado 4?: "))
e=int(input("Quantas faces possui o dado 5?: "))
print(list(product(range(1, a+1), range(1, b+1), range(1, c+1), range(1, d+1), range(1, e+1))))
else:
print("Utilize números inteiros de 1 a 5")
In case you want to know the event:
from itertools import product
A=int(input("Quantas dados serão utilizados? (1-5): "))
if(A==1 or A==2 or A==3 or A==4 or A==5):
if(A==1):
a=input("Quantas faces possui o dado 1?: ")
X=input("Qual o evento (soma do número de faces)?: ")
resultado = product(range(1, a+1))
somam = [ x for x in resultado if x[0] == X]
print("Os eventos são, para os dados de :")
print(somam)
if(A==2):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
X=input("Qual o evento (soma do número de faces)?: ")
resultado = product(range(1, a+1), range(1,b+1))
somam = [ x for x in resultado if x[0] + x[1] == X]
print("Os eventos são, para os dados de :")
print(somam)
if(A==3):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
X=input("Qual o evento (soma do número de faces)?: ")
resultado = product(range(1, a+1), range(1,b+1), range(1,c+1))
somam = [ x for x in resultado if x[0] + x[1] + x[2] == X]
print("Os eventos são, para os dados de :")
print(somam)
if(A==4):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
d=int(input("Quantas faces possui o dado 4?: "))
X=input("Qual o evento (soma do número de faces)?: ")
resultado = product(range(1, a+1), range(1,b+1), range(1,c+1), range(1,d+1))
somam = [ x for x in resultado if x[0] + x[1] + x[2] + x[3] == X]
print("Os eventos são, para os dados de :")
print(somam)
if(A==5):
a=int(input("Quantas faces possui o dado 1?: "))
b=int(input("Quantas faces possui o dado 2?: "))
c=int(input("Quantas faces possui o dado 3?: "))
d=int(input("Quantas faces possui o dado 4?: "))
e=int(input("Quantas faces possui o dado 5?: "))
X=input("Qual o evento (soma do número de faces)?: ")
resultado = product(range(1, a+1), range(1,b+1), range(1,c+1), range(1,d+1), range(1,e+1))
somam = [ x for x in resultado if x[0] + x[1] + x[2] + x[3] + x[4] == X]
print("Os eventos são, para os dados de :")
print(somam)
else:
print("Utilize números inteiros de 1 a 5")
Let’s make this clear: the four-sided die has the sides
[1, 2, 3, 4]
, the one of six has[1, 2, 3, 4, 5, 6]
and the eight has[1, 2, 3, 4, 5, 6, 7, 8]
, correct? Do you want to generate all combinations where the value of the sides does not repeat? For example, the output must contain[1, 2, 3]
, but may not contain[1, 2, 1]
, that’s it?– Woss
@Andersoncarloswoss besides the repetition of values, it is necessary to know if the order matters, e.g. if [1, 2, 3] == [3, 2, 1] will be considered
True
or not– Daniel
@Very well observed blogger. Taking advantage, I calculated here and 192 is the number of sequences with repetition. No repetition, as requested, has only 120 sequences.
– Woss
I must have expressed myself wrong. So it is: the entire sample space is 192, with non-repeats being, for example, [(4,6,8); (3,6,8) ; (4,5,8) ; (4,6,8); (4,5,8); . . . ], is not repeating previous values. The values obtained may be [(1,1,1); (1,1,2); (1,2,1); (1,3,2); ... ] indefinitely, only if the order is prevailed, that is, in this way: whereas a, b and c belong to the positive integers only, the following order [(a,b,c)], cannot be [(b,a,c)], i.e., not changing order
– Luis Carlos Moura
@Andersoncarloswoss, is that I want the possible combinations in the release of these three dice, ie the sample space. Replying to your question, the order does not matter, for your example, [1, 2, 3] is different from [3, 2, 1], would be two possible combinations here In the case of my previous comment, 'a' would assume values between 1 and 4 (given from 4 sides), 'b' asumiria values from 1 to 6 (data from 6 sides) and 'c' would assume values from 1 to 8 sides (data from 8 sides)
– Luis Carlos Moura