Skip to content

Instantly share code, notes, and snippets.

@pawelkijowskizimperium
Last active December 10, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelkijowskizimperium/b8ed6ae939f554ef8c88a9e99ed1c70c to your computer and use it in GitHub Desktop.
Save pawelkijowskizimperium/b8ed6ae939f554ef8c88a9e99ed1c70c to your computer and use it in GitHub Desktop.
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