Here’s a thought: what’s the minimum number of votes your party would need to attract in order to be able to secure a majority of seats in the House of Commons and form a government? Let’s try to work it out.

The 2017 general election reportedly enjoyed a 68.8% turnout. If we assume for simplicity’s sake that each constituency had the same turnout and that votes for candidates other than yours are equally-divided amongst your opposition, that means that the number of votes you need to attract in a given constituency is:

68.8% × the size of its electorate ÷ the number of candidates (rounded up)

For example, if there was a constituency of 1,000 people, 688 (68.8%) would have voted. If there were 3 candidates in that constituency you’d need 688 ÷ 3 = 229⅓, which rounds up to 230 (because you need the plurality of the ballots) to vote for your candidate in order to secure the seat. If there are only 2, you need 345 of them.

The minimum number of votes you’d need would therefore be this number for each of the smallest 326 constituencies (326 is the fewest number of seats you can hold in the 650-seat House of Commons and guarantee a strict majority; in reality, a minority government can sometimes form a government but let’s not get into that right now). Constituencies vary significantly in size, from only 21,769 registered voters in Na h-Eileanan an Iar (the Western Isles of Scotland, an SNP/Labour marginal) to 110,697 in the Isle of Wight (which flip-flops between the Conservatives and the Liberals), but each is awarded exactly one seat, so if we’re talking about the minimum number of votes you need we can take the smallest 326.

By my calculation, with a voter turnout of 68.8% and assuming two parties field candidates, one can win a general election with only 7,375,016 votes; that’s 15.76% of the electorate (or 11.23% of the total population). That’s right: you could win a general election with the support of a little over 1 in 10 of the population, so long as it’s the right 1 in 10.

I’ll leave you to decide how you feel about that. In the meantime, here’s my working (and you can tweak the turnout and number-of-parties fields to see how that affects things). My data comes from the following Wikipedia/Wikidata sources: [1], [2], [3], [4], [5] mostly because the Office of National Statistics’ search engine is terrible.

You are at a party and overhear a conversation between Lucy and her friend.

In the conversation, Lucy mentions she has a secret number that is less than 100.

She also confesses the following information:

“The number is uniquely describable by the answers to the following four questions:”

Q1) Is the number divisible by two?
Q2) Is the number divisible by three?
Q3) Is the number divisible by five?
Q4) Is the number divisible by seven?

…

I loved this puzzle. I first solved it a brute-force way, with Excel. Then I found increasingly elegant and logical solutions. Then I shared it with some friends: I love it! Go read the whole thing.

Imagine I’m in a desert, and there are two wells where I can obtain water. If I want to go to the nearest well, which well do I visit? Clearly, it depends one where I am standing. It’s possible to draw a line dividing the desert. To the ‘left’ of the line, it’s nearer to go to the well on the well on the ‘left’, to the ‘right’ of the line, it’s closer to go to the well on the ‘right’…

So, I’ve not been well lately. And because a few days lying on my back with insufficient mental stimulation is a quick route to insanity for me, I’ve been trying to spend my most-conscious moment doing things that keep my brain ticking over. And that’s how I ended up calculating pi.

Pi (or π) is, of course, the ratio of the circumference of a circle to its diameter, for every circle. You’ll probably have learned it in school as 3.14, 3.142, or 3.14159, unless you were one of those creepy kids who tried to memorise a lot more digits. Over the years, we’ve been able to calculate it to increasing precision, and although there’s no practical or theoretical reason that we need to know it beyond the 32 digits worked out by Ludolph van Ceulen in the 16th Century, it’s still a fascinating topic that attracts research and debate.

Most of the computer-based systems we use today are hard to explain, but there’s a really fun computer-based experimental method that can be used to estimate the value of pi that I’m going to share with you. As I’ve been stuck in bed (and often asleep) for the last few days, I’ve not been able to do much productive work, but I have found myself able to implement an example of how to calculate pi. Recovery like a nerd, am I right?

Remember in school, when you’ll have learned that the formula to describe a circle (of radius 1) on a cartesian coordinate system is x^{2} + y^{2} = 1? Well you can work this backwards, too: if you have a point on a grid, (x,y), then you can tell whether it’s inside or outside that circle. If x^{2} + y^{2} < 1, it’s inside, and if x^{2} + y^{2} > 1, it’s outside. Meanwhile, the difference between the area of a circle and the area of a square that exactly contains it is π/4.

Take those two facts together and you can develop an experimental way to determine pi, called a Monte Carlo method. Take a circle of radius 1 inside a square that exactly contains it. Then randomly choose points within the square. Statistically speaking, these random points have a π/4 chance of occuring within the circle (rather than outside it). So if we take the number of points that lie within the circle, divide that by the total number of points, and then multiply by 4, we should get something that approaches the value of pi. You could even do it by hand!

The software illustration I’ve written is raw Javascript, HTML, and SVG, and should work in any modern web browser (though it can get a little slow once it’s drawn a few thousand points!). Give it a go, here! When you go to that page, your browser will start drawing dots at random points, colouring them red if the sum of the squares of their coordinates is less than 1, which is the radius of the circle (and the width of the square that encompasses it). As it goes along, it uses the formula I described above to approximate the value of pi. You’ll probably get as far as 3.14 before you get bored, but there’s no reason that this method couldn’t be used to go as far as you like: it’s not the best tool for the job, but it’s super-easy to understand and explain.

Oh, and it’s all completely open-source, so you’re welcome to take it and do with it what you wish. Turn off the graphical output to make it run faster, and see if you can get an accurate approximation to 5 digits of pi! Or slow it down so you can see how the appearance of each and every point affects the calculation. Or adapt it into a teaching tool and show your maths students one way that pi can be derived experimentally. It’s all yours: have fun.

And I’ll update you on my health at some other point.

When I learned to program, back when dinosaurs walked the earth and the internet had no cats, there was an idea: if you were good at math, you’d be good at programming. I was great at math as a kid, but perhaps because I didn’t like it much, no one steered me towards programming. I…

Have you ever come across non-transitive dice? The classic set, that you can get in most magic shops, consists of three different-coloured six-sided dice:

There are several variants, but a common one, as discussed by James Grime, involves one die with five “3” sides and one “6” side (described as red below), a second die with three “2” sides and three “5” sides (described as green below), and a third die with one “1” side and five “four” sides (described as blue below).

They’re all fair dice, and – like a normal six-sided dice – they all have an average score of 3.5. But they’ve got an interesting property, which you can use for all kinds of magic tricks and gambling games. Typically: the red die will beat the green die, the green die will beat the blue die, and the blue die will beat the red die! (think Rock, Paper, Scissors…)

If you want to beat your opponent, have them pick a die first. If they pick green, you take red. If they take red, you take blue. If they take blue, you take green. You now have about a 60% chance of getting the highest roll (normally you’d have about a 33% chance of winning, and a 17% chance of a draw, so a 60% chance is significantly better). To make sure that you’ve got the best odds, play “best of 10” or similar: the more times you play, the less-likely you are to be caught out by an unfortunate unlucky streak.

But if that doesn’t bake your noodle enough, try grabbing two sets of nontransitive dice and try again. Now you’ll see that the pattern reverses: the green pair tends to beat the red pair, the red pair tends to beat the blue pair, and the blue pair tends to beat the green pair! (this makes for a great second act to your efforts to fleece somebody of their money in a gambling game: once they’ve worked out how you keep winning, give them the chance to go “double or nothing”, using two dice, and you’ll even offer to choose first!)

The properties of these dice – and of the more-exotic forms, like Oskar van Deventer’s seven-dice set (suitable for playing a game with three players and beating both of your opponents) and like the polyhedral varieties discussed on Wikipedia – intrigue the game theorist and board games designer in me. Could there be the potential for this mechanic to exist in a board game? I’m thinking something with Risk-like combat (dice ‘knock out’ one another from highest to lowest) but with a “dice acquisition” mechanic (so players perform actions, perhaps in an auction format, to acquire dice of particular colours – each with their own strengths and weaknesses among other dice – to support their “hand” of dice). There’s a discussion going on in /r/tabletopgamedesign…

I’ve even written a program (which you’re welcome to download, adapt, and use) to calulate the odds of any combination of any variety of non-transitive dice against one another, or even to help you develop your own non-transitive dice sets.

Penney’s game

Here’s another non-transitive game for you, but this time: I’ve made it into a real, playable game that you can try out right now. In this game, you and I will each, in turn, predict three consecutive flips of a fair coin – so you might predict “tails, heads, heads”. Then we’ll start flipping a coin, again and again, until one of our sequences comes up. And more often than not, I’ll win.

[button link=”https://danq.me/penney/” align=”center” size=”large” caption=”Click here to play a non-transitive coin game.”]Play “Penney’s Game”[/button]

If you win 10 times (or you lose 20 times, which is more likely!), then I’ll explain how the game works, so you know how I “cheated”. I’ll remind you: the coin flips are fair, and it’s nothing to do with a computer – if we played this game face-to-face, with a real coin, I’d still win. Now go play!

The other Three Ringers and I are working hard to wrap up Milestone: Jethrik, the latest version of the software. I was optimising some of the older volunteer availability-management code when, by coincidence, I noticed this new bug:

I suppose it’s true: Lucy (who’s an imaginary piece of test data) will celebrate her birthday in 13/1 days. Or 13.0 days, if you prefer. But most humans seem to be happier with their periods of time not expressed as top-heavy fractions, for some reason, so I suppose we’d better fix that one.

They’re busy days for Three Rings, right now, as we’re also making arrangements for our 10th Birthday Conference, next month. Between my Three Rings work, a busy stretch at my day job, voluntary work at Oxford Friend, yet-more-executor-stuff, and three different courses, I don’t have much time for anything else!

But I’m still alive, and I’m sure I’ll have more to say about all of the things I’ve been getting up to sometime. Maybe at half term. Or Christmas!

You own a time machine with an unusual property: it can only travel to 29^{th} February. It can jump to any 29th February, anywhere at all, in any year (even back before we invented the Gregorian Calendar, and far into the future after we’ve stopped using it), but it can only finish its journey on a 29^{th} of February, in a Gregorian leap year (for this reason, it can only jump to years which are leap years).

One day, you decide to take it for a spin. So you get into your time machine and press the “random” button. Moments later, you have arrived: it is now 29^{th} February in a random year!

Without knowing what year it is: what is the probability that it is a Monday? (hint: the answer is not^{1}/_{7} – half of your challenge is to work out why!).

You own a time machine with an unusual property: it can only travel to 29^{th} February. It can jump to any 29th February, anywhere at all, in any year (even back before we invented the Gregorian Calendar, and far into the future after we’ve stopped using it), but it can only finish its journey on a 29^{th} of February, in a Gregorian leap year (for this reason, it can only jump to years which are leap years).

One day, you decide to take it for a spin. So you get into your time machine and press the “random” button. Moments later, you have arrived: it is now 29^{th} February in a random year!

Without knowing what year it is: what is the probability that it is a Monday? (hint: the answer is not^{1}/_{7} – half of your challenge is to work out why!).

After our attempt at a relaxing day off, which resulted in us getting pretty-much soaked and exhausted, we returned on day five of our holiday to the comedy scene for more fun and laughter.

After failing to get into Richard Wiseman‘s Psychobabble, which attracted a huge queue long before we got to the venue, Ruth, JTA and I instead went to RomComCon: a two-woman show telling the story of how they road-tested all of the top romantic comedy “boy meets girl” cliché situations, to see if they actually worked in real life. It was sweet, even where it wasn’t funny, and it was confidently-performed, even where it wasn’t perfectly-scripted. The mixture of media (slides, video, audience participation, and good old-fashioned storytelling) was refreshing enough to help me overlook the sometimes-stilted jumps in dialogue. I’ll admit: I cried a little, but then I sometimes do that during actual RomComs, too. Although I did have to say “Well d’uh!” when the conclusion of the presentation was that to get into a great relationship, you have to be open and honest and willing to experiment and not to give up hope that you’ll find one. You know: the kinds of things I’ve been saying for years.

We met up with Matt and his new girlfriend, Hannah-Mae, who turns out to be a lovely, friendly, and dryly-sarcastic young woman who makes a wonderful match for our Matt. Then, after a drink together, parted ways to see different shows; promising to meet up again later in the day.

We watched Owen Niblock‘s Codemaker, and were pleased to discover that it was everything that Computer Programmer Extraordinaire (which we saw on day two) failed to be. Codemaker was genuinely geeky (Owen would put up code segments and then explain why they were interesting), funny (everything from the five-months-a-year beard story to his relationship Service Level Agreement with his wife was fabulously-crafted), and moving. In some ways I’m sad that he isn’t attracting a larger audience – we three represented about a quarter to a fifth of those in attendance, at the end – but on the other hand, his computer-centric humour (full of graphs and pictures of old computers) is rather niche and perhaps wouldn’t appeal to the mainstream. Highly recommended to the geeks among you, though!

Back at the flat, we drank gin and played Ca$h ‘n’ Gun$ with Matt and Hannah-Mae. JTA won three consecutive games, the jammy sod, despite the efforts of the rest of us (Matt or I with a hand grenade, Ruth or I as The Kid, or even Hannah-Mae once she had a gun in each hand), and all the way along every single time insisted that he was losing. Sneaky bugger.

We all reconvened at the afternoon repeat of Richard Wiseman’s show, where he demonstrated (in a very fun and engaging way) a series of psychological, mathematical, and slight-of-hand tricks behind the “mind-reading” and illusion effects used by various professional entertainers. I’ve clearly studied this stuff far too much, because I didn’t end up learning anything new, but I did enjoy his patter and the way he makes his material interesting, and it’s well-worth a look. Later, Ruth and I would try to develop a mathematical formula for the smallest possible sum totals possible for integer magic squares of a given order (Wiseman’s final trick involved the high-speed construction of a perfect magic square to a sum total provided by a member of the audience: a simple problem: if anybody wants me to demonstrate how it’s done, it’s quite fun).

Finally, we all went to see Thom Tuck again. Matt, JTA and I had seen him earlier in the week, but we’d insisted that Hannah-Mae and Ruth get the chance to see his fantastic show, too (as well as giving ourselves an excuse to see it again ourselves, of course). He wasn’t quite so impressive the second time around, but it was great to see that his knowledge of straight-to-DVD Disney movies really is just-about as encyclopaedic as he claims, when we gave us new material we hadn’t heard on his previous show (and omitted some that we had), as well as adapting to suggestions of films shouted out by the audience. Straight-To-DVD remains for me a chilling and hilarious show and perhaps the most-enjoyable thing I’ve ever seen on the Fringe.