- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
m =: 256$0
index =: 0
output =: 0$0
input =: 0$0
code =: 0$0
cycles =: 0$0
codeIndex =: 0
setCode =: 3 : 'code =: transform y'
transform =: '><+-.,[]'&i.
preset =: 3 : 'cycles =: 0$0 [ codeIndex =: 0 [ output =: 0$0 [ m =: 256$0 [ index=:0'
returnOutput =: 3 : 'output { a.'
changeValue =: 3 : 'm =: (index&{.,y,(>:index)&}.) m'
addCodeIndex =: 3 : 'codeIndex =: (>: codeIndex)'
setCodeIndex =: 3 : 'codeIndex =: {: cycles'
deleteCycle =: 3 : 'cycles =: }: cycles'
func_1 =: 3 : 'index =:256&|@>:index'
func_2 =: 3 : 'index =:256&|@<:index'
func_3 =: 3 : 'changeValue@(256&|)@>:@(index&{) m'
func_4 =: 3 : 'changeValue@(256&|)@<:@(index&{) m'
func_5 =: 3 : 'output=:output, ((index&{) m)'
func_6 =: 3 : '(input =: }.input)[ changeValue(256&|@{.input)'
func_7 =: 3 : 'cycles =: cycles&, codeIndex'
func_8 =: 3 : '(setCodeIndex`deleteCycle@.(0&=))@(index&{) m'
doAction =: func_1`func_2`func_3`func_4`func_5`func_6`func_7`func_8@.]
doInstuction =: 3 : '(doAction[addCodeIndex)@{.@(codeIndex&{) code'
ExitCond =: 3 : 'codeIndex = (# code)'
interpreter =: 3 : '(((,&1 [ doInstuction )`0: @. ExitCond)^:_) 0'
brainFuck =: returnOutput [ interpreter [ setCode [ preset
brainFuck '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'