Skip to content

Instantly share code, notes, and snippets.

View ochronus's full-sized avatar

Csaba Okrona ochronus

View GitHub Profile
#!/usr/bin/env python
import socket
import subprocess
import sys
from datetime import datetime
# Clear the screen
subprocess.call('clear', shell=True)
# Ask for input
### Keybase proof
I hereby claim:
* I am ochronus on github.
* I am ochronus (https://keybase.io/ochronus) on keybase.
* I have a public key whose fingerprint is 72AE 03B4 9D2A A667 2AF4 64DE CFB8 486E DED3 A6FE
To claim this, I am signing this object:
$("a").each(function() {
var $elem = $(this);
var url = $elem.attr("href");
if (url.indexOf("https://news.ycombinator.com") === 0 || url.indexOf("http") === -1) {
return;
}
if ($elem.attr("target") === undefined) {
$elem.attr("target", "_blank");
(defn bf-interpreter [program-code]
(let [
find-bracket (fn [opening-bracket closing-bracket instruction-pointer direction]
(loop [i (direction instruction-pointer) opened 0]
(condp = (nth program-code i)
opening-bracket (recur (direction i) (inc opened))
closing-bracket (if (zero? opened) i (recur (direction i) (dec opened)))
(recur (direction i) opened))))]
(loop [cells [0N], current-cell 0, instruction-pointer 0]
\[ (recur cells current-cell (inc (if (zero? (nth cells current-cell))
(find-bracket \[ \] instruction-pointer inc)
instruction-pointer)))
\] (recur cells current-cell (find-bracket \] \[ instruction-pointer dec))
find-bracket (fn [opening-bracket closing-bracket instruction-pointer direction]
(loop [i (direction instruction-pointer) opened 0]
(condp = (nth program-code i)
opening-bracket (recur (direction i) (inc opened))
closing-bracket (if (zero? opened) i (recur (direction i) (dec opened)))
(recur (direction i) opened))))
\< (recur cells (dec current-cell) (inc instruction-pointer))
\> (let [
next-ptr (inc current-cell)
next-cells (if (= next-ptr (count cells))
(conj cells 0N)
cells)]
(recur next-cells next-ptr (inc instruction-pointer)))
(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))
\. (do
(print (char (nth cells current-cell)))
(recur cells current-cell (inc instruction-pointer)))
\, (let [ch (.read System/in)]
(recur (assoc cells current-cell ch) current-cell (inc instruction-pointer)))
(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)))))
(defn bf-interpreter [program-code]
(loop instruction-pointer 0]
(recur (inc instruction-pointer))))