Answer the question
In order to leave comments, you need to log in
How to distribute numbers randomly into a matrix?
Hello!
There are 45 tiles (4 in a row) with a geometric pattern (3 types, but how can you flip = 6)
# Вид 1
a = ("A") #7 (кол-во плиток)
b = ("B") #8
# Вид 2
c = ("C") #7
d = ("D") #8
# Вид 3
e = ("E") #7
f = ("F") #8
import random
a = ("A")
b = ("B")
c = ("C")
d = ("D")
e = ("E")
f = ("F")
print(random.sample((a, b, c, d, e, f),6))
Answer the question
In order to leave comments, you need to log in
Well, the head-on solution is to use Counter.
from collections import Counter
cntr = Counter({"A": 7, "B": 8, "C": 7, "D": 8, "E": 7, "F": 8})
x = "A"
if cntr[x]:
# Условие выполнится, только если счётчик для "А" больше нуля
x = "A"
cntr.subtract( {x: 1} ) # Счётчик для "A" уменьшится на единицу
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question