https://github.com/bapjiws/power-set
Script with command-line arguments
https://github.com/bapjiws/power-set
Last synced: 3 months ago
JSON representation
Script with command-line arguments
- Host: GitHub
- URL: https://github.com/bapjiws/power-set
- Owner: bapjiws
- Created: 2015-04-30T09:21:44.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-30T09:24:33.000Z (about 10 years ago)
- Last Synced: 2025-01-28T16:44:18.146Z (5 months ago)
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This script takes a list of at least two items (single alphanumeric characters and special characters or sequences thereof) separated by single spaces and returns a power set with elements sorted by their length.
This implementation relies on binary representation of the provided list. For example, for the input a b c it constructs a list ['000', '001', '010', '011', '100', '101', '110', '111'], where 011 means that we take the last two items and 100 means we take only the first item. Similarly, for the input 1 2 3 4 it constructs ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'], where 1010 means we take the first and the third item.
This is obviously not the fastest possible implementation. It does what it’s supposed to, though :)