Website title

Computing: The Details
Lex's blog of curious computer-related shenanigans.

Blog post

A floppy disk is technially a letter

Published: 2022-09-08

This blog post is also available in video form! Watch it on YouTube

A Royal mail red postbox, and a green 3.5 inch floppy disk with a red first-class postage stamp on it. There is an arrow pointing from the floppy disk to the hole in the post box.

If you live in the UK then you'll almost certainly know about Royal Mail. They probably deliver most of your mail, and you probably recognise their distinctive red-cylinder post boxes.

These are Royal mail stamps.

Nine first-class Royal mail stamps in a stamp book. They are red, with a profile of Queen Elizabeth the second in white.

As you can see they've really gone for the whole Royal theme. This is of course an instagram photo of the queen taken with a "make me look younger" filter. It has done a splendid job.

Each one of these proves that I have paid for postage of one letter. Or at least they do until they start enforcing use of the new barcode stamps. I guess these ones are just too easy to counterfeit.

Now, this stamp book is about two years old and I've used three of them. I have only a few months to use up the last nine of these. If I continue to use stamps at my current rate, then by the time they become invalid I'll still have approximately ... nine stamps. I'm gonna have to drastically increase the rate at which I use stamps, but I never send letters, so what can I do?

Well, I noticed something about what these stamps are valid for. According to Royal Mail, a Letter is anything that fits inside a volume of 240x165x5mm, and up to a weight of 100g.

A screenshot of the royal mail site section that explains the letter restrictions as above

So, I checked a standard 3.5 inch floppy disk, and it does indeed fit quite comfortably in to that specification. This sounds like a much more fun way to use my old stamps.

Actually, you can comfortably fit two floppy disks in the size of one letter. If you tape two together, you can send them both at once! A rendering of two blue floppy disks inside a transparent visualisation of the maximum letter size. There is lots of spare space around the disks

I decided to send a friend of mine a floppy disk with something silly on it.

It's a Microsoft Word 97 dot-doc file containing a stream of hex codes, which when interpreted as ASCII text will give you a base64 encoding of a gzip file, which when unzipped will give you a PNG file, which when rendered presents a QR code that encodes a link to ... Rick Astley's "Never Gonna Give you up".

It's a high-effort rick roll.

I have a particular friend who has a fondness for older versions of Microsoft Word. I decided to send her this floppy disk to see if she would figure out that it was me that sent it.

And the answer is... Yes! She knew it was me. She received the floppy disk, as sent, and she quickly predicted that it contained a Rick roll.

Blog post

I found a ZX Spectrum demo in a box of old tapes

Published: 2022-07-02

This blog post is also available in video form! Watch it on YouTube

screenshot of the first screen of RACHEL's SKILL PROGRAM. the words are printed in a very large font, in red, cyan, and green

Many years ago I bought a job lot of compact casette tapes on ebay. They all contained ZX spectrum software. The lot that I bought also came with a bunch of other things too, and it was those things that I was more interested in.

Since the tapes were mostly cheap games, I only tried playing with the interesting looking ones, and after a short while I put them all in a box and forgot about them.

Recently I opened up this box again and I found something rather interesting on one of the tapes.

What is a Demo?

Before I get into what I found, for the benefit of those not familiar with the Demoscene, allow me to explain what a demo is.

A demo is a piece of software that generates an animation or visual effect in real-time. Often accompanied by music or sound effects. A demo is not simply a video file.

There's a whole digital art subculture around these things, it's called the Demoscene. Here's a link to a better explanation than I can provide.

I'm not sure if Rachel knew they were writing a demo, but they were.

The Demo

In my box of old tapes there was a completely uninteresting looking tape which was clearly bought as a blank C15 tape and had no markings on the outer packaging. I think I probably dismissed this the first time around because it looked like a blank tape.

Upon closer inspection I saw there was one thing on the index card, but it had since been thoroughly erased, but there was also a name written in pencil on the casette.

"Rachel".

Of course, I took the obvious next step and tried loading it up to see what was on there. After about one minute of loading, the sound stopped and it appeared that the spectrum had successfully loaded something.

Running the "LIST" command shows a BASIC listing that had just been loaded from the tape. Looks exciting, let's run it and see what it does!

I will walk through the demo here as a sequence of images, but if you want the full experience then you'll want to see my recording. The raw recording is avialable to watch on YouTube

screenshot 2 screenshot 3

Screenshots 2 and 3 show the first part of the program, first the words "THIS IS A PROGRAM ON MUSIC" are shown on the screen, then a musical scale is played slowly, with a new coloured circle appearing on the screen after each note. Each circle is smaller than the previous, they are all centred on the screen. The circle and note section repeats, playing twice in total.

screenshot 4 screenshot 5 screenshot 6

Screenshots 4, 5, and 6 show the next musical section. First "AND NOW" flashes in large text on the screen, then it is replaced with much smaller text: "CLOSE ENCOUNTERS OF THE THIRD KIND". Finally, a drawing of green alien appears on the screen, while the note sequence from close encounters of the third kind plays. Once again, this section plays twice.

screenshot 7 screenshot 8 screenshot 9

The final musical section is shown in screenshots 7, 8, and 9. Introduced with a repeating rainbow pattern that says "NEXT: CHARIOTS OF FIRE". The animation for this one is random coloured lines being drawn across the screen in random places. The tune from chariots of fire plays.

screenshot 10

Finally, in screenshot 10, we see that the demo has ended. the words "THE END" are printed in large letters, in blue and red. Below is the text "THIS PROGRAM WAS WRITTEN BY THE 'ONE & ONLY' RACHEL BRADLEY !".

Wow! That was really cool. I wonder who Rachel Bradley is. I bet Rachel was a kid in the 80s and had a ZX spectrum in their bedroom. This looks like the result of a kid just having some fun writing some code.

But that's not all, here's a quiz!

It's not the only program of theirs on this tape either. On the other side of the tape is another program, also by Rachel. This time it's an interactive quiz program.

There's not many questions, and at the end it just stops, no score totalling or summary of your answers. The questions are the same every time. It's a very simple program, but with impressive attention to detail. I quite like the layout of the question screen.

I would tell you more about it, but apparently I neglected to capture that side of the tape, and I don't have a convenient way to digitise it right now.

Just those two programs on this tape, and it's the only one in the box that has what appears to be home-made programs.

Thanks Rachel!

I have no idea who Rachel Bradley is, but if you're out there somewhere reading this, then thank you for your demo! I really enjoyed it. It was truly a treasure among this stack of old tapes.

It's possible that I was the first person to have watched that demo for around 35 to 40 years. Who knows?

If you want to take a closer look at the demo, you can download this tap file that I captured from the orignal tape.

Blog post

Playing AmongUs with a sat solver

Published: 2020-11-29

This blog post is also available in video form! Watch it on YouTube

Looking for the code? Get the code on GitHub

A satisfyability solver (sat solver) is a tool that finds solutions to a boolean formula. These are normally used for checking mathematical proofs, or for verification of computer programs. I've used them for this purpose, but sometimes it's fun to do unusual things with them. I used one to help me play the popular online video game of social deduction: Among Us.

It's actually quite hard to be good at doing perfect deductions while playing Among Us. There's lots to remember and although the logic you need for deducing the hidden information is simple, it's hard to apply it properly in your mind within the time.

Given how hard this game is, I thought it might be fun to create a tool that helps you play by remembering all the things you've learned so far, and making the deductions for you.

So I wrote a program for doing exactly this. It knows all the constraints that exist on the game state, and it knows the facts you tell it, and then it recommends people to eject after meetings. Assuming you give it only things you know for sure then it will perfectly deduce who the impostors are.

The constraints that it knows at the start are really simple things like: people who were killed cannot be impostors, there's always more crewmates than impostors after an ejection that doesn't end the game, and some other simple things like that.

You can tell it that someone is a crewmate, maybe you saw them do a visual task, you know they're a crewmate. If you see someone murder or vent, then that's an easy one, you know they're an impostor. You also tell it who has been murdered, and who was ejected, of course. But the most useful thing is to tell it when a group of people is known to contain an impostor.

So if you never let green or red out of your sight for the whole round, but somebody was killed, then you know there's at least one impostor amongst all the players that are not you, green, or red.

The UI

The UI for this thing is a webpage. You run the server locally on your PC, and open up your browser to use the solver. It's a really simple UI. At first you simply select which players are present, and how many impostors there are.

A user selects players from a list of colours. They select red, blue, pink, orange, black, and purple. They start a game with two impostors.

Once a game is created, you can input information by clicking the buttons on each player, or by adding them to the selection with the tick/cross icon, and then marking the selected groups as including an impostor.

Each time more information is learned, the sat solver finds all the possible models (assignments of the variables in the boolean expression) that match all of the given knowledge. The UI shows the number of models in which each player is an impostor. The idea is that if you are in more models, then you're more likely to be an impostor. It also recommends an action to take at the meeting.

A user interacts with the UI to inform the solver that the red player is a crewmate, the blue player was murdered, there is at least one impostor among black and purple, there is at least one impostor amont pink and black, black was ejected, purple is a crewmate. As they do this, the number of models shown for each player decreases from the initial 5 models each. Below the controls for information input are two lists. One of players to suspect, and one for innocent players.

Behind the scenes

It's a piece of python code, which serves the UI over http. It uses Z3, which is a sat-solver, to calculate all the possible explanations for the facts you provide. That means I didn't tell it any of the logic for actually making deductions, I just told it the constraints and facts, and the logic doesn't matter because of the way a sat-solver finds solutions to equations. It also means it's really easy to add extra information, if ever an update to the game adds ways to learn things, or adds new game state.

Z3 has some really nice python bindings that allow you to have a python object that refers to a Z3 variable. Perhaps you're interested to see some code? I won't do an in-depth analysis here, but the code is on GitHub and has a lot of documentation comments. If you want a deep understanding of it, have a read of the code.

The first thing that it does when a game starts is set up some basic facts about the game...


class GameSolver:
    def __init__(self, n_players, n_impostors):
        """ Construct a GameSolver with a known number of players and number of impostors """
        self.n_players = n_players
        # Some variables that model the state of each player
        self.alive, self.murdered, self.impostor, self.ejected = ( 
            [z3.Bool('%s-%d' % (varname, player_id)) for player_id in range(self.n_players)]
            for varname in [
                'player-is-alive'
                ,'player-was-murdered'
                ,'player-is-impostor'
                ,'player-was-ejected'
            ]
        )

        # First bit of information known is the number of impostors
        self.n_impostors = z3.IntVal(n_impostors)
        self.n_alive_impostors = z3.Int('alive_impostors')
        self.knowns = [] # for known facts that will never change until the game ends

        # State for building facts about players during the game, when what is known
        # might change (I know blue is not murderd and green is not ejected, but then
        # green murders blue, we figure it out and eject green, now blue's murdered
        # state changed and green's ejected state changed)
        self.murdered_pids = []
        self.ejected_pids = []

The simple constraints are ones such as "player X is a crewmate". These become basic assertions in Z3, which are tracked in the knowns variable on a GameSolver instance.

    def learn_certain_not_impostor(self, colour):
        """ learn that the player with the specified colour is certainly not an impostor """
        p = self.pid(colour)
        self.knowns.append(
            z3.Not(self.impostor[p])
        )

I find the code for specifying the basic constraints of the game to be quite nicely readable, thanks to the Z3 python bindings...

    def basic_constraints(self):
        """ Returns a list of constraints representing basic facts about the possible game states """
        return [
            # Number of impostors is number of impostors
            self.n_impostors == sumbools(self.impostor)
            # A number of impostors can be alive
            ,self.n_alive_impostors == sumbools(
                z3.And(self.alive[i], self.impostor[i])
                for i in range(self.n_players)
            )
            # People that were murdered cannot be impostors
            ,*[
                z3.Implies(self.murdered[i], z3.Not(self.impostor[i]))
                for i in range(self.n_players)
            ]
            # Alive people have not been murdered and have not been ejected
            ,*[
                z3.And(z3.Not(self.murdered[i]), z3.Not(self.ejected[i])) == self.alive[i]
                for i in range(self.n_players)
            ]
            # There is at least one not-dead impostor
            ,self.n_alive_impostors > z3.IntVal(0)
            # Twice the number of alive impostors is less than the number of alive crewmates
            ,sumbools(self.alive) > (self.n_alive_impostors * z3.IntVal(2))
        ]

Normally Z3 will only find one solution to your system of equations. To make Z3 provide all of the possible models, you have to iteratively remove each model that it finds, until it cannot find any more. I do this by adding a constraint that at least one player that is an impostor in this model must not be an impostor. This makes that particular model no longer valid, and I can search for a new one.

    def not_this_model(self, model):
        """ Returns a constraint that prevents the given model from being valid """
        return z3.Or(
            *[self.impostor[pid] != model[self.impostor[pid]]
            for pid in range(self.n_players)]
        )

Of course, this constraint must then be removed before reevaluating the solutions.

There is a lot more supporting code, and I've not included all of the Z3 logic here, so if you are interested, certainly do have a look at the code on GitHub.

Can I use this to cheat?

No, not really, it's not actually that helpful during the game. I did try and found that it was actually harder than normal play. Making this tool was mostly just an academic exercise.