In my previous post, I had a different approach to Tuply singleton.
This is the third and last post in the Tuply singleton series. We will provide mathematical proof for correctness, and also show a generalized formula.
life, mathematics, programming
In my previous post, I had a different approach to Tuply singleton.
This is the third and last post in the Tuply singleton series. We will provide mathematical proof for correctness, and also show a generalized formula.
In my previous post I showed how we can encode a pair into a single number.
I found out that encoding is wrong for some numbers. For example, consider the pairs . If you encode either of those using the formula we derived, you will get the same answer: 137.2.
In this post, we will change our strategy and slightly adjust our formula.
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?
Suppose one of your programmer friends comes to you and says: “Hey, convince me that 1 + 1 = 2!”.
What a request. You start by “Okay, I have one apple in my hand. I grab another one. Now I have two apples”.
Your friend proceeds: “I am still not convinced”. Now you turn to formalities.
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?