Skip to content

Instantly share code, notes, and snippets.

@RHDZMOTA
Created February 5, 2018 00:39
Show Gist options
  • Save RHDZMOTA/803ce028682b1c836488dbafc86ac916 to your computer and use it in GitHub Desktop.
Save RHDZMOTA/803ce028682b1c836488dbafc86ac916 to your computer and use it in GitHub Desktop.
Brilliant Basic Level: problem of the week of feb 5

1 X 2 X 3 X ... X 2018

My computer solves for the above product and finds its digit sum (sum of all its digits). It then repeats this process of calculating the digit sum until only one digit remains.

What digit is that?

import math
number = math.factorial(2018)
number_str = str(number)
while (len(number_str) != 1):
number = sum([int(i) for i in number_str])
number_str = str(number)
print("Digit %s: " % number_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment