Generating random numbers
Have you ever wondered how deterministic machines like computers are able to make random choices? A computer program has to tell a computer exactly what to do at every stage; the computer cannot make...
View ArticleAn introduction to Turing machines
The story of how Alan Turing made important contributions to the allied war effort in World War II as part of a team cracking German codes, only to later end up being prosecuted for homosexual activity...
View ArticleReversing a linked list in place
The other day I finally realized how you reverse a linked list in place. I had attempted to tackle this problem several times before, and had always ended up looking up the answer online, copying and...
View ArticleThe difference between key-value containers and functions
I was wondering why all of the programming languages I know treat key-value containers (i.e. sequences and associative arrays) differently from functions. From mathematics, I’m used to thinking of...
View ArticleTricks in computer arithmetic
(This post is also available as a PDF, with better typesetting for the mathematical formulas and syntax highlighting for the code listings.) People who do a lot of mental arithmetic often make use of...
View ArticleProgramming languages as theorem verifiers
(This post is also available as a PDF). One of the most interesting ideas in modern logic is the Curry-Howard correspondence. This is the informal observation that, from a certain perspective,...
View ArticleDualities between depth-first search and breadth-first search
Something which I think is fairly well-known among programmers (I first learned it from reading Higher Order Perl) is that depth-first search and breadth-first search can be implemented in such a way...
View ArticleEnumerating the ordered k-partitions of an integer
Given two integers and , where is non-negative, an ordered -partition of is a -tuple of positive integers such that For example, the ordered 3-partitions of 5 are , , , , , and . The problem I'm...
View ArticleImplementing Python’s `cmp_to_key` function
Sorting functions in programming languages often take a parameter which allows the user to control how comparison is done when sorting. The most direct way to do this is to have the parameter be a...
View ArticleThe trajectory of a bouncing ball
You can also view this article at my Github Pages website (the formatting might be better there). Consider an idealized model of a ball bouncing on the ground, where the ball is falling along a line...
View Article