Skip to content

Instantly share code, notes, and snippets.

View ytaki0801's full-sized avatar

TAKIZAWA Yozo ytaki0801

View GitHub Profile
@ytaki0801
ytaki0801 / bf-intp.lua
Created January 24, 2023 07:26
Brainf**k interpreter in Lua
codes = ""; f = io.input(arg[1])
while true do
c = io.read(); if c == nil then break end
codes = codes..c
end
array = {}; p = 1; c = 1; cl = string.len(codes)
for i = 1, 65536 do array[i] = 0 end
while c <= cl do
@ytaki0801
ytaki0801 / bf-intp.sh
Last active January 23, 2023 02:05
Brainf**k interpreter in POSIX shell
#!/bin/sh
while IFS= read L; do
T=$T$L
done < "$1"
L=0
while [ "$T" ]; do
case $T in
+*) export "C$L"=0 L=$((L+1));;
@ytaki0801
ytaki0801 / 2ts-Collatz5.GS
Last active January 14, 2023 04:58
2-Tag System running Collatz-like Function in a Google Spreadsheet
=LAMBDA(u,u(u))(LAMBDA(u,LAMBDA(q,r,IF(LEN(q)>1,{q;u(u)(MID(q,3,LEN(q))&VLOOKUP(MID(q,1,1),r,2),r)},q))))("aaaaa", {{"a","bc"};{"b","a"};{"c","aaa"}})
@ytaki0801
ytaki0801 / cts-Collatz.js
Created January 3, 2023 13:42
Collatz Sequence on Cyclic Tag System in JavaScript/Node.js
// Collatz Sequence on 2-tag system
// rule: {A -> BC, B -> A, C -> AAA}, value: AAA for 3, for example
// Translation from 2-tag system to cyclic tag system
const A = "100", B = "010", C = "001", S = " ";
const clist = [B+C, A, A+A+A, S, S, S];
function printn(q) {
let n = 0;
while (q.length != 0 && q.slice(0, 3) == A) {
@ytaki0801
ytaki0801 / w23tm-2stacksLCR.py
Created January 3, 2023 04:46
2-state 3-symbol State Machine with Two Stacks and One Cell, same as Wolfram's (2,3) Universal Turing Machine
from time import sleep
# (state,symbol) => (state,symbol,head)
delta = {(0,0):(1,1,+1), (0,1):(0,2,-1), (0,2):(0,1,-1),
(1,0):(0,2,-1), (1,1):(1,2,+1), (1,2):(0,0,+1)}
ds = {0: ' ', 1: '.', 2: '*'}
state, stackL, C, stackR = 0, [0]*29, 0, [0]*50
while len(stackL) > 0 and len(stackR) > 0:
@ytaki0801
ytaki0801 / w23tm-2stacks.py
Created January 2, 2023 19:33
2-state 3-symbol State Machine with Two Stacks, same as Wolfram's (2,3) Universal Turing Machine
from time import sleep
# (state,symbol) => (state,symbol,head)
delta = {(0,0):(1,1,+1), (0,1):(0,2,-1), (0,2):(0,1,-1),
(1,0):(0,2,-1), (1,1):(1,2,+1), (1,2):(0,0,+1)}
ds = {0: ' ', 1: '.', 2: '*'}
tlen = 80
state, stack, stackT, head = 0, [0] * tlen, [], int(tlen / 2) - 10
@ytaki0801
ytaki0801 / gist:fd8d5b2aff6191756728f281c9464484
Created December 22, 2022 07:56
Wolfram's (2, 3) Turing Machine as an Universal TM with an Infinite Tape
# (2,3) Turing Machine as an UTM
from time import sleep
# (state,symbol) => (state,symbol,head)
delta = {(0,0): (1,1, 1),
(0,1): (0,2,-1),
(0,2): (0,1,-1),
(1,0): (0,2,-1),
(1,1): (1,2, 1),
@ytaki0801
ytaki0801 / w23tm-dsinf.py
Created December 20, 2022 07:59
(2,3) Turing Machine as an UTM with an infinite tape
# (2,3) Turing Machine as an UTM
from time import sleep
# (state,symbol) => (state,symbol,head)
delta = {(0,0): (1,1, 1),
(0,1): (0,2,-1),
(0,2): (0,1,-1),
(1,0): (0,2,-1),
(1,1): (1,2, 1),
@ytaki0801
ytaki0801 / minilogo.py
Last active December 16, 2022 04:54
Mini LOGO interpreter in Python with Turtle Graphics
import turtle, time
comm = {'fd': lambda n: turtle.fd(n),
'rt': lambda n: turtle.rt(n),
'lt': lambda n: turtle.lt(n)}
def logo(s, p, pe):
while p < pe:
if s[p] == 'loop':
n = int(s[p + 1])
@ytaki0801
ytaki0801 / w23tm-turtle2.py
Created December 10, 2022 12:31
Wolfram's 2-state 3-symbol Turing Machine as an Universal TM with Turtle Graphics
# Wolfram's 2-state 3-symbol Turing Machine as an Universal TM
# with Turtle Graphics
from time import sleep
from turtle import fd, rt, lt, setup, setpos, clear
setup(height=500); setpos(100, 0); clear(); sleep(5)
delta = {1: {0: (1, 1, 2), 1: (2, -1, 1), 2: (1, -1, 1)},
2: {0: (2, -1, 1), 1: (2, 1, 2), 2: (0, 1, 1)}}