← RoseCode

ROSECODE 503

Find the partition

Philippe_57721 · Programming ·

A partition of an integer n will be represented by a non increasing sequence of integers.

The partitions of 7 in lexicographic order are:
  • 1 - 1 1 1 1 1 1 1
  • 2 - 2 1 1 1 1 1
  • 3 - 2 2 1 1 1
  • 4 - 2 2 2 1
  • 5 - 3 1 1 1 1
  • 6 - 3 2 1 1
  • 7 - 3 2 2
  • 8 - 3 3 1
  • 9 - 4 1 1 1
  • 10 - 4 2 1
  • 11 - 4 3
  • 12 - 5 1 1
  • 13 - 5 2
  • 14 - 6 1
  • 15 - 7
and in anti-lexicographic order:
  • 1 - 7
  • 2 - 6 1
  • 3 - 5 2
  • 4 - 5 1 1
  • 5 - 4 3
  • 6 - 4 2 1
  • 7 - 4 1 1 1
  • 8 - 3 3 1
  • 9 - 3 2 2
  • 10 - 3 2 1 1
  • 11 - 3 1 1 1 1
  • 12 - 2 2 2 1
  • 13 - 2 2 1 1 1
  • 14 - 2 1 1 1 1 1
  • 15 - 1 1 1 1 1 1 1
The 10th partition is 4,2,1 in the 1st case and 3,2,1,1 in the 2nd.

What are the 123456789th partition of 123 in lexicographic and anti-lexicographic order?

Answer format: (Comma delimited values) / (Comma delimited values)

Example: 4,2,1/3,2,1,1

[My timing: 11 sec ]