Skip to content

The Great Digital Race (or ‘A 15-second Fib’)

Connie 1, WITCH 0


You can keep your Winter Olympics with all it’s competitive falling and sliding. The real action was last Saturday at The National Museum of Computing where you could witness the inaugural Great Digital Race. A simple proposition: How far can you get a computer through the Fibonacci sequence in fifteen seconds? What results do we get if we get computers from different eras to compete against each other?

Let’s address some basic questions first. What is a Fibonacci sequence? Well, it’s a good choice as it is surprisingly simple. Add the first two numbers together, i.e. 0 and 1, write the result (1) next to it and then add to the previous number. Repeat. Forever.

0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13

…and so on. You may notice that this sequence is growing in size exponentially. It will start hitting some very seriously long numbers very soon. Rather than just a mathematical curiosity, the Fibonacci sequence keeps turning up in nature again and again. It appears to be some immutable rule of evolution. When drawn as a curve you see the famous ‘golden ratio’ appear (Google it, I’m no Brian Cox). The head of a sunflower? The layout of the seeds? Fibonacci sequence. Cool, huh?

The key thing here is that it is easy to code, something like:

A = 0
B = 1
  SUM = A + B
  A = B
  B = SUM

So, enquiring minds at The National Museum of Computing wondered, how would the results change from era to era, running this simple code on a variety of machines? Let’s race.

For full information on the results, have a look at the TNMoC article. Of note was the WITCH, the oldest operating computer in the world, which managed a respectable 3 numbers in 15 seconds. WITCH was built for reliability not speed, so in fact she did well.

I’m going to concentrate on the device to which I was assigned, the BBC micro:bit, and it’s rather more powerful cousin, the iPhone.

A BBC micro:bit. Yesterday.

I was asked to code the micro:bit for the competition, which uses MicroPython as it’s primary programming language. However, I was going to be unavailable on the day of the actual race (although for the benefit of the press we had a dry run on the Thursday before as they have lie-ins on Saturdays). Enter nine-year-old Connie, a friend of TNMoC who was eager to be involved. Brilliant, I thought, she can run the micro:bit entry for the Saturday race. She willingly accepted.

I started to sketch out some code of the micro:bit. Not the greatest challenge in programming terms, but I did want to ensure it stopped at 15 seconds, or the nearest a micro controller can get to it. I was also being hamstrung by one of the race rules; every number generated must be displayed. Hmm. Where? Well, we have some options. Displaying on the front LED matrix would slow things down ridiculously. In fact, a test run got me to 55, 11th in the sequence. The other option was to output each term to the debug console, and display using a connected laptop. This rendered better results, getting to 645th in the sequence, a number 135 digits long.

So what happens if you don’t bother with all that display nonsense at all? A lot, as it turns out. Running a script that just displays the result at the end got to 6,053 in the sequence, a whopping 1,265 digits in length. Satisfied I could bend the rules, I locked this down as my entry.

I didn’t bank on Connie.

I’d encouraged Connie to have a go at writing her own version of the code, without seeing mine. We worked on it together and sure enough she started to understand how to time the script and run the loop. When I received her final code, I ran it on my micro:bit to test.

6,838 in the sequence, 1,429 digits long.

Why faster? Well, probably a bit of vanity on my part. To make the micro:bit look a bit flashy, I’d coded in a countdown made up of fifteen LEDs that went out one by one as the seconds past. Connie would be having nothing to do with such showing-off; speed was the goal. What surprised me the most was how much of a difference removing the LED updating code had on performance. Her code got 785 terms further than mine, all because I wanted some blinkenlights.

“No Connie, your code can’t possibly be that fast, there must be a mista… Oh.”

On Saturday, the little micro:bit trounced the competition and Connie won the first Great Digital Race. At this point you may be wondering about the iPhone, how could that not win? It was by far the most powerful computer in the race and should have swept the board. In the end, the iPhone 6s scored just fourth in the sequence. Fourth. That’s number eight.

The official reason given for the iPhone’s humiliation was the fact that getting the highest number wasn’t really the point. The numbers had been entered into the iPhone by voice, using Siri. With the best will in the world, you can’t get very far in fifteen seconds by voice. This was done to demonstrate how technology has moved on. After all you can talk softly to the WITCH as much as you like but she won’t do a thing until you offer up some delicious punched tape.

I’ve got a bit of a different take on the iPhone’s failure. The one thing every other computer had in common was that they were open to use. Anyone can write code for them, whether it’s the simple instruction set of the WITCH, BBC Basic, Excel macros or MicroPython. You can only write code for an iPhone if you pay (and continue to pay) the requisite amount of money to Apple for a developer licence. With that barrier, the only way to ‘input’ was by voice (or maybe by keyboard using the calculator). The iPhone failed because it refused to play.

It’s been fascinating to see how small differences can have major effects on code performance through such a simple exercise. Also, never get over-confident when there are nine-year old code ninjas about.

The final number?


Main image © The National Museum of Computing
All other images in this post are copyright of their respective owners and may not be used without permission

Keep Turing and Welchman’s Bombe at Bletchley Park. We need your help!

Published inTNMoC


  1. Paul R Paul R

    This piqued my interest and I couldn’t resist knocking something up on a PC. The 6838th number comes up in less than 1ms, and agrees with yours.

    Less than 10s to iterate to the millionth Fibonacci number, but as it has 209018 digits when rendered in decimal it takes a while to print it out. (10 million takes 980s, and is getting a bit silly).

    It would be really interesting to see the museum hold a pure race to solve some problem that is tractable on all devices and which could demonstrate the rate of progress in raw CPU performance. And to see how fast an iPhone actually is. First problem is to think of a suitable problem…

    • PJ PJ

      A friend wrote some code in Haskell, compiled it and got to over SEVENTY MILLION in 15 seconds!

      • Paul R Paul R

        Would like to see that!

        I think on my oldish CPU there is only 2.5MB of level 3 cache per core, so as soon as the numbers stop fitting and main memory comes into play it’s relatively catastrophic slow down.

        You can get to a given value using way fewer multiplies than the usually required additions, but then you don’t go through each value, which seems out of the spirit…Might try it anyway.

        • Paul R Paul R

          I found the Haskell code at

          I don’t think it’s fast because it’s Haskell, it’s the GMP provided arbitrary precision integers, which look to have some rather fancy code in them.

          Endless fun.

  2. Ed Ed

    There must be some hope of computing within the iphone’s browser… a quick check shows that will supply a python3 command line. OK, two layers of interpretation going on, but even so.

    • PJ PJ

      Yeah, you could write some javascript and run it in the browser but it wouldn’t compare to the phone’s raw power.

  3. Very cool, and well done, Connie! Are MicroPython ints arbitrary precision, like Python 3? If they’re not, then I *seriously* repsect her work.

    • PJ PJ

      Thankfully it does have arbitrary precision, unlike the Windows 98 box that took part and got very upset very quickly. 🙂

      • Whew, thank goodness. Are the rules available anywhere? You’ve mentioned that the whole sequence has to be printed (so I guess I should go to a text window instead of running a terminal program on X windows, to cut down on I/O overhead); I am curious about whether the rules insist on decimal output–that would mean a LOT more calculation unless you went with BCD.

        • PJ PJ

          It was a very informal event, and just a bit of fun. So no real rule sheet as such. However, it was expected that the numbers be displayed and yes, in decimal.

Leave a Reply

Your email address will not be published. Required fields are marked *