Created
September 17, 2017 01:06
-
-
Save katsuyan/6eb06c48e8b7aada44b0f51eeba31fb4 to your computer and use it in GitHub Desktop.
数学パズルonClojure-Q11
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.q11) | |
(def fibs (lazy-cat [1 1] (map + fibs (rest fibs)))) | |
(defn num-to-digits [num] | |
(loop [n num res []] | |
(if (zero? n) | |
res | |
(recur (quot n 10) (cons (mod n 10) res))))) | |
(defn num-to-digits-sum [num] | |
(reduce + (num-to-digits num))) | |
(defn be-divisible? [num] | |
(= 0 (mod num (num-to-digits-sum num)))) | |
(def answer (take 13 (filter be-divisible? fibs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment