# Primetime!

My pal Doug made a feature request for the solar metric clock: Add an indicator that tells you when the displayed time is a prime number. This comports with my obsession with primes and my desire to keep futzing with this project endlessly.

So of course I did it.

I decided not to regard the hh:mm time as a single number for this purpose. Hours and minutes are counting quantities differently, so it doesn’t seem right to regard that as a scalar. But both the solar and the local metric times do make sense as scalars.

I thought I would compute all the primes less than the maximum displayable number (9999) at startup, save them to a sparse vector and do a fast lookup on demand to see if the time was prime. Doug and I talked about the approach. He reasoned that, if Elon were to make any changes to the simulation we all live in, then the prime numbers might change, so it would be safest to compute them at power up. That made sense.

Unfortunately, my Arduino Uno Wifi Rev2 board doesn’t have enough memory for the Sieve of Eratosthenes algorithm’s data structures and the lookup vector I wanted to use. One of the interesting things about the Arduino compute platform is that it’s resource-constrained. It takes me back to writing applications on the Apple II when I was in high school: You have to pay attention to making things small and efficient.

It turns out that you can determine the primality of any number up to 10,000 by checking its divisibility by the primes up to the first prime after the square root of 10,000. This isn’t enough for computing factors, just for determining primality. I won’t lay out the number theory here because it’s kind of fun to figure out for yourself.

I hard-coded the array [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101] into the clock and test for divisibility each time I paint a metric time on one of 4-digit, 7-segment displays. This is actually pretty efficient: Half the numbers are knocked out by testing against 2, and so on.

When the time is prime, I light up the decimal point following the final digit:

I enjoy noticing when it’s prime time. It happens pretty often that both the solar and local metric times displayed are prime. That’s a double jolt of number-theoretic endorphins!