Hacker News new | past | comments | ask | show | jobs | submit login

When the person I was responding to said the largest JS int is 2^54-1 I assumed that meant I could use all integers in [0, 2^54-1], but you are right that I can only go up 2^53. That breaks the specific code I posted but not the underlying idea. Fixing it to deal with that lower upper bound is easy.

Just change the constant 10000000000000000 in the outer loop to 1000000000000000 (which is 2^49+437050046578688 and well below 2^53), change the filling of the right[] array to

  for (let r = 0; r < 10; ++r) {
    right.push('000' + itos(r) + '\n')
  }   
  for (let r = 10; r < 100; ++r) {
    right.push('00' + itos(r) + '\n')
  }   
  for (let r = 100; r < 1000; ++r) {
    right.push('0' + itos(r) + '\n')
  }   
  for (let r = 1000; r < 10000; ++r) {
    right.push(itos(r) + '\n')
  }
and change the loop that starts "for (let r = 1; r < 1000; ++r) {" to go to 10000 instead of 1000.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: