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 *stack (ref nil)) | |
| (defn push [x] | |
| #_(println x) | |
| (dosync (ref-set *stack (cons x @*stack)))) | |
| (defn pre-push [v] | |
| (doseq [i (range 8) j (range 8) :when (<= i j)] | |
| #_(println (subvec v i (inc j))) | |
| (when (every? #(= % "0") (subvec v i (inc j))) | |
| (let [new-v (cond | |
| (= i 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
| (def +score+ (atom 0)) | |
| (def +answer+ (atom nil)) | |
| (defn new-game [] | |
| (reset! +answer+ (->> (range 4) | |
| (map #(list % (rem (inc %) 4))) | |
| (map (comp inc first shuffle)) | |
| (shuffle))) | |
| (reset! +score+ 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
| (defn max-visits [visits time] | |
| (reduce (fn [num t] (if (> time t) (dec num) num)) | |
| (reduce (fn [num t] (if (> time t) (inc num) num)) 0 (first visits)) | |
| (second visits))) | |
| (def GUESTS 30) | |
| (def starts (map (fn [x] (int (* (rand) 24))) (range GUESTS))) | |
| (def ends (map #(int (+ (* (- 24 %) (rand)) %)) starts)) | |
| (def visits [(sort > starts) (sort > ends)]) |
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 'korma.core) | |
| (use 'korma.db) | |
| (import '(java.io FileOutputStream)) | |
| (import '(org.apache.poi.ss.usermodel Cell Row Sheet Workbook)) | |
| (import '(org.apache.poi.xssf.streaming SXSSFWorkbook)) | |
| (defdb +db24+ | |
| (mssql | |
| {:user "xx" | |
| :password "xxxxxxxxxx" |
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
| (defmacro defenum [class & symbols] | |
| (try (Class/forName (str class)) | |
| (catch java.lang.ClassNotFoundException e | |
| (gen-and-load-class (str class) :extends java.lang.Enum))) | |
| (cons 'do | |
| (map (fn [sym val] | |
| `(def ~symbol (new ~class ~(str sym) ~val))) | |
| symbols (iterate inc 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
| (def +time-hashes+ (agent [])) | |
| (def +time-hashes-gc-interval+ 1800000) ; 30 minutes | |
| (def ^:dynamic *time-hashes-gc-stop?* false) | |
| (defn time-hash [] | |
| (let [result (ref {:shutdown? false :hash {}})] | |
| (send +time-hashes+ (partial cons result)) | |
| result)) | |
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
| // http://code.google.com/p/clojure/downloads/list | |
| // javac TestClojureScript.java | |
| // java -cp .;clojure.jar TestClojureScript script1.clj # => 20 | |
| // java -cp .;clojure.jar TestClojureScript script2.clj # => 40 | |
| import clojure.lang.RT; | |
| import clojure.lang.Var; | |
| public class TestClojureScript { | |
| public static void main(String[] args){ |