Jon Rosario's Journal.
Unique Numbers Algorithm [WIP]
April 6, 2021
I worked on writing an algorithm that would generate a set of positive integers {n1, n2, ..., nk} that would satisfy follow criteria:
1. ni > ni-1
2. Each number ni is not repeated in the set
3. Each number ni cannot be recreated by summing any combination of the previous numbers {n1, n2, ..., nk}
An example of such a set of numbers is {1, 2, 4}. Each sequential number is increasing, there are no repeats, and you cannot make a number from summation of the previous numbers in the set (4 is not equal to 2+1).
In reality, the reason for this was mostly curiousity resulting from social media. On social media, there a popular game where people will give a list of actions, and for each that you have (or haven't) done, you will add a point value to your "score". A player will post their resulting score, but others will not know which actions gave them points. Example is shown below:
I was interested in whether there is a set of point values you can associate to each action, and thus be able to figure out exactly what actions a player picked. I split the problem into three parts:
1. Writing up a way to check if a single number could be made from ANY possible sum of a list of integers
2. Checking if a set of integers satisfied the above condition for every sequential number and it's subset of integers preceding it in the original set.
Easily generating a list of random numbers satisifying these conditions
Today, I did the first two using these two functions. o_check corresponds to 1. It returns a list of possible ways to add up to a given number "points" given a dictionary of actions mapped onto point values {str:int}. is_unique_map corresponds to 2. It returns a boolean value (True = dictionary satisfies conditions/ False = fails conditions), and a list of combinations that would cause in_unique_map to return a False using o_check.
I still haven't gotten to the third part, but that's because I want to figure out an efficient method of generating numbers that isn't too intensive.
That's all for now, thanks for reading!