mathtools.partition_integer_by_ratio — Abjad v1.1.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Project Abjad »
- Abjad v1.1.1 documentation »
- Abjad API »

# mathtools.partition_integer_by_ratio

`abjad.tools.mathtools.` `partition_integer_by_ratio`(n, ratio)

  Partition integer `n` into parts such that the sum of all parts in parts equals `n` and such that the proportions between the parts in parts equals the the proportions in `ratio` with some rounding magic.

      abjad> mathtools.partition_integer_by_ratio(10, [1])
      [10]

      abjad> mathtools.partition_integer_by_ratio(10, [1, 1])
      [5, 5]

      abjad> mathtools.partition_integer_by_ratio(10, [1, 1, 1])
      [3, 4, 3]

      abjad> mathtools.partition_integer_by_ratio(10, [1, 1, 1, 1])
      [3, 2, 3, 2]

      abjad> mathtools.partition_integer_by_ratio(10, [1, 1, 1, 1, 1])
      [2, 2, 2, 2, 2]

      abjad> ratio(10, [1, 2])
      [3, 7]

      abjad> ratio(10, [3, 1])
      [8, 2]

      abjad> ratio(10, [3, 2])
      [6, 4]

  Raise `TypeError` on noninteger n:

      abjad> mathtools.partition_integer_by_ratio('foo', [1, 1, 3])
      TypeError

  Raise `ValueError` on nonpositive n:

      abjad> mathtools.partition_integer_by_ratio(-1, [1, 1, 3])
      ValueError

### Navigation

- index
- modules |
- next |
- previous |
- Project Abjad »
- Abjad v1.1.1 documentation »
- Abjad API »