Lego Computer Science: Algorithms and computational agents

Child following lego instructions
Image by Thomas G. from Pixabay

The idea of an algorithm is core to computer science. So what is an algorithm? If you have ever used the instructions from some Lego set for building a Lego building, car or animal, then you have followed algorithms for fun yourself and you have been a computational agent.

An algorithm is just a special kind of set of instructions to be followed to achieve something. That something that is to be achieved could be anything (as long as someone is clever enough to come up with instructions to do it). It could be that the instructions tell you how to multiply two number, how to compute an answer to some calculation; how to best rank search results so the most useful are first; or how to make a machine learn from data so it can tell pictures of dogs from cats or recognise faces. The instructions could also be how to build a TIE fighter from a box of lego pieces, or how to build a duck out of 5 pieces of lego or, in fact, anything you might want to build from lego.

The first special thing about the instructions of an algorithm is that they guarantee the desired result is achieved (if they are followed exactly) … every time. If you follow the steps taught in school of how to multiply those numbers then you will get the answer right every time, whatever numbers you are asked to multiply. Similarly, if you follow the instructions that come with a lego box exactly and you will build exactly what is in the picture on the box. If you take it apart and build it again, it will come out the same the second time too.

For this to be possible and for instructions to be an algorithm, those instructions must be precise. There can be no doubt about what the next step is. In computer science, instructions are written in special languages like pseudocode or a programming language. Those languages are used because they are very precise (unlike English) with no doubt at all about what the instruction means to be done. Those nice people at Lego who write the booklets of instructions in each set, put a lot of effort into making sure their instructions are precise (and easy to follow). Algorithms do not have to be written in words. Lego use diagrams rather than words to be precise about each step. Their drawings are very clear so there is no room for doubt about what needs to be done next.

Computer scientists talk about “computational agents”. A computational agent is something that can follow an algorithm precisely. It does so without needing to understand or know what the instructions do. It just follows them blindly. Computers are the most obvious thing to act as a computational agent. It is what they are designed to do. In fact, it is all they can do. THey do not know what they are doing (they are just metal and silicon). They are machines that precisely follow instructions. But a human can act as a computational agent too, if they also follow instructions. If you build a lego set following the instructions exactly making no mistake then you are acting as a computational agent. If you miss a step or do steps in the wrong order of place a piece in the wrong place or (heaven forbid) do something creative and change the design as you go, then you are no longer being a computational agent. You are no longer following an algorithm. If you do act as a computational agent you will build whatever is on the box exactly, however big it is and even if you have no idea what you are building.

Acting as a computational agent can be a way to destress, a form of mindfulness where you switch off your mind. They can also be good to build up useful skills that matter as a programmer: like attention to detail, or if following a program helping you understand the semantics of programming languages so learn to program better. It is also a good debugging technique, and part of code audits where you step through a program to check it does do as intended (or find out where and why is doesn’t).

Algorithms are the core of everything computers do. They can do useful work or they can be just fun to follow. I know which kind I like playing with best.

– Paul Curzon, Queen Mary University of London


Lego Computer Science

Image shows a Lego minifigure character wearing an overall and hard hat looking at a circuit board, representing Lego Computing
Image by Michael Schwarzenberger from Pixabay

Part of a series featuring featuring pixel puzzles,
compression algorithms, number representation,
gray code, binary and computation.

More on …


Subscribe to be notified whenever we publish a new post to the CS4FN blog.


This page is funded by EPSRC on research agreement EP/W033615/1.

QMUL CS4FN EPSRC logos

The Lego Computer Science series was originally funded by UKRI, through grant EP/K040251/2 held by Professor Ursula Martin, and formed part of a broader project on the development and impact of computing.

Mary and Eliza Edwards: the mother and daughter human computers

The globe with lines of longitude marked
Lines of Longitude. Image from wikimedia, Public Domain.

Mary Edwards was a computer, a human computer. Even more surprisingly for the time (the 1700s), she was a female computer (and so was her daughter Eliza).

In the early 1700s navigation at sea was a big problem. In particular, if you were lost in the middle of the Atlantic Ocean, there was no good way to determine your longitude, your position east to west. There was of course no satnavs at the time not least because there would be no satellites for 300 years! 

It could be done based on taking sightings of the position of the sun, moon or planets, at different times of the day, but only if you had an accurate time. Unfortunately, there was no good way to know the precise time when at sea. Then in the mid 1700s, an accurate clock that could survive a rough sea voyage and still be highly accurate was invented by clockmaker John Harrison. Now the problem moved to helping mariners know where the moon and planets were supposed to be at any given time so they could use the method.

As a result, the Board of Longitude (set up by the UK government to solve the problem) with the Royal Greenwich Observatory started to publish the Nautical Almanac from 1767. It consisted lots of information of such astronomical data for use by navigators at sea. For example, it contained tables of the position of the moon (or specifically its angle in the sky relative to the sun and planets (known as lunar distances). But how were these angles known years in advance to create the annual almanacs? Well, basic Newtonian physics allow the positions of planets and the moon to be calculated based on how everything in the solar system moves together with their positions at a known time. From that their position in the sky at any time can be calculated. That answers would be in the Nautical Almanac. Each year a new table was needed, so the answers also needed to be constantly recomputed.

But who did the complex calculations? No calculators, computers or other machines that could do it automatically would exist for several hundred years. It had to be done by human mathematicians. Computers then were just people, following algorithms, precisely and accurately, to get jobs like this done. Astronomer Royal, Nevil Maskelyne recruited 35 male mathematicians to do the job. One was the Revd John Edwards (well-educated clergy were of course perfectly capable of doing maths in their spare time!). He was paid for calculations done at home from 1773 until he died in 1884.

However, when he died Maskelyne received a letter from his wife Mary, revealing officially that in fact she had been doing a lot of the calculations herself, and with no family income any more she asked if she could continue to do the work to support herself and her daughters. Given the work had been of high enough quality that John Edwards had been kept on year after year so Mary was clearly an asset to the project, (and given he had visited the family several times so knew them, and was possibly even unofficially aware who was actually doing the work towards the end) Maskelyne was open-minded enough to give her a full time job. She worked as a human computer until her death 30 years later. Women doing such work was not at all normal at the time and this became apparent when Maskelyne himself died and the work stated to dry up. The quality of the work she did do, though, eventually persuaded the new Astronomer Royal  to continue to give her work.

Just as she helped her husband, her daughter Eliza helped her do the calculations, becoming proficient enough herself that when Mary died, Eliza took over the job, continuing the family business for another 17 years. Unfortunately, however, in 1832, the work was moved to a new body called ‘His Majesty’s Nautical Almanac Office’ At that point, despite Mary and Eliza having proved they were at least as good as the men for half a century or more, government imposed civil service rules came into force that meant women could no longer be employed to do the work.

Mary and Eliza, however had done lots of good, helping mariners safely navigate the oceans for very many years through their work as computers.

More on …

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


This page is funded by EPSRC on research agreement EP/W033615/1.

QMUL CS4FN EPSRC logos