This file contains 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; create memoised func | |
;; | |
;; momoize in clojure 1.2 and after does not work as I expected. So, I created this macro. | |
(defmacro defn-memo | |
"Creates memoised function. | |
Also creates: | |
accessor of the memoized data which named <fname>-data. | |
resetter of the memoized data which named <fname>-crear." |
This file contains 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
(require '[clojure.contrib.io :as io]) | |
(defn get-gcj-args-list [file-name] | |
(map list | |
(iterate inc 1) | |
(map (fn [line-dat] | |
(map (fn [s] (BigInteger. s)) | |
(.split line-dat " "))) | |
(drop 1 (io/read-lines file-name))))) |
This file contains 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 snapper [N K] | |
(if (= (repeat N \1) (take N (reverse (Integer/toBinaryString K)))) | |
"ON" | |
"OFF")) |
This file contains 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; prime nums | |
(defn sieve [n] | |
(let [n (int n)] | |
"Returns a list of all primes from 2 to n" | |
(let [root (int (Math/round (Math/floor (Math/sqrt n))))] | |
(loop [i (int 3) | |
a (int-array n) | |
result (list 2)] |
This file contains 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 jc-queue [one-set] | |
(flatten (repeat one-set))) | |
(defn run-jc [k q N] | |
"run jetcoaster once and returns revenue in euro" | |
(loop [seats k, rest k, queue q, revenue 0, group-num N] | |
(if (or | |
(< rest (first queue)) |
This file contains 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
(require '[clojure.contrib.io :as io]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Main funcs | |
;; step back | |
;; get previous position of the target card | |
(defn un-shuffle [W ab-list] | |
(let [[A B] ab-list] | |
(cond (<= W B) (+ W (- A 1)) |
This file contains 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
(require '[clojure.contrib.io :as io]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Main funcs | |
;; sort coffee data by | |
;; : in descending order with satisfaction | |
;; : and in accending order with expiry date. | |
(defn sort-coffee-data [dat-list] |
This file contains 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
(require '[clojure.contrib.io :as io]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Main funcs | |
;; find digits pair for a and b | |
;; returns [<total bit count> <carry>] | |
(defn check-one-digit [tgt-digit carry is-msb] |
This file contains 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.contrib.math) | |
(defn concat-num [n m] | |
(let [zeros (first (drop-while #(<= % m) (iterate #(* 10 %) 1)))] | |
(+ (* n zeros) m))) | |
(defn prime-pair? [n m] | |
(and (is-prime? (concat-num n m)) | |
(is-prime? (concat-num m n)))) |
This file contains 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
;; Problem 61 : 2011/11/16 | |
;;"Elapsed time: 1208.733513 msecs" | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; triangle, pentagonal, hexagonal, and so on. | |
;; 3 | |
(require '[clojure.contrib.math :as math]) | |
(defn triangle-num [n] | |
(/ (* n (+ 1 n)) 2)) |
OlderNewer