A simple Python terminal program to manage a list of items (superset) and create smaller groups (subsets) using a clever math trick called dyadic retrieval algorithm. Each item in a subset can only appear once, and the program keeps everything saved for later.
- Add items to a superset (your master list)
- Create subsets from items in the superset
- Show any subset or all subsets
- Show all items in the superset
- Friendly colored terminal output
- Python 3.10+ (should work on most Python 3 versions)
- Terminal (Linux, macOS, Windows Terminal, or VS Code terminal)
- No extra Python packages required
⚠ On old Windows
cmd.exe, colors may not work. Use Windows Terminal or VS Code terminal for full experience.
- Download the code to a folder on your computer.
- Open a terminal and navigate to that folder.
- Run the program:
python main.pyYou’ll see a menu like this:
=== Menu ===
0. Exit
1. Form the superset
2. Show the superset
3. Create a subset
4. Output a subset
5. Show all subsets- Form the superset
- Choose option 1
- Type items you want in your master list, one at a time
- Type X when you’re done
You will get colored messages:
- Green = item added
- Yellow = item already exists
- Show the superset
- Choose option 2
- See all items you have in your superset
- Create a subset
- Choose option 3
- Give your subset a name
- Add items from your superset, one by one
- Type X to finish the subset
Messages:
- Green = item added
- Yellow = item already in subset
- Red = item not in superset
You cannot create a subset until you have at least one item in the superset.
- Output a subset
- Choose option 4
- Type the name of a subset
- See all items in that subset
- Type X to stop
- Show all subsets
- Choose option 5
- Shows all your subsets and their items at once
- Exit
- Choose option 0 to safely exit the program
Subsets are saved automatically in
subsets.json
Superset items are saved in
superset.txt
The program prevents duplicates in subsets
In this program, each subset is represented by a single number, called the sum identifier. This number, denoted as
This sum identifier is unique for each subset because every combination of powers of two produces a different sum — this is why the algorithm is called dyadic (dyadic = “based on powers of two”). The function
We define
Note: unlike formulas using
$k = \left\lfloor \log_{2}(n) \right\rfloor$ here we select$k$ iteratively: starting from 0, we increase$k$ until$2^{k+1} > n$ then pick$2^k$
For
Therefore:
Verifying: