int restored(LifeList *pattern, LifeList *perturb, int transl, int steps) { int i,damaged, lastsfor; copyLifeList(perturb, &spread1); spread(&spread1, 1); copyLifeList(pattern, &tmp); damaged = 0; lastsfor = 0; for (i=0; i<steps; i++) { generate(&tmp); if ( matchLifeList(&tmp, perturb, transl) == perturb->ncells && matchLifeList(&tmp, &spread1, transl) == perturb->ncells ) { if (damaged) lastsfor++; if (lastsfor>=10) return 1; } else { damaged = 1; lastsfor = 0; } } return 0; }
int interact(LifeList *pat1, LifeList *pat2, int transl) { /* both pat1 and pat2 are generated one step */ copyLifeList(pat1, &both); mergeLifeLists(&both, pat2, transl); generate(pat1); generate(pat2); generate(&both); return !( both.ncells == pat1->ncells + pat2->ncells && pat1->ncells == countMatch(pat1->cellList, pat1->ncells, both.cellList, both.ncells) && pat2->ncells == matchLifeList(&both, pat2, transl) ); }
int mostSurvives(LifeList *pattern, LifeList *perturb, int transl, int steps) { int i; copyLifeList(pattern, &tmp); copyLifeList(perturb, &spread1); spread(&spread1, 1); for (i=0; i<steps; i++) { generate(&tmp); } if ( matchLifeList(&tmp, perturb, transl) >= perturb->ncells-4 ) return 1; return 0; }
int survives(LifeList *pattern, LifeList *perturb, int transl, int steps) { int i; copyLifeList(pattern, &tmp); copyLifeList(perturb, &spread1); spread1.ncells = removeGreaterThan(spread1.cellList, spread1.ncells, 1); for (i=0; i<steps; i++) { generate(&tmp); if ( matchLifeList(&tmp, &spread1, transl) < spread1.ncells ) // || matchLifeList (&tmp, perturb, transl) < perturb->ncells-6 ) return 0; } return 1; }
main(int argc, char *argv[]) { static LifeList cells; static LifeList matchcells; static LifeList outcells; int i,j,n=0; int gens=500; int x,y; int match; int pos; int count[240]; int least= 0; int fail; int damaged; int restored; int prodcells; int restorefilter=10; char outpat[100000]; History hist; int period, repetitions; Cell lifetrail[5000]; static char nextpat[10000]; int ncls; initLifeList(&cells); initLifeList(&matchcells); initLifeList(&outcells); if (argc>2) { sscanf(argv[2], "%d", &restorefilter); } while(gets(nextpat)) { for (i=0; i<240; i++) { count[i] = i; } getpat(nextpat, &cells); copyLifeList(&cells, &matchcells); if (argc>1) { for (i=0; argv[1][i]; i++) { matchcells.ncells = removeIfEquals(matchcells.cellList, matchcells.ncells, argv[1][i]); } } fail=0; damaged=0; restored=0; for (i=0; i<gens; i++) { generate(&cells); // printf("%d %d %d %d\n", i, fail, damaged, restored); count[i%240] = cells.ncells; if (cells.ncells == 0) break; match = 1; for (j=0; j<180; j++) { if (count[j] != count[j+60]) { match = 0; break; } } if (match) break; if ( matchLifeList(&cells, &matchcells, 0) < matchcells.ncells) { fail++; restored=0; } else { prodcells = cells.ncells - matchcells.ncells; copyLifeList(&cells, &outcells); restored++; if (restored>restorefilter) { if (fail>damaged) damaged=fail; fail = 0; } } if (fail>150) break; } if (damaged) { fflush(stdout); removeLifeList(&outcells, &matchcells, 0); makeString(outcells.cellList, outcells.ncells, outpat); printf("%s %d %d %d %d %s\n", nextpat, damaged, fail, i-fail, prodcells, outpat); } } }
main(int argc, char *argv[]) { static LifeList cells; static LifeList matchcells; static LifeList boundarycells; static LifeList intercells; static LifeList outcells; int i,j,n=0; int gens=500; int x,y; int match; int pos; int count[240]; int least= 0; int fail; int damaged; int restored; int firstgen; int maxgen; int survivegen; int restorefilter=10; int maxrecoverytime=20; char interpat[100000]; char outpat[100000]; History hist; int period, repetitions; Cell lifetrail[50000]; static char nextpat[100000]; int ncls; initLifeList(&cells); initLifeList(&matchcells); initLifeList(&boundarycells); initLifeList(&intercells); initLifeList(&outcells); if (argc>2) { sscanf(argv[2], "%d", &restorefilter); } while(gets(nextpat)) { for (i=0; i<240; i++) { count[i] = i; } getpat(nextpat, &cells); copyLifeList(&cells, &matchcells); if (argc>1) { for (i=0; argv[1][i]; i++) { matchcells.ncells = removeIfEquals(matchcells.cellList, matchcells.ncells, argv[1][i]); } } copyLifeList(&matchcells, &boundarycells); spread(&boundarycells, 1); fail=0; damaged=0; restored=0; firstgen=0; maxgen=0; survivegen=0; for (i=0; i<gens; i++) { // printf("%d %d %d %d\n", i, fail, damaged, restored); count[i%240] = cells.ncells; if (cells.ncells == 0) break; match = 1; for (j=0; j<180; j++) { if (count[j] != count[j+60]) { match = 0; break; } } if (match) break; if ( matchLifeList(&cells, &matchcells, 0) < matchcells.ncells || matchLifeList(&cells, &boundarycells, 0) != matchcells.ncells) { fail++; restored=0; if (firstgen == 0) { firstgen = i; maxgen = i + restorefilter + maxrecoverytime; } } else { restored++; survivegen = i; if (restored>restorefilter) { if (restored == restorefilter + 1) { copyLifeList(&cells, &intercells); copyLifeList(&cells, &outcells); } if (i <= maxgen) { copyLifeList(&cells, &outcells); } if (fail>damaged) damaged=fail; fail = 0; firstgen = 0; } } if (fail>150) break; generate(&cells); } if (damaged) { fflush(stdout); removeLifeList(&outcells, &matchcells, 0); makeString(outcells.cellList, outcells.ncells, outpat); removeLifeList(&intercells, &matchcells, 0); makeString(intercells.cellList, intercells.ncells, interpat); printf("%s %d %s %s\n", nextpat, survivegen, interpat, outpat); } } }