Created
October 26, 2017 11:30
-
-
Save katsuyan/189f9b8921318b891551233b6794f841 to your computer and use it in GitHub Desktop.
数学パズルonClojure-Q14
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
(ns puzzule.q14) | |
(def countries_org ["Brazil", "Croatia", "Mexico", "Cameroon", "Spain", "Netherlands", | |
"China", "Australia", "Colombia", "Greece", "Cote d'Ivoire", "Japan", | |
"Uruguay", "Costa Rica", "England", "Italy", "Switzerland", "Euador", | |
"France", "Honduras", "Argentina", "Bosnia and Herzegovina", "Iran", | |
"Nigeria", "Germany", "Portugal", "Ghana", "USA", "Belgium", "Algeria", | |
"Russia", "Korea Republic"]) | |
(def countries (map #(.toLowerCase %) countries_org)) | |
(defn char-range [start end] | |
(map char (range (int start) (inc (int end))))) | |
(def a-to-z (map str (char-range \a \z))) | |
(defn filter-from-initial [initial strs] | |
(filter #(= (first %) initial) strs)) | |
(defn max-shiritori [prev countries] | |
(let [filtered-countris (filter-from-initial (last prev) countries)] | |
(if (= 0 (count filtered-countris)) | |
0 | |
(+ 1 (apply max (map #(max-shiritori % (remove #{%} countries)) filtered-countris)))))) | |
(def answer (apply max (map #(max-shiritori % countries) a-to-z))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment