/grains.clj Secret
Created
July 10, 2014 00:38
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
(ns grains) | |
(defn- grains [] | |
(letfn | |
[(f [n] | |
(seq [n (fn [] (f (* 2 n)))]))] | |
(f 1N))) | |
(defn- stream-for-n-steps [stream n] | |
(letfn | |
[(f [i stream-rest] | |
(let | |
[pair (stream-rest)] | |
(when (not= i 0) | |
(cons (first pair) | |
(f (- i 1) (second pair))))))] | |
(f n stream))) | |
(defn square [sqr-num] | |
(last (stream-for-n-steps grains sqr-num))) | |
(defn total [] | |
(reduce + 0 (stream-for-n-steps grains 64))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment