Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Would someone write a mathematical proof showing this is always true?


  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.


Thank you for that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: