seeds/default
씨앗
- 종류
- 2차원 셀룰러 오토마타
- 보는 이웃
- 무어, 여덟 칸
- 규칙
- B2/S
- 상태
- 2
언어를 고르면 코드가 열린다
BORN = (2,) SURVIVE = () def live_neighbors(cells, w, h, x, y): total = 0 for dy in (-1, 0, 1): for dx in (-1, 0, 1): if dx == 0 and dy == 0: continue total += cells[(y + dy) % h * w + (x + dx) % w] return total def seeds_step(cells, w, h): out = [0] * (w * h) for y in range(h): for x in range(w): live = live_neighbors(cells, w, h, x, y) rule = SURVIVE if cells[y * w + x] == 1 else BORN out[y * w + x] = 1 if live in rule else 0 return out
const BORN = [2]; const SURVIVE = []; function liveNeighbors(cells, w, h, x, y) { let total = 0; for (let dy = -1; dy <= 1; dy++) { for (let dx = -1; dx <= 1; dx++) { if (dx === 0 && dy === 0) continue; total += cells[((y + dy + h) % h) * w + ((x + dx + w) % w)]; } } return total; } function seedsStep(cells, w, h) { const out = new Uint8Array(w * h); for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const live = liveNeighbors(cells, w, h, x, y); const rule = cells[y * w + x] === 1 ? SURVIVE : BORN; out[y * w + x] = rule.includes(live) ? 1 : 0; } } return out; }
#define BORN (1 << 2) #define SURVIVE 0 static int live_neighbors(const char cells[], int w, int h, int x, int y) { int total = 0; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dx == 0 && dy == 0) continue; total += cells[((y + dy + h) % h) * w + (x + dx + w) % w]; } } return total; } void seeds_step(const char cells[], char out[], int w, int h) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int live = live_neighbors(cells, w, h, x, y); int rule = cells[y * w + x] == 1 ? SURVIVE : BORN; out[y * w + x] = (rule >> live) & 1; } } }
constexpr int BORN = 1 << 2; constexpr int SURVIVE = 0; static int live_neighbors(const std::vector<char>& cells, int w, int h, int x, int y) { int total = 0; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dx == 0 && dy == 0) continue; total += cells[((y + dy + h) % h) * w + (x + dx + w) % w]; } } return total; } std::vector<char> seeds_step(const std::vector<char>& cells, int w, int h) { std::vector<char> out(cells.size(), 0); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int live = live_neighbors(cells, w, h, x, y); int rule = cells[y * w + x] == 1 ? SURVIVE : BORN; out[y * w + x] = (rule >> live) & 1; } } return out; }
const int Born = 1 << 2; const int Survive = 0; static int LiveNeighbors(byte[] cells, int w, int h, int x, int y) { int total = 0; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dx == 0 && dy == 0) continue; total += cells[((y + dy + h) % h) * w + (x + dx + w) % w]; } } return total; } static byte[] SeedsStep(byte[] cells, int w, int h) { byte[] next = new byte[w * h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int live = LiveNeighbors(cells, w, h, x, y); int rule = cells[y * w + x] == 1 ? Survive : Born; next[y * w + x] = (byte)((rule >> live) & 1); } } return next; }
static final int BORN = 1 << 2; static final int SURVIVE = 0; static int liveNeighbors(byte[] cells, int w, int h, int x, int y) { int total = 0; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dx == 0 && dy == 0) continue; total += cells[((y + dy + h) % h) * w + (x + dx + w) % w]; } } return total; } static byte[] seedsStep(byte[] cells, int w, int h) { byte[] out = new byte[w * h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int live = liveNeighbors(cells, w, h, x, y); int rule = cells[y * w + x] == 1 ? SURVIVE : BORN; out[y * w + x] = (byte) ((rule >> live) & 1); } } return out; }