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.
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.
You can do the sum by looking directly at the digits in the string, no need for module at all.
Number to string is even more expensive.