All Projects → mxschmitt → Golang Combinations

mxschmitt / Golang Combinations

Licence: mit
Golang library which provide an algorithm to generate all combinations out of a given string array.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Golang Combinations

Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-31.37%)
Mutual labels:  array, string, strings
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-72.55%)
Mutual labels:  string, array
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (+0%)
Mutual labels:  array, strings
indexed-string-variation
Experimental JavaScript module to generate all possible variations of strings over an alphabet using an n-ary virtual tree
Stars: ✭ 16 (-68.63%)
Mutual labels:  string, strings
Data-Structures-Algorithms-Handbook
A series of important questions with solutions to crack the coding interview and ace it!
Stars: ✭ 30 (-41.18%)
Mutual labels:  strings, array
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (-56.86%)
Mutual labels:  string, array
StringPool
A performant and memory efficient storage for immutable strings with C++17. Supports all standard char types: char, wchar_t, char16_t, char32_t and C++20's char8_t.
Stars: ✭ 19 (-62.75%)
Mutual labels:  string, strings
DS ALGO
Data Structures and algorithms
Stars: ✭ 20 (-60.78%)
Mutual labels:  string, array
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (+425.49%)
Mutual labels:  array, string
Interview Questions In Javascript
A mostly reasonable collection of technical software development interview questions solved in Javascript
Stars: ✭ 3,268 (+6307.84%)
Mutual labels:  array, strings
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+529.41%)
Mutual labels:  array, string
Competitive Programming
Programming👨‍💻 Questions on BinarySearch💻, LeetCode💻, CodeChef💻, Codeforces💻,DSA 450
Stars: ✭ 188 (+268.63%)
Mutual labels:  string, array
common
Metarhia Common Library
Stars: ✭ 55 (+7.84%)
Mutual labels:  strings, array
tplv
👣 Nano string template library for modern, based on ES6 template string syntax.
Stars: ✭ 31 (-39.22%)
Mutual labels:  string, strings
php-helpers
An extensive set of PHP helper functions and classes.
Stars: ✭ 27 (-47.06%)
Mutual labels:  string, array
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (+33.33%)
Mutual labels:  string, array
Problem-Solving
This Repository consists of my solutions💡 in Python 3 to various problems in Data Structures and Algorithms.🎖️
Stars: ✭ 17 (-66.67%)
Mutual labels:  strings, array
Data-Structure-Algorithm-Programs
This Repo consists of Data structures and Algorithms
Stars: ✭ 464 (+809.8%)
Mutual labels:  string, array
type-reverse
🦄 Lightweight reverse utility around strings, arrays, numbers and more.
Stars: ✭ 30 (-41.18%)
Mutual labels:  string, array
Android interviews
🚀Everything you need to know to find a android job. 算法 / 面试题 / Android 知识点 🔥🔥🔥 总结不易,你的 star 是我最大的动力!
Stars: ✭ 510 (+900%)
Mutual labels:  array, string

Golang combinations

GoDoc Build Status Coverage Status Go Report Card License

This package provides a method to generate all ordered combinations out of a given string array. This essentially creates the powerset of the given array except that the empty set is disregarded.

Examples

Take a look at the godoc for examples.

In general when you have e.g. []string{"A", "B", "C"} you will get:

[
    ["A"],
    ["B"],
    ["A", "B"],
    ["C"],
    ["A", "C"],
    ["B", "C"],
    ["A", "B", "C"]
]

Background

The algorithm iterates over each number from 1 to 2^length(input), separating it by binary components and utilizes the true/false interpretation of binary 1's and 0's to extract all unique ordered combinations of the input slice.

E.g. a binary number 0011 means selecting the first and second index from the slice and ignoring the third and fourth. For input {"A", "B", "C", "D"} this signifies the combination {"A", "B"}.

For input slice {"A", "B", "C", "D"} there are 2^4 - 1 = 15 binary combinations, so mapping each bit position to a slice index and selecting the entry for binary 1 and discarding for binary 0 gives the full subset as:

1	=	0001	=>	---A	=>	{"A"}
2	=	0010	=>	--B-	=>	{"B"}
3	=	0011	=>	--BA	=>	{"A", "B"}
4	=	0100	=>	-C--	=>	{"C"}
5	=	0101	=>	-C-A	=>	{"A", "C"}
6	=	0110	=>	-CB-	=>	{"B", "C"}
7	=	0111	=>	-CBA	=>	{"A", "B", "C"}
8	=	1000	=>	D---	=>	{"D"}
9	=	1001	=>	D--A	=>	{"A", "D"}
10	=	1010	=>	D-B-	=>	{"B", "D"}
11	=	1011	=>	D-BA	=>	{"A", "B", "D"}
12	=	1100	=>	DC--	=>	{"C", "D"}
13	=	1101	=>	DC-A	=>	{"A", "C", "D"}
14	=	1110	=>	DCB-	=>	{"B", "C", "D"}
15	=	1111	=>	DCBA	=>	{"A", "B", "C", "D"}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].