partition_entier.py

Created by nicolas-patrois

Created on February 12, 2019

348 Bytes

Script from this page: http://jeromekelleher.net/category/combinatorics.html


def partent(n):
  a=[0 for _ in range(n+1)]
  k=1
  y=n-1
  liste=[]
  while k:
    x=a[k-1]+1
    k-=1
    while 2*x<=y:
      a[k]=x
      y-=x
      k+=1
    l=k+1
    while x<=y:
      a[k]=x
      a[l]=y
      liste.append(a[:k+2])
      x+=1
      y-=1
    a[k]=x+y
    y=x+y-1
    liste.append(a[:k+1])
  return liste

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.