Skip to content

Instantly share code, notes, and snippets.

View ytaki0801's full-sized avatar

TAKIZAWA Yozo ytaki0801

View GitHub Profile
@ytaki0801
ytaki0801 / CGoL_tput.py
Created February 4, 2023 05:03
Conway's Game of Life in Python with tput
from random import randint
from copy import deepcopy
from os import system
a, b = 80, 24; x, y, n = range(a), range(b), [-1,0,1]
c = [[randint(0,1) for _ in x] for _ in y]; g = deepcopy(c)
while True:
t = ''.join([''.join(['*' if c[j][i] else ' ' for i in x])+'\n' for j in y])
system('tput cup 18 0'); print(t, end='')
@ytaki0801
ytaki0801 / CGoL.scm
Last active February 2, 2023 17:20
Conway's Game of Life in Scheme
;; Using srfi.1 srfi.18 srfi.27
;;
;; gosh -u srfi.1 -u srfi.18 -u srfi.27 CGoL.scm
;; chibi-scheme -m srfi.1 -m srfi.18 -m srfi.27 CGoL.scm
(define xs 80) (define ys 38)
(random-source-randomize! default-random-source)
(define (randbinlist n)
(list-tabulate n (lambda (n) (random-integer 2))))
@ytaki0801
ytaki0801 / CGoL.sh
Last active February 16, 2023 19:22
Conway's Game of Life in POSIX Shell
#!/bin/sh
xs=80 ys=24
ORIGIN=$(clear) LF='
'
if [ ! ${RANDOM} ]; then
set -- $(head -c $((xs * ys)) /dev/random | od -An -vtu1)
fi
@ytaki0801
ytaki0801 / CGoL.py
Created February 1, 2023 12:17
Conway's Game of Life in Python
from random import randint
from os import system
from time import sleep
from copy import deepcopy
xs, ys = 210, 100
c = [[randint(0,1) for _ in range(ys)] for _ in range(xs)]
cn = [[0 for _ in range(ys)] for _ in range(xs)]
while True:
@ytaki0801
ytaki0801 / eca.c
Created January 31, 2023 12:08
Elementary Cellular Automata in C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define CN 180
#define ST 80
int main(void)
{
char r[8], c[CN], cn[CN], b, x, y, z;
@ytaki0801
ytaki0801 / eca.scm
Last active January 31, 2023 11:51
Elementary Cellular Automata in Scheme
(define (d2b n x)
(let loop ((d n) (r '()))
(if (= d 0) (let ((b (if (null? r) '(0) r)))
(append (make-list (- x (length b)) 0) b))
(loop (quotient d 2) (cons (modulo d 2) r)))))
(define (cinit cnum)
(let ((ci (make-list (+ (quotient cnum 2) (modulo cnum 2)) 0)))
(append ci '(1) (make-list (- (quotient cnum 2) 1) 0))))
@ytaki0801
ytaki0801 / eca.sh
Last active February 1, 2023 03:29
Elementary Cellular Automata in POSIX Shell, Rules from 0 to 255
#!/bin/sh
cnum=180; step=80;
rule=0
while [ $rule != 256 ]; do
b=$rule; for x in 0 1 2 3 4 5 6 7; do export r$x=$((b%2)) b=$((b/2)); done
i=0; while [ $i != $cnum ]; do export c$i=0 i=$((i+1)); done
export c$((cnum/2))=1
@ytaki0801
ytaki0801 / eca.py
Created January 28, 2023 17:04
Elementary Cellular Automata in Python 20 lines, Rules from 1 to 255
from time import sleep
cnum, step, r, b, = 150, 50, {}, (False,True)
g = [(x,y,z) for x in b for y in b for z in b]
for rule in range(1,256):
n = [int(x) for x in format(rule, '08b')]
for i in range(8): r[g[i]] = n[7-i]
c, cn = [False]*cnum, [False]*cnum
c[cnum//2] = 1
@ytaki0801
ytaki0801 / cat cts-Collatz5.py
Created January 25, 2023 09:00
Collatz-like Sequence on Cyclic Tag System in Python
from time import sleep
q = '100100100100100'
r = {'0':('','','','','','')}
r = {**r, **{'1':('010001','100','100100100','','','')}}
i, m = 0, 6
while q[1:]: q = q[1:]+r[q[0]][i]; i = (i+1)%m; print(q); sleep(0.1)
@ytaki0801
ytaki0801 / cts-Collatz5.sh
Last active January 25, 2023 09:01
Collatz-like Sequence on Cyclic Tag System in POSIX Shell
Q=100100100100100
S=000001010011100101
R0001=010001; R0011=100; R0101=100100100
while [ ${Q#?} ]; do
eval Q=${Q#?}\$R${S%${S#???}}${Q%${Q#?}}
S=${S#???}${S%${S#???}}
echo $Q
sleep 0.1
done