Bonjour, je suis étudiant en bioingénierie et je dois créer un automate cellulaire pour mon cours d'informatique.
J'aurais besoin d'un petit peu d'aide
L'énoncé du travail se trouve en pièce jointe.
Voici le début de mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 import sys n=int(raw_input('Entrez votre règle en décimal\n')) def dec2bin(n) : if n<0 or n>255 : return 'Nombre non compris entre 0 et 255' else : bin1 = [] while n!=0 : if (n%2) ==0 : n=n/2 bin1.insert (0,0) else : n = (n-1)/2 bin1.insert (0,1) while len (bin1) <8 : bin1.insert (0,0) return bin1 bin=dec2bin(n) print bin lignepapa = raw_input('Entrez une liste de chiffres\n') n = raw_input ('Nombres de lignes') lignepapa= str(lignepapa) lignepapa= list(lignepapa) u = len(lignepapa) def reglesautomate () : lignegarcon = [] for i in range (0,u) : if lignepapa[int((i-1)%u)]==1 and lignepapa [i]==1 and lignepapa [int((i+1)%u)]==1 : lignegarcon.append (dec2bin [0]) elif lignepapa[int((i-1)%u)]==1 and lignepapa [i]==1 and lignepapa [int((i+1%u)]==0 : lignegarcon.append (dec2bin [1]) elif lignepapa[int((i-1)%u)]==1 and lignepapa [i]==0 and lignepapa [int((i+1)%u)]==1 : lignegarcon.append (dec2bin [2]) elif lignepapa[int((i-1)%u)]==0 and lignepapa [i]==1 and lignepapa [int((i+1)%u)]==0 : lignegarcon.append (dec2bin [3]) elif lignepapa[int((i-1)%u)]==0 and lignepapa [i]==1 and lignepapa [int((i+1)%u]==1 : lignegarcon.append (dec2bin [4]) elif lignepapa[int((i-1)%u)]==0 and lignepapa [i]==1 and lignepapa [int((i+1)%u)]==0 : lignegarcon.append (dec2bin [5]) elif lignepapa[int((i-1)%u)]==0 and lignepapa [i]==0 and lignepapa [int((i+1)%u)]==1 : lignegarcon.append (dec2bin [6]) else : lignepapa [int((i-1)%u)]==0 and lignepapa [i]==0 and lignepapa [int((i+1)%u)]==0 lignegarcon.append (dec2bin [7]) return lignegarcon ligneenfant= reglesautomate () print ligneenfant def repeat (n,regle, lignepapa) : n= int (n) print lignepapa
J'ai plusieurs problèmes :
1) J'ai réalisé le début en utilisant "raw_input" or, on demande de pouvoir invoquer l'automate à partir du terminal. Comment faire?
2) la fin de mon code me donne une ligne de 0 et non un réel nouvel "état". Je ne comprends pas pourquoi
3) Comment répéter la règle sur "n" ligne filles?
Merci beaucoup d'avance !
Partager