Skip to content

Instantly share code, notes, and snippets.

@pawelkijowskizimperium
Last active December 10, 2018 02:20
Efficient digital root
import UIKit
func digitalRoot(of number: Int) -> Int {
if (number <= 0) {
return number
} else if (number % 9 == 0) {
return 9
} else {
return number % 9
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment