The number of partitions of an integer is the number of ways that integer can be represented as a sum of positive integers.
5 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1
There are 7 ways to represent the number 5, therefore 7 is the partition number corresponding to the number 5.
Write a program that takes a positive integer as input, and outputs the two numbers that generate the two closest partition numbers to the input number.
- Input must be 1 positive integer.
- If the input is not a partition number, the output must be the 2 different positive integers that generate the two closest partition numbers to the input number. (If two partition numbers are equal candidates for one of the output numbers, it doesn't matter which one you choose.)
- If the input is a partition number, the output must be 1 positive integer that generates the input number.
- Input and output may be in any reasonable format.
- You may assume that the input will not be larger than 100 million (eg. output will never be larger than 95).
- Built-in functions to calculate partition numbers are not allowed, along with other Standard loopholes.
- This is code-golf, so least number of bytes wins.
Input: 66 Output: 11, 12
(The partition numbers that correspond to the numbers 11 and 12 are 56 and 77, which are the two closest partition numbers to 66.)
Input: 42 Output: 10
(The number 42 is already a partition number, so just output the number that corresponds to the partition number.)
Input: 136 Output: 13, 14
(The two closest partition numbers to 136 are actually both LESS than 136 (eg. 101 and 135), therefore the output is 13 and 14 as opposed to 14 and 15.)
Input: 1 Output: 0 or 1
(Both 0 and 1 are valid outputs in this special case.)
Input: 2484 Output: 26, 25 or 26, 27
(Both of these outputs are valid, because 2484 is equal distance from 1958 and 3010.)
Input: 4 Output: 3, 4