Skip to content

Instantly share code, notes, and snippets.

@MarcusGoldschmidt
Last active August 29, 2020 00:37
Show Gist options
  • Save MarcusGoldschmidt/dcae16f27ca6f10a6250fac37499541d to your computer and use it in GitHub Desktop.
Save MarcusGoldschmidt/dcae16f27ca6f10a6250fac37499541d to your computer and use it in GitHub Desktop.
Clojure: Number divisible by eleven
(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