Discuss Scratch
- Discussion Forums
- » Show and Tell
- » Turing Machine Programs
- lolucky
-
5 posts
Turing Machine Programs
Share your awesome programs and challenges from the project Turing Machine Programming
The more insane the better!
The more insane the better!
Last edited by lolucky (Feb. 28, 2023 02:54:06)
- donotforgetmycode
-
1000+ posts
Turing Machine Programs
cH: _: H > ce
ce: _: e > cl1
cl1: _: l > cl2
cl2: _: l > co1
co1: _: o > cspace
cspace: _: > cW
cW: _: W > co2
co2: _: o > cr
cr: _: r > cl3
cl3: _: l > cd
cd: _: d > done
ce: _: e > cl1
cl1: _: l > cl2
cl2: _: l > co1
co1: _: o > cspace
cspace: _: > cW
cW: _: W > co2
co2: _: o > cr
cr: _: r > cl3
cl3: _: l > cd
cd: _: d > done
Last edited by donotforgetmycode (Nov. 18, 2022 17:12:25)
- donotforgetmycode
-
1000+ posts
Turing Machine Programs
Set the strip to 2 binary numbers separated by a + sign (like 1011+1100), then run this code:
right:
1: >
0: >
+: >
_: < subtract
subtract:
0: 1 <
1: 0 middle
+: done
_: error
middle:
0: <
1: <
+: < add
_: error
add:
1: 0 <
0: 1 left
+: error
_: 1 left
left:
1: <
0: <
+: <
_: > right
- MonkeyBean2
-
500+ posts
Turing Machine Programs
Counter, I think:
right:
0: >
1: >
_: < carry
carry:
0: < 1 left
1: < 0
_: 1 right
left:
0: <
1: <
_: > right
- lolucky
-
5 posts
Turing Machine Programs
very nice adder, @donotforgetmycode
here's another adder that is more efficient with the cost of being longer code:
here's another adder that is more efficient with the cost of being longer code:
right:
0: >
1: >
O: >
I: >
+: >
_: < read
read:
0: _ < left0
1: _ < left1
+: _ < rewrite
left0:
0: <
1: <
+: < add0
left1:
0: <
1: <
+: < add1
add0:
0: O > right
1: I > right
O: <
I: <
add1:
0: I > right
1: O < carry
O: <
I: <
carry:
1: 0 <
0: 1 right
_: 1 right
rewrite:
O: 0 <
I: 1 <
0: <
1: <
_: done
Last edited by lolucky (Nov. 29, 2022 19:31:32)
- donotforgetmycode
-
1000+ posts
Turing Machine Programs
Nice, I really like how you replace the digits with letters. very nice adder, @donotforgetmycode
here's another adder that is more efficient with the cost of being longer code:
(snip)
- larsikene
-
6 posts
Turing Machine Programs
start:
_: _ >
1: next
next:
1: 1 > divide
_: done
divide:
1: _ > next
_: 5 > done
a thing that divides the amount of 1s by two
if u get 5 at the end that is supposed to be .5
Last edited by larsikene (Jan. 8, 2023 18:40:22)
- MonkeyBean2
-
500+ posts
Turing Machine Programs
Binary adder.
Supply it with two binary numbers separated by a “+”
Supply it with two binary numbers separated by a “+”
right:
0: >
1: >
+: >
_: < add
add:
0: < 1 back
1: < 0
_: 1 right
sub:
0: < 1
1: < 0 back2
_: 1 right
check0:
0: >
1: > check0hit1
+: done
check0hit1:
0: >
1: >
+: < sub
back:
0: <
1: <
+: <
_: > check0
back2:
0: <
1: <
+: <
_: > right
- larsikene
-
6 posts
Turing Machine Programs
hello this is (probably) first ever sorting algorithm coded inside this machine
NOTE: its from high to low, the only numbers it supports are 1 to 5 and if the machine gets to the end of the string please press the >> button agian
also im not gonna indentations cuz its super long
bugs may be present too
NOTE: its from high to low, the only numbers it supports are 1 to 5 and if the machine gets to the end of the string please press the >> button agian
also im not gonna indentations cuz its super long
bugs may be present too
start: 1: 1 > 1a 2: 2 > 2a 3: 3 > 3a 4: 4 > 4a 5: 5 > 5a _: _ < repeatover repeatover: 5: 5 < 4: 4 < 3: 3 < 2: 2 < 1: 1 < _: _ > start 1a: 1: start 2: 2 < 2b 3: 3 < 3b 4: 4 < 4b 5: 5 < 5b 2a: 1: start 2: start 3: 3 < 3b 4: 4 < 4b 5: 5 < 5b 3a: 1: start 2: start 3: start 4: 4 < 4b 5: 5 < 5b 4a: 1: start 2: start 3: start 4: start 5: 5 < 5b 5a: 1: start 2: start 3: start 4: start 5: start 1b: 1: 1 > 1c 2: 1 > 2c 3: 1 > 3c 4: 1 > 4c 5: 1 > 5c 2b: 1: 2 > 1c 2: 2 > 2c 3: 2 > 3c 4: 2 > 4c 5: 2 > 5c 3b: 1: 3 > 1c 2: 3 > 2c 3: 3 > 3c 4: 3 > 4c 5: 3 > 5c 4b: 1: 4 > 1c 2: 4 > 2c 3: 4 > 3c 4: 4 > 4c 5: 4 > 5c 5b: 1: 5 > 1c 2: 5 > 2c 3: 5 > 3c 4: 5 > 4c 5: 5 > 5c 1c: 1: 1 start 2: 1 start 3: 1 start 4: 1 start 5: 1 start 2c: 1: 2 start 2: 2 start 3: 2 start 4: 2 start 5: 2 start 3c: 1: 3 start 2: 3 start 3: 3 start 4: 3 start 5: 3 start 4c: 1: 4 start 2: 4 start 3: 4 start 4: 4 start 5: 4 start 5c: 1: 5 start 2: 5 start 3: 5 start 4: 5 start 5: 5 start
Last edited by larsikene (Feb. 17, 2023 19:53:24)
- larsikene
-
6 posts
Turing Machine Programs
i improved it Counter, I think:right:
0: >
1: >
_: < carry
carry:
0: < 1 left
1: < 0
_: 1 right
left:
0: <
1: <
_: > right
astate:
0: 1 bstate
1: 0 <
_: 1 bstate
bstate:
1: 1 >
0: 0 >
_: _ < astate
- larsikene
-
6 posts
Turing Machine Programs
Last edited by larsikene (April 26, 2023 08:23:13)
- larsikene
-
6 posts
Turing Machine Programs
Boole algebra machine (version 4: fixed bug where xor gate wont care about brackets)
0 is for false, 1 for true, letters below are operations
E = END
ends the code
A = AND
truth table: 0A0, 0A1, 1A0 = 0 1A1 = 1
O = OR
truth table: 0O0 = 0 1O0, 0O1, 1O1 = 1
N = NOT
truth table: N1 = 0 N0 = 1
X = XOR
truth table: 0X0, 1X1 = 0 0X1, 1X0 = 1
() = BRACKETS
tells the order of the operations
example: ((NOT 1) AND 1) OR (1) = N1A1O1E or ((N1)A1)O(1)E or 1O(1A(N1))E = true
ALL THE OPERATIONS MUST BE LEFT TO RIGHT DEPENDING ON THEIR ORDER IF YOU'RE NOT USING BRACKETS!
for example:
if we were to get the output of an AND operation with the inputs being 1 and the NOT operation of 1
we would have to write it like this: N1A1E, which outputs 0
otherwise, if we wrote it as 1AN1E it will get bugged
but if we write it like this: 1A(N1)E it will work
here's the code:
0 is for false, 1 for true, letters below are operations
E = END
ends the code
A = AND
truth table: 0A0, 0A1, 1A0 = 0 1A1 = 1
O = OR
truth table: 0O0 = 0 1O0, 0O1, 1O1 = 1
N = NOT
truth table: N1 = 0 N0 = 1
X = XOR
truth table: 0X0, 1X1 = 0 0X1, 1X0 = 1
() = BRACKETS
tells the order of the operations
example: ((NOT 1) AND 1) OR (1) = N1A1O1E or ((N1)A1)O(1)E or 1O(1A(N1))E = true
ALL THE OPERATIONS MUST BE LEFT TO RIGHT DEPENDING ON THEIR ORDER IF YOU'RE NOT USING BRACKETS!
for example:
if we were to get the output of an AND operation with the inputs being 1 and the NOT operation of 1
we would have to write it like this: N1A1E, which outputs 0
otherwise, if we wrote it as 1AN1E it will get bugged
but if we write it like this: 1A(N1)E it will work
here's the code:
astate: 1: 1 > 0: 0 > A: AND O: OR N: NOT X: XOR (: > ): bracket _: > E: ending
NOT: N: N > 1: 1 NOT1 0: 0 NOT0 _: < (: astate
NOT1: 1: 0 astate
NOT0: 0: 1 astate
AND: A: A < 1: 1 > ANDTCHECK 0: 0 > ANDFSEND _: <
ANDTCHECK: A: A > 0: 0 < ANDFALSEA 1: 1 < ANDTRUEA _: > (: astate
ANDFSEND: A: A > 1: 1 < ANDFALSEA _: > 0: 0 < ANDFALSEA (: astate
ANDFALSEA: _: < A: A < 1: _ > ANDFALSEB 0: _ > ANDFALSEB ANDFALSEB: _: > A: _ > 1: 0 astate 0: 0 astate
ANDTRUEA: _: < A: A < 1: _ > ANDTRUEB
ANDTRUEB: _: > A: _ > 1: 1 astate
OR: O: < 1: > ORTRUE 0: > ORFALSE _: <
ORTRUE: O: O > _: > 1: 1 < ORTRUEA 0: 0 < ORTRUEA (: astate
ORFALSE: _: > O: O > 1: 1 < ORTRUEA 0: < ORFALSEA (: astate
ORTRUEA: _: < O: O < 1: _ > ORTRUEB 0: _ > ORTRUEB
ORTRUEB: _: > O: _ > 0: 1 astate 1: 1 astate
ORFALSEA: _: < O: O < 0: _ > ORFALSEB
ORFALSEB: _: > O: _ > 0: 0 astate
XOR: X: < 1: > XORTRUE 0: > XORFALSE _: <
XORTRUE: X: X > _: > 1: 1 < XORFALSEA 0: 0 < XORTRUEA (: astate
XORFALSE: _: > X: X > 1: 1 < XORTRUEA 0: < XORFALSEA (: astate
XORTRUEA: _: < X: X < 1: _ > XORTRUEB 0: _ > XORTRUEB
XORTRUEB: _: > X: _ > 0: 1 astate 1: 1 astate
XORFALSEA: _: < X: X < 0: _ > XORFALSEB 1: _ > XORFALSEB
XORFALSEB: _: > X: _ > 0: 0 astate 1: 0 astate
bracket: ): < _ 1: _ bracketone _: < 0: _ bracketzero
bracketone: _: < N: _ < (: 1 < astate
bracketzero: _: < N: _ < (: 0 < astate
ending: E: < _: < 1: _ > end1 0: _ > end0
end1: _: > E: 1 done
end0: _: > E: 0 done
Last edited by larsikene (March 1, 2025 13:34:16)
- lolucky
-
5 posts
Turing Machine Programs
Find Matching Parentheses
enter a strip of “(” and “)” with only spaces allowed between them
put pointer on one parentheses and it will find the matching parentheses
enter a strip of “(” and “)” with only spaces allowed between them
put pointer on one parentheses and it will find the matching parentheses
start: (:{ > L1 ):} < R1
L1: }:] > [:> ]:> _:> (:> ):} < L2
L2: [:< ]:< _:< (:[ > L1 {:( > L3
L3: [:( > ]:) > _:> }:) done
R1: {:[ < [:< ]:< _:< ):< (:{ > R2
R2: [:> ]:> _:> ):] < R1 }:) < R3
R3: [:( < ]:) < _:< {:( done
Last edited by lolucky (Feb. 28, 2023 19:27:04)
- lolucky
-
5 posts
Turing Machine Programs
BrainF*** Interpreter
< > move the data pointer to the left or right (make sure not to go off the data stip!)
! flip the bit at the data pointer (normal BrainF*** uses multibit cells and increment and decrement, but I implemented it with 1 bit cells)
[ jumps to matching ] if the data pointer is on 0, and does nothing on 1
] jumps to matching [ if the data pointer is on 1, and does nothing on 0
"[" and “]” work together to make a block like RepeatUntil (pointer = 0)
* is the program pointer
. is the data pointer
# is the end of the program and start of the data
put spaces between every character in the code, and a * before the first operation
example strip: *[_!_>_]_#_1_1_1_0_1_1
program that fills everything with 1s: *[_!_]_!_[_>_[_!_]_!_]_#_1_1_1_0_1_1
code:
tell me if you run into any bugs with it
< > move the data pointer to the left or right (make sure not to go off the data stip!)
! flip the bit at the data pointer (normal BrainF*** uses multibit cells and increment and decrement, but I implemented it with 1 bit cells)
[ jumps to matching ] if the data pointer is on 0, and does nothing on 1
] jumps to matching [ if the data pointer is on 1, and does nothing on 0
"[" and “]” work together to make a block like RepeatUntil (pointer = 0)
* is the program pointer
. is the data pointer
# is the end of the program and start of the data
put spaces between every character in the code, and a * before the first operation
example strip: *[_!_>_]_#_1_1_1_0_1_1
program that fills everything with 1s: *[_!_]_!_[_>_[_!_]_!_]_#_1_1_1_0_1_1
code:
pre1: *:> 0:> 1:> [:> ]:> !:> <:> >:> _:> #:> pre2
pre2:_: . to_code
to_code: *:> read 0:< 1:< [:< ]:< !:< <:< >:< .:< #:< _:<
read: [:< cmd[ ]:< cmd] !:< cmd! >:< cmd> <:< cmd< #:< done
cmd!:*: _ > 3! 3!:!: > 4! 4!:_: * > to_data!
to_data!: .:> set! 0:> 1:> [:> ]:> !:> <:> >:> #:> _:>
set!: 0: 1 to_code 1: 0 to_code
cmd>:*: _ > 3> 3>:>: > 4> 4>:_: * > to_data>
to_data>: .:_ > set> 0:> 1:> [:> ]:> !:> <:> >:> #:> _:>
set>: 0:> set>2 1:> set>2 set>2:_: . to_code
cmd<:*: _ > 3< 3<:<: > 4< 4<:_: * > to_data<
to_data<: .:_ < set< 0:> 1:> [:> ]:> !:> <:> >:> #:> _:>
set<: 0: < set<2 1: < set<2 set<2: _: . to_code
cmd[:*:> to_data[
to_data[: 0:> 1:> [:> ]:> !:> <:> >:> #:> _:> .:> get[ get[:
0: to_code[0
1: to_code[1
to_code[0: 0:< 1:< [:< ]:< !:< <:< >:< .:< #:< _:<
*:_ > L0 L0:[:{ > L1
retL:_: * > read
to_code[1: 0:< 1:< [:< ]:< !:< <:< >:< .:< #:< _:<
*:_ > 2[ 2[: [: > 3[ 3[: _:* > read
L1: }:) > (:> ):> [:> _:> !:> <:> >:> *:> ]:} < L2
L2: (:< ):< ]:< _:< !:< <:< >:< *:< [:( > L1 {:[ > L3
L3: (:[ > ):] > _:> !:> <:> >:> *:> }:> ] retL
cmd]:*:> to_data]
to_data]: 0:> 1:> [:> ]:> !:> <:> >:> #:> _:> .:> get] get]:
0: to_code]0
1: to_code]1
to_code]0: 0:< 1:< [:< ]:< !:< <:< >:< .:< #:< _:<
*:_ > 2] 2]: ]: > 3] 3]: _:* > read
to_code]1: 0:< 1:< [:< ]:< !:< <:< >:< .:< #:< _:<
*:_ > R0 R0:]:} < R1
retR:_: * > read
R1: {:( < (:< ):< _:< !:< <:< >:< *:< ]:< [:{ > R2
R2: (:> ):> _:> _:> !:> <:> >:> *:> ]:) < R1 }:] < R3
R3: (:[ < ):] < _:< !:< <:< >:< *:< {:> [ retR
tell me if you run into any bugs with it
Last edited by lolucky (Feb. 28, 2023 20:17:44)
- larsikene
-
6 posts
Turing Machine Programs
read the instructions. if you have problems i may help. How does this work? I am confused.
- shenmuueedoesnumbers
-
68 posts
Turing Machine Programs
aa: _: 1 > bb 1: < bb bb: _: 1 < aa 1: _ < cc cc: _: 1 > done 1: < dd dd: _: 1 > 1: _ > aa
- Discussion Forums
- » Show and Tell
-
» Turing Machine Programs