Metapost: Tuply singleton – Freedom of creativity

I like puzzles. If it’s a non-trivial one, in order to come up with a solution I usually spend a few days (on and off) thinking about it. But it also has to be interesting to get my attention.

As an example, consider one of my earlier blog posts series: Tuply singleton, Tuply singleton v2, Tuply singleton v3. This is what I do in general, and blog posts are usually just the result of my thinking. Blogging (or pen & paper) is one of the best tools we have as humans – given the reliability of our memory.

But then another thought came. What if someone had asked me that same question on a job interview? Most job interviews usually have a time constraint, so there’s a high chance I would come up with the first (erroneous) version.

To me, this is freedom of creativity – to keep thinking about something that seems interesting and come up with a solution, without being pressured or constrained by time.

Tuply singleton

I noticed this while at a company team meetup. Whenever we were discussing which place we should eat food at, most of my coworkers were paying attention to two numbers: rating and number of votes.

For example, Restaurant #1 can have a 5.0-star rating with 1 vote, and Restaurant #2 can have a 3.9-star rating with 17 votes.

This metric makes a tuple, where the first element is the rating and the second element is the vote count. It is represented by, e.g. (3.9, 17) in Haskell (and is of type (Double, Int)), or [3.9, 17] (or { fst: 3.9, snd: 17 }) in JavaScript.

So we need two elements (or numbers) to capture this metric. What is a good way to combine them in a single element, such that both can be extracted at any time?

Continue reading “Tuply singleton”