Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created December 9, 2011 16:49
Show Gist options
  • Save takeshik/1452333 to your computer and use it in GitHub Desktop.
Save takeshik/1452333 to your computer and use it in GitHub Desktop.
Brainf*ck on Yacq
(def bf (\ [c:String] ($ [
d Int32.array.(new 30000) ; data array
di 0 ; data index
ci 0 ; code index
s Stack.[Int32].(new) ; jump stack
jc 0 ; jump counter
]
EnumerableEx.(Repeat c)
.(TakeWhile {!= ci $0.Length})
.(ForEach {$
(== jc 0).(if
$0.[ci].(switch
'>'
(++= di)
'<'
(--= di)
'+'
(++= d.[di])
'-'
(--= d.[di])
'.'
d.[di].(to Char).(printn)
','
(= d.[di] (type 'System.Console').(ReadKey).KeyChar.(to Int32))
'[' ($
s.(Push ci)
(== d.[di] 0).(then (++= jc))
)
']'
(!= d.[di] 0).(then (= ci (-- s.(Pop))))
; otherwise - do nothing
)
(== $0.[ci] ']').(then s.(Pop) (--= jc))
)
(++= ci)
})
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment