Skip to content

Instantly share code, notes, and snippets.

View realkarmakun's full-sized avatar
🏠
Working from home

rkkm realkarmakun

🏠
Working from home
  • Russia
View GitHub Profile
@realkarmakun
realkarmakun / combination.py
Last active January 11, 2024 11:54 — forked from jonesinator/combination.py
Compute the nth combination in lexicographic order more efficiently, also with code for varying lengths
#! /usr/bin/python
#
# This snippet provides a simple function "combination" that can compute an
# arbitrary k-combination of n elements given an index m into the
# lexicographically ordered set of all k-combinations of n elements.
from math import comb