2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -2,12 +2,12 @@
|
|||
"Computes the unbounded sequence of Hamming 235 numbers."
|
||||
[]
|
||||
(letfn [(merge [xs ys]
|
||||
(let [xv (first xs), yv (first ys)]
|
||||
(if (< xv yv) (cons xv (lazy-seq (merge (next xs) ys)))
|
||||
(cons yv (lazy-seq (merge xs (next ys))))))),
|
||||
(if (nil? xs) ys
|
||||
(let [xv (first xs), yv (first ys)]
|
||||
(if (< xv yv) (cons xv (lazy-seq (merge (next xs) ys)))
|
||||
(cons yv (lazy-seq (merge xs (next ys)))))))),
|
||||
(smult [m s] ;; equiv to map (* m) s -- faster
|
||||
(cons (*' m (first s)) (lazy-seq (smult m (next s)))))]
|
||||
(do (def s5 (cons 5 (lazy-seq (smult 5 s5))))
|
||||
(def s35 (cons 3 (lazy-seq (merge s5 (smult 3 s35)))))
|
||||
(def s235 (cons 2 (lazy-seq (merge s35 (smult 2 s235)))))
|
||||
(cons 1 (lazy-seq s235)))))
|
||||
(cons (*' m (first s)) (lazy-seq (smult m (next s))))),
|
||||
(u [s n] (let [r (atom nil)]
|
||||
(reset! r (merge s (smult n (cons 1 (lazy-seq @r)))))))]
|
||||
(cons 1 (lazy-seq (reduce u nil (list 5 3 2))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue