Skip to content

Instantly share code, notes, and snippets.

@littleredcomputer
littleredcomputer / wordladder.py
Last active Sep 25, 2015
maximum-length minimal word ladders
View wordladder.py
#!/usr/local/bin/python3
import sys
from networkx import nx
from pprint import pprint
from functools import reduce
N = 4
words=[w.strip()
View pell.clj
(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]]
View pell.clj
(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]]
View cf.clj
(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 Aug 29, 2015
Egyptian fractions in Clojure
View gist:9fed7db435d24522fbdb
(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)))))))))
View Bugs1.pde
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;
View gist:3140e7cb57c4095ed83f
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)
View gist:46a7d17c3126179863c4
void setup () {
fill(255,0,60);
stroke(0);
rect(50,50,10,10);
}