Generieren Sie eine zufällige Matrix in Python, die eine Bedingung erfülltPython

Python-Programme
Anonymous
 Generieren Sie eine zufällige Matrix in Python, die eine Bedingung erfüllt

Post by Anonymous »

Ich definiere manuell die folgenden 16 Matrizen in Python: < /p>

Code: Select all

matrices = {
"Simulation 1": [
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 3, 2],
[1, 1, 1, 1, 3, 3],
[1, 1, 1, 1, 3, 3]
],

"Simulation 2": [
[1, 1, 2, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 2, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 2, 3],
[1, 1, 1, 3, 3, 3]
],

"Simulation 3": [
[1, 1, 2, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 3, 3],
[1, 1, 2, 2, 3, 3],
[1, 1, 1, 3, 3, 3],
[1, 1, 3, 3, 3, 3]
],

"Simulation 4": [
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 2, 2, 2],
[3, 1, 3, 3, 3, 2],
[3, 3, 3, 3, 3, 2],
[3, 3, 3, 3, 3, 2],
[3, 3, 3, 3, 3, 3]
],

"Simulation 5": [
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 3, 2],
[1, 3, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3]
],

"Simulation 6": [
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 1, 2, 3],
[1, 3, 3, 3, 3, 3],
[1, 3, 3, 3, 3, 3]
],

"Simulation 7": [
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 3, 2, 2, 3],
[1, 1, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3]
],

"Simulation 8": [
[1, 1, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 3, 3],
[2, 2, 3, 3, 3, 3],
[2, 2, 2, 3, 3, 3]
],

"Simulation 9": [
[1, 1, 2, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 1, 3, 2],
[1, 1, 1, 1, 3, 3],
[1, 1, 3, 3, 3, 3]
],

"Simulation 10": [
[1, 1, 1, 2, 2, 2],
[1, 1, 2, 2, 2, 2],
[1, 1, 2, 2, 2, 2],
[1, 1, 2, 2, 2, 3],
[1, 1, 1, 1, 3, 3],
[1, 1, 1, 3, 3, 3]
],

"Simulation 11": [
[1, 1, 1, 2, 2, 2],
[1, 1, 2, 2, 2, 2],
[1, 1, 2, 2, 2, 3],
[1, 1, 1, 2, 3, 3],
[1, 1, 1, 3, 3, 3],
[1, 1, 1, 3, 3, 3]
],

"Simulation 12": [
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 1, 2, 2],
[3, 1, 1, 3, 3, 3],
[3, 3, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3]
],

"Simulation 13": [
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 3, 3, 3],
[1, 3, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3]
],

"Simulation 14": [
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 3, 3, 2],
[1, 3, 3, 3, 3, 3],
[1, 3, 3, 3, 3, 3]
],

"Simulation 15": [
[1, 1, 1, 2, 2, 2],
[1, 2, 2, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 1, 3, 3],
[1, 1, 1, 3, 3, 3],
[1, 1, 1, 3, 3, 3]
],

"Simulation 16": [
[1, 1, 3, 2, 2, 2],
[1, 1, 3, 2, 3, 3],
[1, 1, 3, 3, 3, 3],
[1, 1, 3, 3, 3, 3],
[1, 1, 3, 3, 3, 3],
[1, 1, 3, 3, 3, 3]
]
}
Wenn sich diese visualisiert, sehen diese so aus:

Positions.

Code: Select all

positions = [
[1,  2,  3,  4,  5,  6],
[7,  8,  9,  10, 11, 12],
[13, 14, 15, 16, 17, 18],
[19, 20, 21, 22, 23, 24],
[25, 26, 27, 28, 29, 30],
[31, 32, 33, 34, 35, 36]
]
< /code>
Diese Matrizen haben die folgenden Eigenschaften: < /p>
[list]
[*] 1 = rot, 2 = blau, 3 = grün < /li>
 Position 1 ist immer rot, Position 6 ist immer blau und Position 36 ist immer grün. Farbe
[/list]
Hier ist ein Beispiel für eine ungültige Matrix (d. H.  Knoten 1 (rot) kann die anderen roten Knoten nicht erreichen, ohne auf Blau zu treten):

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post