Last active
August 29, 2020 00:37
-
-
Save MarcusGoldschmidt/dcae16f27ca6f10a6250fac37499541d to your computer and use it in GitHub Desktop.
Clojure: Number divisible by eleven
This file contains hidden or 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 string-to-number [number-string] | |
(let [convert (int \0)] | |
(map #(- (int %) convert) number-string))) | |
(defn map-by-index [numbers] | |
(map-indexed #(if (even? %1) %2 (- %2)) numbers)) | |
(defn divide-even? [number-string] | |
(= 0 (mod (reduce + 0 (map-by-index (string-to-number number-string))) 11))) | |
(loop [user-input (read-line)] | |
(when (not= user-input "0") | |
(println (if (divide-even? user-input) "SIM" "NAO")) | |
(recur (read-line)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment