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
(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
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
(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
(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
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
(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
/* | |
/-------------\ | |
/ \ | |
/ \ | |
/ \ | |
| 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
def let(binds, &body) | |
eval("proc{|#{binds.keys.join(',')}| body }").call(*binds.values).call | |
end | |
let(:a => 10, :b => 20) { | |
puts a,b | |
} |
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
#include <stdio.h> | |
#define ID_SIZE 6 | |
// this is the array of authorized key strings that | |
// reader input is checked against | |
char *authorized_ids[] = { | |
"000013579EF3", | |
"\0" | |
}; |