Created
March 16, 2010 00:40
-
-
Save foogoof/333504 to your computer and use it in GitHub Desktop.
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
(defn nth-val [first-val step val-count] | |
(+ first-val (* step (dec val-count)))) | |
(defn arithmetic-series [first-val step val-count] | |
(let [last-val (nth-val first-val step val-count)] | |
(* val-count | |
(/ (+ first-val last-val) 2)))) | |
(defn arithmetic-series-of-multiples-less-than [ceiling] | |
(fn [val] | |
(arithmetic-series val val (quot (dec ceiling) val)))) | |
(defn prob1 [val1 val2 ceiling] | |
(let [calc-series (arithmetic-series-of-multiples-less-than ceiling) | |
val1-series (calc-series val1) | |
val2-series (calc-series val2) | |
multiples-series (calc-series (* val1 val2))] | |
(- (+ val1-series val2-series) multiples-series))) | |
(time (prob1 3 5 1e3)) | |
(time (prob1 3 5 1e30)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment