-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtiny-turing-2-testing.rkt
More file actions
executable file
·62 lines (55 loc) · 1.66 KB
/
Copy pathtiny-turing-2-testing.rkt
File metadata and controls
executable file
·62 lines (55 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#lang racket
(require "tiny.rkt"
"tiny-turing-2.rkt"
"virtual-machine.rkt")
(provide (all-defined-out))
(define ones-to-twos
(make-tiny-turing
'(start one halt)
'(0 1 2)
'start
'halt
'((start 1 start 2 R)
(start 0 halt 0 R))))
#;(ones-to-twos '(1 1 1))
(define double-list
(make-tiny-turing
'(start goto-end goto-start loop restart clear halt)
'(0 1 start old new)
'start
'halt
'(; Mark the starting position
(start 1 goto-end start R)
; Go to the first 0, replace it with new
(goto-end old goto-end old R)
(goto-end new goto-end new R)
(goto-end 0 goto-start new L)
(goto-end 1 goto-end 1 R)
; Go back to the start
(goto-start start loop start R)
(goto-start old goto-start old L)
(goto-start new goto-start new L)
(goto-start 1 goto-start 1 L)
; Loop back or check if we're done
(loop old loop old R)
(loop new restart new L)
(loop 1 goto-end old R)
; Go back to the start symbol
(restart old restart old L)
(restart start clear 1 R)
; Write out all 1s
(clear old clear 1 R)
(clear new clear 1 R)
(clear 0 halt 0 R))))
#;(double-list '(1 1 1))
#;(double-list (map (λ (_) (range 100))))
(define duck-duck-goose
(make-tiny-turing
'(start go-back halt)
'(0 1 duck goose)
'start
'halt
'((start 0 go-back 0 L)
(start 1 start duck R)
(go-back duck halt goose R))))
#;(duck-duck-goose '(1 1 1 1 1))