Created
September 3, 2015 13:23
-
-
Save onemouth/42cb35242389b17ef570 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
(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