Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 29, 2016 00:54
Show Gist options
  • Select an option

  • Save chrisguitarguy/dba464e673e76f1d97a1 to your computer and use it in GitHub Desktop.

Select an option

Save chrisguitarguy/dba464e673e76f1d97a1 to your computer and use it in GitHub Desktop.
(defn- read-int-line []
(Integer/parseInt (read-line)))
(defn- spring? [current-cycle]
(= 0 (mod current-cycle 2)))
(defn- tree-height-after [total-cycles]
(loop [current-cycle 0
height 1]
(if (>= current-cycle total-cycles)
height
(recur (inc current-cycle) (if (spring? current-cycle) (* 2 height) (inc height))))))
(defn run []
(let [tc-count (read-int-line)
test-cases (repeatedly tc-count read-int-line)]
(doseq [total-cycles test-cases]
(println (tree-height-after total-cycles)))))
(run)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment