The Two Billion Towers of Time

Wednesday, October 11 2023

When the final tower is completed, time will overflow.

This animation counts down to the Epochalypse by displaying the current Unix time as progress in solving a 31 level Tower of Hanoi.

Unix Time

Unix time is the number of seconds which have passed since midnight UTC, January 1, 1970, the Unix epoch. Computers use Unix time internally to store when an event occurred as a single number. Unlike regular1 timestamps, Unix timestamps are never repeated or skipped. This number can then be converted into the user’s calendar, timezone, and language. The current Unix time is [the current unix time].

Epochalypse

Many pieces of software store Unix time in 32-bit signed integers. This data type has a limited range, so at some point in the future the current Unix time will exceed the allocated space and cause problems. This will occur 2 31 seconds after the Unix epoch, at 3:14:08 UTC January 19, 2038.

Tower of Hanoi

The Tower of Hanoi is a puzzle about moving a stack of discs from a first position to a third position. Its difficulty comes from three restrictions. First, the player may only move one disc at a time. Second, the player may never place a larger disc onto a smaller disc. Last, the discs must be placed in one of only three stacks, including the starting and ending positions.

As the number of discs increases, the number of moves it takes to solve the puzzle grows exponentially. For three discs, the puzzle can be solved in seven moves, but for 31 discs, the solution requires over two billion moves.

Animation

There are a few neat things going on here.

  • Most algorithms for solving the Tower of Hanoi compute each step in order2. This one computes the k-th state directly.
  • It is possible to recover the exact date and time from the animation!
  • The arcing path of the moving piece is optimized to minimize its maximum x and y acceleration.
  • This is my first time animating with JavaScript and the canvas API.

  1. Such as Sunday, November 5, 2023, 1:30am, which occurred twice in time zones that observed Daylight Savings Time. ↩︎

  2. For example, this lesson on Kahn Academy ↩︎