Skip to content

Instantly share code, notes, and snippets.

View ytaki0801's full-sized avatar

TAKIZAWA Yozo ytaki0801

View GitHub Profile
@ytaki0801
ytaki0801 / letLISP-REPL.py
Last active April 6, 2024 12:42
A Pure LISP Interpreter with dynamic-scope named-let in pseudocode-style Python 3
####
#### letLISP-REPL.py:
#### A Pure LISP Interpreter
#### with dynamic-scope named-let
#### in pseudocode-style Python 3
####
#### (C) 2022 TAKIZAWA Yozo
#### This code is licensed under CC0,
#### Creative Commons 0 as Public Domain
####
@ytaki0801
ytaki0801 / w23tm-turtle.py
Last active December 10, 2022 14:44
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, setpos, pu, pd
pu(); setpos(-300, 300); pd(); 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)}}
@ytaki0801
ytaki0801 / w23tm-ds.py
Created December 10, 2022 11:41
Wolfram's 2-state 3-symbol Turing Machine
# Wolfram's 2-state 3-symbol Turing Machine
from time import sleep
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)}}
ds = {0: ' ', 1: '.', 2: '*'}
tlen = 80
tape, head, state = [0] * tlen, int(tlen / 2) - 9, 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)}}
@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-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 / 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-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 / 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 / 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) {