Skip to content

Instantly share code, notes, and snippets.

@foogoof
Created March 16, 2010 00:40
Show Gist options
  • Save foogoof/333504 to your computer and use it in GitHub Desktop.
Save foogoof/333504 to your computer and use it in GitHub Desktop.
(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