This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns defn-test | |
(:use clj-html.core | |
[net.cgrand.moustache :only [app]] | |
[ring.adapter.jetty :only [run-jetty]] | |
[ring.util.response :only [response]])) | |
(defhtml application [text body] | |
[:html | |
[:head | |
[:title text]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns vector-math.core | |
(:import [javax.vecmath Vector2d])) | |
(defprotocol Vec2Math | |
(add [this other])) | |
(deftype vec2 | |
[#^float x #^float y] :as this | |
Vec2Math | |
(add [other] (vec2. (+ x (.x #^vec2 other)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns vector-math.core | |
(:import [javax.vecmath Vector2d])) | |
(def epsilon 1e-6) | |
(defprotocol Vec2Math | |
(add [this other]) | |
(sub [this other]) | |
(mul [this scalar]) | |
(div [this scalar]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns flocking.flocking3 | |
(:use [vecmath.vec2 :only [vec2 zero sum]] | |
clojure.contrib.pprint) | |
(:require [rosado.processing :as p] | |
[rosado.processing.applet :as applet] | |
[vecmath.core :as vm])) | |
(deftype dist-boid | |
[loc vel acc r max-speed max-force dist] | |
clojure.lang.IPersistentMap) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.walk :only [postwalk]]) | |
(use '[clojure.contrib.macro-utils :only [mexpand-all]]) | |
(defn casted? [expr] | |
(when-let [[_ x] expr] | |
(when (and (coll? x) (#{'float 'int 'double 'long 'short 'byte} (first x))) | |
true))) | |
(defn to-prim-op [type] | |
(fn [expr] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn pearson-fast | |
[v1 v2] | |
(let [v1 (doubles v1) | |
v2 (doubles v2) | |
dim (double (count v1)) | |
meanv1 (/ (areduce v1 i ret 0 | |
(+ ret (aget v1 i))) dim) | |
meanv2 (/ (areduce v2 i ret 0 | |
(+ ret (aget v2 i))) dim) | |
sum (areduce v1 i ret 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; from Learn You A Haskell Real Good | |
; rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24 ] | |
(def right-triangles | |
(let [r (range 1 11)] | |
(for [c r | |
b r :when (< b c) | |
a r :when (< a b) | |
:when (and (= (+ (* a a) (* b b)) (* c c)) | |
(= (+ a b c) 24))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cellular-automata-basic) | |
(definterface AutomataOps | |
(^long getCell [^long i ^long j]) | |
(^long sumEightNeighbors [^long i ^long j]) | |
(^long urEightNeighMinmax [^long i ^long j]) | |
(^long rule [^long i ^long j])) | |
(defprotocol Automata | |
(update [this])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(definterface IntToIntFn | |
(#^int call [^int n])) | |
(def fibr | |
(let [one (int 1) | |
two (int 2)] | |
(reify | |
IntToIntFn | |
(call [this n] | |
(if (>= one n) one (+ (.call this (dec n)) (.call this (- n two)))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ^:static sum-8-neighbors ^long [dv ^long i ^long j ^long ncols] | |
(let [dv (longs dv) | |
v (longs (let [v1631 (longs (make-array Long/TYPE 8))] | |
(aset v1631 0 (aget dv (+ (* (dec i) ncols) (dec j)))) | |
(aset v1631 1 (aget dv (+ (* (dec i) ncols) j))) | |
(aset v1631 2 (aget dv (+ (* (dec i) ncols) (inc j)))) | |
(aset v1631 3 (aget dv (+ (* i ncols) (inc j)))) | |
(aset v1631 4 (aget dv (+ (* (inc i) ncols) (inc j)))) | |
(aset v1631 5 (aget dv (+ (* (inc i) ncols) j))) | |
(aset v1631 6 (aget dv (+ (* (inc i) ncols) (dec j)))) |