Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Created November 25, 2011 11:55
Show Gist options
  • Select an option

  • Save ypsilon-takai/1393359 to your computer and use it in GitHub Desktop.

Select an option

Save ypsilon-takai/1393359 to your computer and use it in GitHub Desktop.
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
(= 1 n) (a-seq 0)
:else (+ (* (a-seq (dec n))
(cf-numerator (dec n) a-seq))
(cf-numerator (- n 2) a-seq))))
(defn-memo cf-denominator [n a-seq]
(cond (zero? n) 0
(= 1 n) 1
:else (+ (* (a-seq (dec n))
(cf-denominator (dec n) a-seq))
(cf-denominator (- n 2) a-seq))))
(defn pe-65 [n]
(sum-of-digits (cf-numerator n cf-seq-of-e)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment