Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@skensell
skensell / ScottsSnake.elm
Created May 30, 2014 15:46
snake game in Elm
--- module ScottsSnake where
import Keyboard
import Random
import String
import Set
type Position = {x: Int, y: Int }
type Board = {w: Int, h: Int, wall: [Position]}
type Apple = Position
(defn ack [m n]
(cond (zero? m) (inc n)
(zero? n) (ack (dec m) 1)
:else (ack (dec m) (ack m (dec n)))))
(defn ack-cps
([m n] (ack-cps m n identity))
([m n k]
(loop [m m, n n, k k]
(cond (zero? m) (k (inc n))
@amalloy
amalloy / gist:1420686
Created December 1, 2011 23:29
.ssh/config
Host nfsn
Hostname ssh.phx.nearlyfreespeech.net
Host *
IdentityFile ~/.ssh/id_fibonatch_auto
IdentityFile ~/.ssh/id_fibonatch_weak
(ns shuffle.core
(:use (incanter core charts)))
; naive, O(n+m)
(defn take-rand1 [n coll] (take n (shuffle coll)))
; lazy, O(n!@#$%m^&)
(defn take-rand2 [n coll]
(let [coll (vec coll)]
(take n (distinct (repeatedly #(rand-nth coll))))))
(defn tricky-logic [x]
(cond (or (cheap-test1)
(expensive-test))
(...body1...)
(and (cheap-test2)
(expensive-test))
(...body2...)
:else (expensive-test)))
;; rewrite to avoid repeating tests *or* code:
(defn my-memo [f]
(let [cache (atom {})]
(fn [& args]
(force (get (swap! cache update-in [args]
#(or % (delay (apply f args))))
args)))))
####################################
# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/
# Last tested & updated 10/13/2011
####################################
sudo apt-get update
sudo apt-get upgrade
(->> [1]
(iterate (fn [row]
(for [[a b] (partition 2 1
(concat [0] row [0]))]
(+ a b))))
(take 10))
([1] (1 1) (1 2 1) (1 3 3 1) (1 4 6 4 1) (1 5 10 10 5 1) (1 6 15 20 15 6 1) (1 7 21 35 35 21 7 1) (1 8 28 56 70 56 28 8 1) (1 9 36 84 126 126 84 36 9 1))
;; amalloy's solution to http://4clojure.com/problem/58
(fn [& fs]
(reduce (fn [f g]
(fn [& x] (f (apply g x))))
fs))
(ns shuffle.core
(:use (incanter core charts)))
; naive, O(n+m)
(defn take-rand1 [n coll] (take n (shuffle coll)))
; lazy, O(n!@#$%m^&)
(defn take-rand2 [n coll]
(let [coll (vec coll)]
(take n (distinct (repeatedly #(rand-nth coll))))))