Float Scales — Data Structures

Reorder float additions so the result comes out exact, even when 1e16 + 1 = 1e16: 18 levels of IEEE-754, the 2^53 limit and precision loss.

What you learn in this game

A JavaScript number is a 64-bit float (a double): it keeps 53 bits of significant digits, about 15 to 16 digits. The gap between two numbers it can write, its smallest step, grows with the number. Up to 2^53 (9007199254740992) every whole number can still be written; above it the step is 2, then 4, 8, 16. A sum is rounded to the nearest number that can be written, and when it lands exactly halfway, to the even one (its last bit 0). That is why 1e16 + 1 === 1e16, and why the order of a sum can change its result. This scale's display adds with JavaScript numbers, one load at a time; Mas Bayu's book adds with BigInt, with no rounding.

2^53 is the limit. Number.MAX_SAFE_INTEGER equals 253 - 1: the largest whole number whose neighbours can still be written too. From 253 up the gap to the next number is 2, so 253 + 1 lands exactly halfway and is rounded to the even one: back to 253. 253 + 2 is exactly one step, so it is recorded whole. Add the small ones while the display is small, or let the big ones cancel first.

When there are several pairs of giant stacks, the key is the same: never let a giant sit on the display while a small envelope goes on. Let each pair cancel, then put the envelope on, usually last.

What the levels ask

  1. Tap the loads one at a time: the waiting ones go on the scale, the ones on it come off.
  2. Order the loads on and off until the display matches the book.
  3. Order the loads on and off until the display matches the book.
  4. Order the loads on and off until the display matches the book.
  5. Order the loads on and off until the display matches the book.
  6. Order the loads on and off until the display matches the book.
  7. Order the loads on and off until the display matches the book.
  8. Order the loads on and off until the display matches the book.
  9. Order the loads on and off until the display matches the book.
  10. Order the loads on and off until the display matches the book.
  11. Order the loads on and off until the display matches the book.
  12. Order the loads on and off until the display matches the book.

And more, 18 levels in all.