Skip to main content
added 6 characters in body
Source Link
Manish Kundu
  • 5.4k
  • 2
  • 19
  • 48

Python 3.8 (pre-release), 125 121 114 111 108108 107 bytes

import math
c=math.comb
f=lambda n,r,k=0,c=math.comb:n and(cn<c(k+1,r)>n and f(n-c(k,r),r-1)+[k]or f(n,r,k+1))or[*range(r)]

Try it online!Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

Python 3.8 (pre-release), 125 121 114 111 108 bytes

import math
f=lambda n,r,k=0,c=math.comb:n and(c(k+1,r)>n and f(n-c(k,r),r-1)+[k]or f(n,r,k+1))or[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

Python 3.8 (pre-release), 125 121 114 111 108 107 bytes

import math
c=math.comb
f=lambda n,r,k=0:n and(n<c(k+1,r)and f(n-c(k,r),r-1)+[k]or f(n,r,k+1))or[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

added 4 characters in body
Source Link
Manish Kundu
  • 5.4k
  • 2
  • 19
  • 48

Python 3.8 (pre-release), 125 121 114 111111 108 bytes

import math
f=lambda n,r,k=0,c=math.comb:n and(c(k+1,r)>n and f(n-c(k,r),r-1)+[k]if c(k+1,r)>n else+[k]or f(n,r,k+1))if n else[*rangeor[*range(r)]

Try it online!Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

Python 3.8 (pre-release), 125 121 114 111 bytes

import math
f=lambda n,r,k=0,c=math.comb:(f(n-c(k,r),r-1)+[k]if c(k+1,r)>n else f(n,r,k+1))if n else[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

Python 3.8 (pre-release), 125 121 114 111 108 bytes

import math
f=lambda n,r,k=0,c=math.comb:n and(c(k+1,r)>n and f(n-c(k,r),r-1)+[k]or f(n,r,k+1))or[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

deleted 30 characters in body
Source Link
Manish Kundu
  • 5.4k
  • 2
  • 19
  • 48

Python 3.8 (pre-release), 125 121 114 111 bytes

import math
f=lambda n,r,k=0,c=math.comb:(f(n-c(k,r),r-1)+[k]if c(k+1,r)>n else f(n,r,k+1))if n else[*range(r)]

Try it online!

Explanation: Start from k=0k=0 and keep increasing kk as long as comb(k, r)comb(k, r) does not exceed nn. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

Python 3.8 (pre-release), 125 121 114 111 bytes

import math
f=lambda n,r,k=0,c=math.comb:(f(n-c(k,r),r-1)+[k]if c(k+1,r)>n else f(n,r,k+1))if n else[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n.

Python 3.8 (pre-release), 125 121 114 111 bytes

import math
f=lambda n,r,k=0,c=math.comb:(f(n-c(k,r),r-1)+[k]if c(k+1,r)>n else f(n,r,k+1))if n else[*range(r)]

Try it online!

Explanation: Start from k=0 and keep increasing k as long as comb(k, r) does not exceed n. Update n accordingly. Once the current value of n is 0, simply return the first r integers starting from 0.

deleted 30 characters in body
Source Link
Manish Kundu
  • 5.4k
  • 2
  • 19
  • 48
Loading
Source Link
Manish Kundu
  • 5.4k
  • 2
  • 19
  • 48
Loading