Skip to content

Instantly share code, notes, and snippets.

@onemouth
Created September 3, 2015 13:23
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 onemouth/42cb35242389b17ef570 to your computer and use it in GitHub Desktop.
Save onemouth/42cb35242389b17ef570 to your computer and use it in GitHub Desktop.
(require '[clojure.string :as str])
(defn parse-str-to-cells [str-cells]
(->> (str/split str-cells #"\s+")
(mapv #(Integer. %))))
(defn is-end-by-num-of-cell [n]
#(= (dec n) %))
(defn step [wheel cells is-end?]
(loop [history #{}
start-point 0
next-add wheel]
(let [next-point (+ start-point next-add)]
(cond
(is-end? start-point) "Yes"
(nil? (get cells next-point)) "No"
(= next-point start-point) "No"
(contains? history next-point) "No"
:else (recur (conj history start-point)
next-point
(get cells next-point))))))
(let [num-of-cell (Integer. (read-line))
is-end? (is-end-by-num-of-cell num-of-cell)
cells (parse-str-to-cells (read-line))
n-input (Integer. (read-line))]
(doseq [x (range n-input)]
(println (step (Integer. (read-line)) cells is-end?))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment