-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcellautomata.c
71 lines (61 loc) · 1.17 KB
/
cellautomata.c
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
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int N;
void print_as_asterix(int[] , int );
int new_value(int[], int );
int row =1;
int main() {
int rule;
int max_iter;
int initial;
scanf("%d %d %d %d", &rule, &max_iter, &N, &initial);
int pick[N];
int x;
for(x=0;x<N;x++){
scanf("%d", &pick[x]);
}
for(x=0;x<N;x++){
printf("%d", pick[x]);
}
return 0;
}
void print_as_asterix(int arr[], int length){
int x;
if(row < 10){
printf("%d -",row++);
} else if(row <100){
printf("%d -",row++);
} else if(row , 1000){
printf("%d -",row++);
}
for(x=0; x<length;x++){
if(arr[x]){
printf("*");
}else{
printf(" ");
}
}
printf("-\n");
}
int new_value(int rep[], int index){
int nm1, np1, n;
//corner cases.
n = rep[index];
if(index == 0){
nm1 = 0;
}else{
nm1 = rep[index-1];
}
if(index == N-1){
np1 = 0;
} else{
np1 = rep[index+1];
}
int a,b,c;
a= nm1;
b= rep[index];
c = np1;
return (!a&&c)||(!a&&b)||(a&&!b&&!c);
}