partitionFib

maelzel.distribute.partitionFib(n, numpart)[source]

Partition n into numpart partitions with fibonacci proportions

Parameters:
  • n (int) – the number to partition

  • numpart (int) – the number of partitions

Return type:

list[float]

Returns:

a list of partitions which add up to n

Example

>>> from maelzel import distribute
>>> from emlib.iterlib import pairwise
>>> parts = distribute.partitionFib(40, 5)
>>> parts
[2.4500439227299493,
 3.964254340907179,
 6.414298263637129,
 10.378552604544307,
 16.792850868181436]
>>> intparts = distribute.roundSeqPreservingSum(parts)
>>> intparts
[3, 4, 7, 10, 16]
>>> for p1, p2 in pairwise(intparts):
...     print(f"{p1 = } {p2 = }         {p2/p1 = :.3f}")
p1 = 3  p2 = 4          p2/p1 = 1.333
p1 = 4  p2 = 7          p2/p1 = 1.750
p1 = 7  p2 = 10         p2/p1 = 1.429
p1 = 10 p2 = 16         p2/p1 = 1.600

Note

In order to partition into integer values, use roundSeqPreservingSum()