Skip to content

Instantly share code, notes, and snippets.

@igorw
igorw / README.md
Last active August 29, 2015 14:15
bf

bf

A Clojure library designed to ... well, that part is up to you.

Usage

$ lein run ">++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>>+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++."
Hello World!

License

(ns fannkuch.core
(:require [clojure.math.combinatorics :as combo]))
; Fannkuchen
;
; it's super slow though
; also I was too stupid to implement permutations, so I used Mark Engelberg's library
;
; https://www.haskell.org/haskellwiki/Shootout/Fannkuch
--- divmod2.s 2015-01-09 21:58:10.000000000 +0100
+++ divmod.s 2015-01-09 21:56:08.000000000 +0100
@@ -12,20 +12,27 @@
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
- leaq _divmod.n(%rip), %rax
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
- movl -4(%rbp), %esi
(ns divmod.core)
; division by repeated subtraction
; http://en.wikipedia.org/wiki/Division_algorithm#Division_by_repeated_subtraction
(defn divmod
[n d]
(cond
(= d 0) (throw (Throwable. "Division By Zero"))
(< d 0)
@igorw
igorw / mu.scm
Created January 7, 2015 09:23
GEB MU puzzle in miniKanren
; Douglas Hofstadter's MU puzzle from Gödel, Escher, Bach
; written in miniKanren
;
; https://github.com/miniKanren/miniKanren/blob/master/mk.scm
(load "mk.scm")
(define print
(lambda (exp)
(display exp)
<?php
$permutations = [
['a', 'c', 'f'],
['b', 'd'],
['a', 'b', 'd'],
['e', 'f'],
];
/*
(ns interp.core)
(def empty-state {:ip 0, :code [], :stack '(), :labels {}})
(defn step
[state]
(let [instr (get (:code state) (:ip state))
state (update-in state [:ip] inc)]
(cond
(nil? instr)
<?php
// AVL tree
class Node {
public $value;
public $left;
public $right;
public $height;
@igorw
igorw / fox-goose-bag-of-corn.scm
Created December 28, 2014 17:50
miniKanren implementation of Lewis Carroll's "Fox, Goose, and Bag of Corn" puzzle, described by Carin Meier (@gigasquid)
; miniKanren solution to fox-goose-bag-of-corn
; https://github.com/gigasquid/wonderland-clojure-katas/blob/master/fox-goose-bag-of-corn/README.md
(load "mk.scm")
(define print
(lambda (exp)
(display exp)
(newline)))
@igorw
igorw / fizz-buzzo.scm
Last active August 29, 2015 14:12
fizzbuzz in miniKanren. See also minikanren.org and github.com/webyrd/miniKanren-uncourse
(load "mk.scm")
(define print
(lambda (exp)
(display exp)
(newline)))
(define peanoo
(lambda (n)
(conde