loading...

re: Daily Challenge #264 - Digital Root VIEW POST

FULL DISCUSSION
 

Here's my solution in Python. Not bad considering I gave it only 5 minutes. I could have gone with reduce and lambda, but it's not really pythonic, not fast and the reading would be terrible. I like the short circuit behavior.

def digital_root(n):
  while True:
    n_list = [int(d) for d in str(n)]
    if len(n_list) == 1:
      return n
    n = sum(n_list)
Code of Conduct Report abuse