12
The number of partitions of an integer is the number of ways that integer can be represented as a sum of positive integers.
For example:
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.
Partition numbers: OEIS: #A000041
Directions
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.
Partition numbers: OEIS: #A000041
Examples
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
(Yup)
You didn't define what is a partition number – proud haskeller – 2014-12-26T18:44:54.253
@proudhaskeller Partition numbers are the numbers that are in the OEIS sequence linked. Explanation for what the partition number for
5
is is at the top. (I'll add clarification if you think it's not clear enough.) – kukac67 – 2014-12-26T18:51:04.4401
This is very close to being a dupe of this earlier partition question.
– Peter Taylor – 2014-12-26T20:47:27.370