Skip to content

Instantly share code, notes, and snippets.

@littleredcomputer
littleredcomputer / wordladder.py
Last active September 25, 2015 20:27
maximum-length minimal word ladders
#!/usr/local/bin/python3
import sys
from networkx import nx
from pprint import pprint
from functools import reduce
N = 4
words=[w.strip()
(ns cf
(:require [clojure.math.numeric-tower :as nt]))
(defn- step [x-2 x-1 [a & as]]
(when a
(let [x (+ (* a x-1) x-2)]
(cons x (lazy-seq (step x-1 x as))))))
(defn convergents [as]
(let [c (fn c [[h & hs] [k & ks]]
(ns cf
(:require [clojure.math.numeric-tower :as nt]))
(defn- step [x-2 x-1 [a & as]]
(when a
(let [x (+ (* a x-1) x-2)]
(cons x (lazy-seq (step x-1 x as))))))
(defn convergents [as]
(let [c (fn c [[h & hs] [k & ks]]
(ns cf
(:require [clojure.math.numeric-tower :as nt]))
(defn- step [x-2 x-1 [a & as]]
(when a
(let [x (+ (* a x-1) x-2)]
(cons x (lazy-seq (step x-1 x as))))))
(defn convergents [as]
(let [c (fn c [[h & hs] [k & ks]]
@littleredcomputer
littleredcomputer / gist:9fed7db435d24522fbdb
Last active August 29, 2015 14:14
Egyptian fractions in Clojure
(ns ef
(:require [clojure.math.numeric-tower :as nt]))
(defn ef [r]
(loop [r r ef []]
(let [x (numerator r)
y (denominator r)]
(if (= x 1) (conj ef r)
(recur (/ (mod (- y) x) (* y (nt/ceil (/ y x))))
(conj ef (/ (nt/ceil (/ y x)))))))))
import java.util.ArrayList;
import java.util.List;
import processing.core.PVector;
List<Bug> bugs = new ArrayList<Bug>();
int w = 500;
abstract class Actor {
protected PVector pos;
protected float rot;
@littleredcomputer
littleredcomputer / gist:3140e7cb57c4095ed83f
Last active August 29, 2015 14:06
transducers in python
summer = lambda acc, val: acc+val
maxxer = lambda acc, val: max(acc, val)
unioner = lambda acc, val: acc.union({val})
def log(val):
print 'value:', val
return val
print reduce(summer, xrange(5), 0)
print reduce(maxxer, xrange(5), 0)
void setup () {
fill(255,0,60);
stroke(0);
rect(50,50,10,10);
}