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
/* | |
/-------------\ | |
/ \ | |
/ \ | |
/ \ | |
| XXXX XXXX | | |
| XXXX XXXX | | |
| XXX XXX | | |
\ X / | |
--\ XXX /-- |
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 scorewords | |
(:use [clojure.test])) | |
(defn score-sub [words] | |
(map (fn [[word n]] [word (if (> n 3) | |
0 | |
(/ 1 n))]) (partition 2 (interleave words (iterate inc 2))))) | |
(defn score-words | |
([term words base] |
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
load(["lib/underscore.js"]); | |
load(["lib/json2.js"]); | |
var fact = ['def', 'fact', ['fn', ['n'], | |
['if', ['<=', 'n', 2], | |
'n', | |
['*', 'n', ['fact', ['-', 'n', 1]]]]]] | |
var infix = ['+', '-', '*', '/', '<', '>', '<=', '>=']; |
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 files-in-dir | |
([& dirs] | |
(map files-in-dir dirs)) | |
([dir] | |
(let [dirFile (File. dir)] | |
(.list dirFile))) | |
([dir suffix] | |
(let [dirFile (File. dir) | |
fileFilter (proxy [FilenameFilter] [] | |
(accept [dir name] (.endsWith name suffix)))] |
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
(set! *warn-on-reflection* true) | |
(defn bfs-seq [branch? children root] | |
"Same as tree-seq but walks the tree breadth-first instead | |
of depth-first." | |
(let [walk (fn walk [queue] | |
(when-let [node (peek queue)] | |
(lazy-seq | |
(cons node (walk (into (pop queue) | |
(when (branch? node) |
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
Imap.prototype.next: ((id, fmt) -> | |
prefix: (for i in [0...fmt.replace(/0/g, "").length] | |
(-> this.charAt(Math.random()*this.length)) | |
.call("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | |
).join("") | |
fmt: fmt.replace(/X/g, "") | |
return ( -> | |
id: ++id % (parseInt(fmt.replace(/0/g, "9")) + 1) |
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 org.jtornadoweb.cljhttputils | |
(:use [clojure.contrib.monads :only (domonad maybe-m)] | |
[clojure.contrib.str-utils2 :only (split)]) | |
(:gen-class | |
:name org.jtornadoweb.CljHttpUtils | |
:methods [[parseQueryString [String] java.util.HashMap]] | |
:main false)) | |
(defn- parse-qs | |
[uri] |
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
; Euler problem #1. Sum of integers between 1 and N which are | |
; divisible by i, j, k, ..., or l. | |
; | |
; The sum 1+2+3+...+n = (n^2 + n)/2, call this sum-range(n). | |
; | |
; Then the sum of i+2i+3i+...+qi = i * sum-range(floor(n/i)), where | |
; qi is the greatest multiple of i such that i <= n. | |
; | |
; For n=20, f(3,5) involves summing the rows in a table: | |
; |
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 Rack::Static, | |
:urls => ['/css', '/images'], # put directories here, files will get served for free | |
:root => "public" | |
run lambda { |env| | |
[ | |
200, | |
{ 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, | |
File.open('public/index.html', File::RDONLY) # Point this at the starting file | |
] |
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
class Lisp | |
def initialize | |
@env = { | |
:label => lambda { |(name,val), _| @env[name] = val }, | |
:quote => lambda { |sexpr, _| sexpr[0] }, | |
:car => lambda { |(list), _| list[0] }, | |
:cdr => lambda { |(list), _| list.drop 1 }, | |
:cons => lambda { |(e,cell), _| [e] + cell }, | |
:eq => lambda { |(l,r), _| l == r }, | |
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) }, |