Skip to content

Instantly share code, notes, and snippets.

@JoshMock
Created July 7, 2014 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshMock/c21ca7e719f8cbc0be69 to your computer and use it in GitHub Desktop.
Save JoshMock/c21ca7e719f8cbc0be69 to your computer and use it in GitHub Desktop.
(defn calc-height-step [height current-step]
(if (= 1 (mod current-step 2))
(* height 2)
(+ height 1)))
(defn calc-height []
(def steps (Integer/parseInt (read-line)))
(println (reduce calc-height-step 1 (range 1 (+ steps 1)))))
(def t (Integer/parseInt (read-line)))
(dotimes [n t] (calc-height))
@puredanger
Copy link

It is highly preferred to avoid def inside a defn - use a let!

(let [steps (Integer/parseInt (read-line))]
  (println (reduce calc-height-step 1 (range 1 (+ steps 1)))))

@ericnormand
Copy link

Nice job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment