{"id":23282525,"url":"https://github.com/n8brooks/combinatorics","last_synced_at":"2025-08-21T13:33:35.122Z","repository":{"id":42422224,"uuid":"411153966","full_name":"N8Brooks/combinatorics","owner":"N8Brooks","description":"🦕 Combinatorial generators including combinations, permutations, combinations with replacement, permutations with replacement, cartesian products, and power sets.","archived":false,"fork":false,"pushed_at":"2022-07-06T04:28:42.000Z","size":115,"stargazers_count":26,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-09T18:46:35.934Z","etag":null,"topics":["cartesian-product","combinations","combinations-with-repetition","combinatorics","deno","npm","permutations","permutations-with-repetition","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/combinatorics","language":"TypeScript","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/N8Brooks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-28T05:52:04.000Z","updated_at":"2024-08-20T04:06:08.000Z","dependencies_parsed_at":"2022-09-17T14:52:43.593Z","dependency_job_id":null,"html_url":"https://github.com/N8Brooks/combinatorics","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N8Brooks%2Fcombinatorics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N8Brooks%2Fcombinatorics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N8Brooks%2Fcombinatorics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N8Brooks%2Fcombinatorics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/N8Brooks","download_url":"https://codeload.github.com/N8Brooks/combinatorics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230516244,"owners_count":18238368,"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":["cartesian-product","combinations","combinations-with-repetition","combinatorics","deno","npm","permutations","permutations-with-repetition","typescript"],"created_at":"2024-12-20T00:17:47.247Z","updated_at":"2024-12-20T00:17:47.873Z","avatar_url":"https://github.com/N8Brooks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# combinatorics\n\n[![docs](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/combinatorics/mod.ts)\n[![codecov](https://codecov.io/gh/N8Brooks/combinatorics/branch/main/graph/badge.svg?token=PTN34S691O)](https://codecov.io/gh/N8Brooks/combinatorics)\n[![cd](https://github.com/N8Brooks/combinatorics/actions/workflows/cd.yml/badge.svg)](https://github.com/N8Brooks/combinatorics/actions/workflows/cd.yml)\n[![ci](https://github.com/N8Brooks/combinatorics/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/N8Brooks/combinatorics/actions/workflows/ci.yml)\n\nThis module provides generators for iterating subsets of an input. It is heavily\ninspired by the combinatorial iterators provided by the\n[itertools](https://docs.python.org/3/library/itertools.html) package from the\n`Python` standard library.\n\n- All generators are importable on their own.\n- These implementations do not build up intermediate results in memory.\n- All functions iterate subsets lexicographically according to their input\n  indices. If the input is sorted the output will be too.\n- Likewise, whether the input elements are unique or not does not matter.\n- The inputs provided are not modified, however, consumable iterables will be\n  consumed.\n\n## Usage\n\n### combinations\n\nYields `r` length `Arrays` from the input `iterable`. Order of selection does\nnot matter and elements are chosen without replacement.\n\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { combinations } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...combinations([1, 2, 3, 4], 2)];\n\nassertEquals(sequences, [\n  [1, 2],\n  [1, 3],\n  [1, 4],\n  [2, 3],\n  [2, 4],\n  [3, 4],\n]);\n```\n\n### permutations\n\nYields `r` length `Arrays` from the input `iterable`. Order of selection is\nimportant and elements are chosen without replacement. If `r` is undefined, then\nthe length of the `iterable` is used.\n\n\u003c!-- deno-fmt-ignore --\u003e\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { permutations } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...permutations([1, 2, 3, 4], 2)];\n\nassertEquals(sequences, [\n  [1, 2], [1, 3], [1, 4],\n  [2, 1], [2, 3], [2, 4],\n  [3, 1], [3, 2], [3, 4],\n  [4, 1], [4, 2], [4, 3],\n]);\n```\n\n### combinationsWithReplacement\n\nYields `r` length `Arrays` from the input `iterable`. Order of selection is not\nimportant and elements are chosen with replacement.\n\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { combinationsWithReplacement } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...combinationsWithReplacement([1, 2, 3, 4], 2)];\n\nassertEquals(sequences, [\n  [1, 1],\n  [1, 2],\n  [1, 3],\n  [1, 4],\n  [2, 2],\n  [2, 3],\n  [2, 4],\n  [3, 3],\n  [3, 4],\n  [4, 4],\n]);\n```\n\n### permutationsWithReplacement\n\nYields `r` length `Arrays` from the input `iterable`. Order of selection is\nimportant and elements are chosen with replacement.\n\n\u003c!-- deno-fmt-ignore --\u003e\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { permutationsWithReplacement } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...permutationsWithReplacement([1, 2, 3, 4], 2)];\n\nassertEquals(sequences, [\n  [1, 1], [1, 2], [1, 3], [1, 4],\n  [2, 1], [2, 2], [2, 3], [2, 4],\n  [3, 1], [3, 2], [3, 3], [3, 4],\n  [4, 1], [4, 2], [4, 3], [4, 4],\n]);\n```\n\n### cartesianProduct\n\nRoughly equivalent to running nested `for...of` loops using one of the inputs to\nprovide the element at each index for the yielded `Array`.\n\n\u003c!-- deno-fmt-ignore --\u003e\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { cartesianProduct } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...cartesianProduct([1, 2, 3], [4, 5, 6], [7, 8, 9])];\n\nassertEquals(sequences, [\n  [1, 4, 7], [1, 4, 8], [1, 4, 9],\n  [1, 5, 7], [1, 5, 8], [1, 5, 9],\n  [1, 6, 7], [1, 6, 8], [1, 6, 9],\n  [2, 4, 7], [2, 4, 8], [2, 4, 9],\n  [2, 5, 7], [2, 5, 8], [2, 5, 9],\n  [2, 6, 7], [2, 6, 8], [2, 6, 9],\n  [3, 4, 7], [3, 4, 8], [3, 4, 9],\n  [3, 5, 7], [3, 5, 8], [3, 5, 9],\n  [3, 6, 7], [3, 6, 8], [3, 6, 9],\n]);\n```\n\n### powerSet\n\nThe set of all subsets of the given `iterable`. Equivalent to running\n`combinations` with `0 \u003c= r \u003c= iterable.length` and flattening the results. The\nfirst subset is the empty set given when `r = 0`.\n\n```ts\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport { powerSet } from \"https://deno.land/x/combinatorics/mod.ts\";\n\nconst sequences = [...powerSet([1, 2, 3])];\n\nassertEquals(sequences, [\n  [],\n  [1],\n  [2],\n  [3],\n  [1, 2],\n  [1, 3],\n  [2, 3],\n  [1, 2, 3],\n]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn8brooks%2Fcombinatorics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn8brooks%2Fcombinatorics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn8brooks%2Fcombinatorics/lists"}