From 4c8409da359cf0da14214ccc939c10ac759f76a5 Mon Sep 17 00:00:00 2001 From: mRnea Date: Thu, 22 Aug 2024 00:24:19 +0300 Subject: added new examples --- examples/rule110/rule110.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/rule110/rule110.c (limited to 'examples/rule110/rule110.c') diff --git a/examples/rule110/rule110.c b/examples/rule110/rule110.c new file mode 100644 index 0000000..76f3b75 --- /dev/null +++ b/examples/rule110/rule110.c @@ -0,0 +1,23 @@ +#include + +#define BOARD_CAP 100 +static int board[BOARD_CAP]; + +int main() +{ + board[BOARD_CAP - 2] = 1; + + for (size_t i = 0; i < BOARD_CAP - 2; ++i) { + for (size_t j = 0; j < BOARD_CAP; ++j) { + fputc(" *"[board[j]], stdout); + } + fputc('\n', stdout); + + int pattern = (board[0] << 1) | board[1]; + for (size_t j = 1; j < BOARD_CAP - 1; ++j) { + pattern = ((pattern << 1) & 7) | board[j + 1]; + board[j] = (110 >> pattern) & 1; + } + } + return 0; +} -- cgit v1.2.3