Comment by ryao 1 year ago Would someone write a mathematical proof showing this is always true? 2 comments ryao Reply afiodorov 1 year ago a = [int(x) for x in str(n)][::-1] assert n == sum(d*(10**i) for i, d in enumerate(a)) Now when you're operating mod 9, 10 == 1 % 9, thus 10**i == 1 % 9 Comes from the fact that (a*b) % 9 == (a % 9) * (b % 9) Now using (a+b) % 9 == (a % 9) + (b % 9) We get that that sum(a) and n are same mod 9. ryao 1 year ago Thank you for that.
afiodorov 1 year ago a = [int(x) for x in str(n)][::-1] assert n == sum(d*(10**i) for i, d in enumerate(a)) Now when you're operating mod 9, 10 == 1 % 9, thus 10**i == 1 % 9 Comes from the fact that (a*b) % 9 == (a % 9) * (b % 9) Now using (a+b) % 9 == (a % 9) + (b % 9) We get that that sum(a) and n are same mod 9. ryao 1 year ago Thank you for that.
Now when you're operating mod 9, 10 == 1 % 9, thus
Comes from the fact that
Now using
We get that that sum(a) and n are same mod 9.
Thank you for that.