Skip to content

Instantly share code, notes, and snippets.

@alandipert
alandipert / gist:1144670
Created August 14, 2011 07:28 — forked from micha/gist:997056
Euler project problem #1
; 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:
;
(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]
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)
@alandipert
alandipert / glob.clj
Created March 28, 2010 00:04 — forked from jkk/glob.clj
(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)
(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)))]
load(["lib/underscore.js"]);
load(["lib/json2.js"]);
var fact = ['def', 'fact', ['fn', ['n'],
['if', ['<=', 'n', 2],
'n',
['*', 'n', ['fact', ['-', 'n', 1]]]]]]
var infix = ['+', '-', '*', '/', '<', '>', '<=', '>='];
(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]
/*
/-------------\
/ \
/ \
/ \
| XXXX XXXX |
| XXXX XXXX |
| XXX XXX |
\ X /
--\ XXX /--
@alandipert
alandipert / let.rb
Created February 2, 2010 05:55 — forked from anonymous/let.rb
def let(binds, &body)
eval("proc{|#{binds.keys.join(',')}| body }").call(*binds.values).call
end
let(:a => 10, :b => 20) {
puts a,b
}
@alandipert
alandipert / char.c
Created January 31, 2010 22:00 — forked from anonymous/char.c
#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"
};