Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library

Comment by ActivePattern

1 year ago

Doing a single modulo 9 operation is much faster than summing a d-digit number, which requires d modulo 10s, d divide 10s, and d sums.

2 comments

ActivePattern

Reply

brabel  1 year ago

You can do the sum by looking directly at the digits in the string, no need for module at all.

  • Jensson  1 year ago

    Number to string is even more expensive.

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities