{"id":13516967,"url":"https://github.com/mxschmitt/golang-combinations","last_synced_at":"2025-05-16T08:05:27.314Z","repository":{"id":48102644,"uuid":"135211310","full_name":"mxschmitt/golang-combinations","owner":"mxschmitt","description":"Golang library which provide an algorithm to generate all combinations out of a given string array.","archived":false,"fork":false,"pushed_at":"2024-10-21T08:23:04.000Z","size":34,"stargazers_count":121,"open_issues_count":0,"forks_count":20,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-08T20:17:56.258Z","etag":null,"topics":["arrangement","array","golang","hacktoberfest","permutation","powerset","string","strings"],"latest_commit_sha":null,"homepage":"https://mxschmitt.github.io/golang-combinations","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mxschmitt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mxschmitt"}},"created_at":"2018-05-28T21:34:57.000Z","updated_at":"2025-03-02T23:01:57.000Z","dependencies_parsed_at":"2024-06-18T13:44:40.609Z","dependency_job_id":"96b3aa98-4eec-483f-83c1-bbdbf2a4c8ad","html_url":"https://github.com/mxschmitt/golang-combinations","commit_stats":{"total_commits":32,"total_committers":8,"mean_commits":4.0,"dds":0.40625,"last_synced_commit":"904496b8053593863e2f7a517808cf990386c6d0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxschmitt%2Fgolang-combinations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxschmitt%2Fgolang-combinations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxschmitt%2Fgolang-combinations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxschmitt%2Fgolang-combinations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mxschmitt","download_url":"https://codeload.github.com/mxschmitt/golang-combinations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493378,"owners_count":22080126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrangement","array","golang","hacktoberfest","permutation","powerset","string","strings"],"created_at":"2024-08-01T05:01:27.886Z","updated_at":"2025-05-16T08:05:22.305Z","avatar_url":"https://github.com/mxschmitt.png","language":"Go","funding_links":["https://github.com/sponsors/mxschmitt"],"categories":["`list.Combinations(n int, joiner string) (*golist.List, error)`","Go"],"sub_categories":[],"readme":"# Golang combinations\n\n[![GoDoc](https://godoc.org/github.com/mxschmitt/golang-combinations?status.svg)](https://godoc.org/github.com/mxschmitt/golang-combinations)\n[![Go](https://github.com/mxschmitt/golang-combinations/actions/workflows/go.yml/badge.svg)](https://github.com/mxschmitt/golang-combinations/actions/workflows/go.yml)\n[![Coverage Status](https://coveralls.io/repos/github/mxschmitt/golang-combinations/badge.svg?branch=master)](https://coveralls.io/github/mxschmitt/golang-combinations?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mxschmitt/golang-combinations)](https://goreportcard.com/report/github.com/mxschmitt/golang-combinations)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nThis package provides a method to generate all ordered combinations out of a given generic array.\nThis essentially creates the powerset of the given array except that the empty set is disregarded.\n\n## Examples\n\nTake a look at the [godoc](https://godoc.org/github.com/mxschmitt/golang-combinations/#pkg-examples) for examples.\n\nIn general when you have e.g. `[]string{\"A\", \"B\", \"C\"}` you will get:\n\n```json\n[\n    [\"A\"],\n    [\"B\"],\n    [\"A\", \"B\"],\n    [\"C\"],\n    [\"A\", \"C\"],\n    [\"B\", \"C\"],\n    [\"A\", \"B\", \"C\"]\n]\n```\n\n## Background\n\nThe 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.\n\nE.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\"}`.\n\nFor 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:\n\n```txt\n1\t=\t0001\t=\u003e\t---A\t=\u003e\t{\"A\"}\n2\t=\t0010\t=\u003e\t--B-\t=\u003e\t{\"B\"}\n3\t=\t0011\t=\u003e\t--BA\t=\u003e\t{\"A\", \"B\"}\n4\t=\t0100\t=\u003e\t-C--\t=\u003e\t{\"C\"}\n5\t=\t0101\t=\u003e\t-C-A\t=\u003e\t{\"A\", \"C\"}\n6\t=\t0110\t=\u003e\t-CB-\t=\u003e\t{\"B\", \"C\"}\n7\t=\t0111\t=\u003e\t-CBA\t=\u003e\t{\"A\", \"B\", \"C\"}\n8\t=\t1000\t=\u003e\tD---\t=\u003e\t{\"D\"}\n9\t=\t1001\t=\u003e\tD--A\t=\u003e\t{\"A\", \"D\"}\n10\t=\t1010\t=\u003e\tD-B-\t=\u003e\t{\"B\", \"D\"}\n11\t=\t1011\t=\u003e\tD-BA\t=\u003e\t{\"A\", \"B\", \"D\"}\n12\t=\t1100\t=\u003e\tDC--\t=\u003e\t{\"C\", \"D\"}\n13\t=\t1101\t=\u003e\tDC-A\t=\u003e\t{\"A\", \"C\", \"D\"}\n14\t=\t1110\t=\u003e\tDCB-\t=\u003e\t{\"B\", \"C\", \"D\"}\n15\t=\t1111\t=\u003e\tDCBA\t=\u003e\t{\"A\", \"B\", \"C\", \"D\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxschmitt%2Fgolang-combinations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmxschmitt%2Fgolang-combinations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxschmitt%2Fgolang-combinations/lists"}