Last active
December 6, 2016 04:36
-
-
Save katsuyan/4d023fd4af52e010cbd3d875e3200853 to your computer and use it in GitHub Desktop.
数学パズルonClojure-Q3
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
(defn make-cards [num] | |
(for [x (range 1 (inc num)) y [false]] [x y])) | |
(defn reverse-cards [cards reverse-num] | |
(map (fn [[num side]] | |
(if (= 0 (mod num reverse-num)) | |
[num (not side)] | |
[num side])) | |
cards)) | |
(defn reverse-recur [cards num] | |
(if (= num (count cards)) | |
(reverse-cards cards num) | |
(recur (reverse-cards cards num) (inc num)))) | |
(defn get-answer [card-num start-num] | |
(let [cards (make-cards card-num)] | |
(map (fn [[num _]] num) | |
(filter (fn [[_ side]] (not side)) | |
(reverse-recur cards start-num))))) | |
(def N 100) | |
(def START 2) | |
(def answer (get-answer N START)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment