Last active
October 19, 2023 13:55
-
-
Save kaic/247d99b6d559c259928b9777dd393d16 to your computer and use it in GitHub Desktop.
Digital Root Clojure Solution 1
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
| (ns digital-root | |
| (:require [clojure.string :as str])) | |
| (defn split-numbers [n] | |
| (str/split (str n) #"")) | |
| (defn sum-numbers [numbers] | |
| (reduce (fn [sum number] | |
| (+ (int sum) (Integer/parseInt number))) | |
| 0 numbers)) | |
| (defn digital-root [n] | |
| (let [splited-numbers (split-numbers n) | |
| result (sum-numbers splited-numbers)] | |
| (if (< result 10) result | |
| (recur result)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment