Python iter()

A seemingly little-known use for the Python iter() built-in: it can be used to tidy up code that would otherwise need a separate statement for assignment.

with open('text') as f:
    for b in iter(lambda:, ''):

instead of:

with open('text') as f:
    while True:
        b =
        if b == '': break

A small extension to this idea can be constructed to allow for arbitrary exit conditions, as opposed to just equality to a single value:

def until(f, sentinel):
    while True:
        v = f()
        if sentinel(v): break
        yield v

with open('text') as f:
    for b in until(lambda:, lambda c: c in ('', '\n')):

A switch to Ghost

As may be evident, this blog is undergoing some more change. In particular, I have switched to another CMS yet again, this time Ghost. So I have had to redo the theme, and now fix up my content. More to come on the transition once that is done...


Orbiting Earth is just moving sideways so fast that you move away from Earth as fast as you fall back towards it. Just getting up there is easy, but it isn’t enough — you’d just fall straight back down. It’s the sideways speed which is so hard to reach.

You could do this in our atmosphere as well, if the atmosphere wasn’t slowing you down so much.

A card problem

I was recently party to a very simple, but nonetheless interesting card game. In the game, four players begin the game holding one suit of cards each from a single deck. Then, for thirteen rounds (until the players have run out of cards) every player discards one of their cards simultaneously into the centre, with the player who discards the highest-value card winning the round. If two or more players discard cards of the same face value, then the round is a draw. The winner of the most rounds at the end then wins the game.

While this game is pretty simple and at first glance largely up to luck, it did make me wonder whether there were any strategies that could increase a player’s chance of winning. It would seem so, especially since the starting hands are constant. Therefore, it would be interesting to find both the optimal strategy assuming everyone else plays randomly (i.e. equal probability to play any remaining card), as well as the optimal strategy assuming everyone else plays optimally.

Functional Python

Ever tried to learn Haskell? Confused? Know Python? How about trying to write some functional code in Python? And no, I don’t even mean just using functional principles in Python as the docs describe, I mean actually writing Python like you write Haskell.

Read more…

The book of Synook

“Why are you burying that notebook in the ground?”

“I want to start a religion.”

Comic Neue

Random sampling job applicants

Recently, one of my friends told me of her job application, which had been rejected before even the second stage of the recruitment process, which was an entirely automated cognitive aptitude test. I joked that maybe the company randomly sampled their applicants, due to high demand for employment. This made me wonder, however, whether such a procedure was in fact reasonable. After all, processing candidates is expensive and time-consuming, right?

Consider a job application process: there are a certain number of applicants n, of which only some proportion p are “suitable” for the position (in this case, we will consider all suitable candidates equally so). Fortunately, the company only has some t < np* positions open, and thus does not need to find all the suitable candidates. Say they wanted to have a 90% chance of finding at least t suitable candidates — how much of the applicant population would they need to sample?

Of the answer, I’m not sure… perhaps someone can enlighten me. An interesting question though, no?


Let the ephemeral sunlight shine through the gathering clouds onto the waves crashing upon the shores of our hearts; and in the last moments of our day shall we be called to travel beyond the endless seas to the place where time is no more, a place forever waiting for those who remain to join us who have gone, in the eternal sunlight of the perfect day.