Skip to content

Instantly share code, notes, and snippets.

@ochronus
Created April 2, 2016 10:10
Show Gist options
  • Save ochronus/77e1c450930ed7b99255c1510e3556ba to your computer and use it in GitHub Desktop.
Save ochronus/77e1c450930ed7b99255c1510e3556ba to your computer and use it in GitHub Desktop.
(defn bf-interpreter [program-code]
(loop [cells [0N], current-cell 0, instruction-pointer 0]
(condp = (get program-code instruction-pointer)
\+ (recur (update-in cells [current-cell] inc) current-cell (inc instruction-pointer))
\- (recur (update-in cells [current-cell] dec) current-cell (inc instruction-pointer))
(recur cells current-cell (inc instruction-pointer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment