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”

Meet them all

Here’s a funny algorithm task I was thinking about during lunch at Automattic Grand Meetup.

Given infinite tables and 900 people – they have lunch, then dinner, then lunch, etc. repeatedly. They can’t have lunch after lunch, or dinner after dinner. A lunch table consists of 8 persons and a dinner table consists of 4.

What is the least number (or a good lower bound) of lunches and dinners they need to have for every person to have met all other persons?

Continue reading “Meet them all”