Skip to content

Instantly share code, notes, and snippets.

View ypsilon-takai's full-sized avatar
😊
taking care of things around myself

Ypsilon.takai ypsilon-takai

😊
taking care of things around myself
View GitHub Profile
@ypsilon-takai
ypsilon-takai / pe_62.clj
Created November 17, 2011 10:09
project euler 62
;; 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))
@ypsilon-takai
ypsilon-takai / pe_63.clj
Created November 17, 2011 10:10
project euler 63
;; 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)]
@ypsilon-takai
ypsilon-takai / pe_64.clj
Created November 18, 2011 09:10
project euler 64
;; Problem 64 : 2011/11/25
;; "Elapsed time: 755.433163 msecs"
;; (sqrt X)+M
;; -----------
;; N
(defn int-floor [n]
(Math/round (Math/floor n)))
@ypsilon-takai
ypsilon-takai / pe_65.clj
Created November 25, 2011 11:55
project euler 65
;; 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
@ypsilon-takai
ypsilon-takai / pe_67.clj
Last active September 28, 2015 06:38
project euler 67
;; 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)]
@ypsilon-takai
ypsilon-takai / pe_66.clj
Created November 29, 2011 04:18
project euler 66
;; 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)))
@ypsilon-takai
ypsilon-takai / pe_68.clj
Created December 1, 2011 06:33
project euler 68
;; 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)))
@ypsilon-takai
ypsilon-takai / pe_69.clj
Last active September 28, 2015 10:09
project euler 69
;; 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)
@ypsilon-takai
ypsilon-takai / pe_70.clj
Created December 8, 2011 08:44
project euler 70
;; 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 %))
@ypsilon-takai
ypsilon-takai / pe_71.clj
Created December 8, 2011 10:54
project euler 71
;; 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)