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 62 : 2011/11/17 | |
;; "Elapsed time: 2139.92309 msecs" | |
(defn pe62 [tgt-count] | |
(loop [num 9 | |
res-map {}] | |
(let [cubed (* num num num) | |
num-key (sort (num-to-list cubed))] | |
(if (= (dec tgt-count) (count (res-map num-key))) | |
(cons num (res-map num-key)) |
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 63 : 2011/11/17 | |
;; "Elapsed time: 1.326705 msecs" | |
(require '[clojure.contrib.math :as math]) | |
(defn digits-of-pow [x n] | |
(count (str (math/expt x n)))) | |
(defn pe63 [] | |
(for [x (range 1 10)] |
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 64 : 2011/11/25 | |
;; "Elapsed time: 755.433163 msecs" | |
;; (sqrt X)+M | |
;; ----------- | |
;; N | |
(defn int-floor [n] | |
(Math/round (Math/floor 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 65 : 2011/11/25 | |
;; "Elapsed time: 3.193423 msecs" | |
(defn cf-seq-of-e [n] | |
(cond (zero? n) 2 | |
(= (rem n 3) 2) (* 2 (/ (inc n) 3)) | |
:else 1)) | |
(defn-memo cf-numerator [n a-seq] | |
(cond (zero? n) 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
;; reviced for clojure 1.4 | |
;; Problem 67 : 2011/11/28 | |
;; "Elapsed time: 52.128413 msecs" | |
(defn pe-67 [input-list] | |
(apply max | |
(reduce (fn [root new] | |
(let [rt-r (cons 0 root) | |
rt-l (conj root 0)] |
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 66 : 2011/11/29 | |
;; "Elapsed time: 67.348225 msecs" | |
;; treat all num as | |
;; (sqrt X)+M | |
;; ----------- | |
;; N | |
(defn int-floor [x] | |
(Math/round (Math/floor x))) |
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 68 : 2011/12/1 | |
;;"Elapsed time: 89.450754 msecs" | |
(defn check-pe68 [tgt] | |
(let [[[a2 a3 a4 a5] [b1 b2 b3 b4 b5]] tgt] | |
(if (= 14 | |
(+ 6 b1 b2) (+ a2 b2 b3) (+ a3 b3 b4) | |
(+ a4 b4 b5) (+ a5 b5 b1)) | |
[6 b1 b2 a2 b2 b3 a3 b3 b4 a4 b4 b5 a5 b5 b1] | |
false))) |
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 69 : 2011/12/6 | |
;; This needs too long time. | |
;; "Elapsed time: 980693.545995 msecs" | |
(defn get-n-slash-phi-n [n] | |
(/ 1 (reduce * (map #(- 1 (/ 1 %)) (distinct (factors n)))))) | |
(defn pe-69 [end-val] | |
(reduce #(if (> (first %1) (first %2)) %1 %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
;; Problem 70 : 2011/12/8 | |
;; "Elapsed time: 19858.886534 msecs" | |
(defn permutation-num? [n m] | |
(= (sort (seq (str n))) | |
(sort (seq (str m))))) | |
(defn pe-70 [limit] | |
(reduce #(if (< (first %1) (first %2)) %1 %2) | |
(filter #(permutation-num? (second %) (last %)) |
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 71 : 2011/12/8 | |
;; "Elapsed time: 151.987474 msecs" | |
(defn my-numerator [n] | |
(if (integer? n) | |
n | |
(numerator (rationalize n)))) | |
(defn my-denominator [n] | |
(if (integer? n) |