18
1
The Task
Given an input positive integer n
(from 1 to your language's limit, inclusively), return or output the maximum number of distinct positive integers that sum to n
.
Test Cases
Let f
define a valid function according to the task:
The sequence for f
, starting at 1:
1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, ...
As a larger test case:
>>> f(1000000000) // Might not be feasible with brute-forcers
44720
Test Code
For any test cases not explicitly given, the output of your code should match the result of the following:
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println((int) Math.floor(Math.sqrt(2*x + 1./4) - 1./2));
}
}
Can it be 0-indexed? – totallyhuman – 2018-01-05T00:05:00.240
1@totallyhuman "it" being the answers? Because this isn't about a list... – Addison Crump – 2018-01-05T00:12:26.530
Yes. Can the output for 1 be 2? – totallyhuman – 2018-01-05T00:13:52.047
3@totallyhuman No. This is about the distinct partitions of specific numbers. – Addison Crump – 2018-01-05T00:14:39.247
5
This is OEIS A003056.
– Jeppe Stig Nielsen – 2018-01-05T10:33:05.957If it helps anyone, this is equivalent to finding the last triangle number, and returning its index in the sequence of triangle numbers. – FlipTack – 2018-01-05T17:33:00.283
4I feel insignificant most every time I stumble into the codegolf stack. The answers and the comments are much more than humbling. The questions are usually interesting too but with his comment @JeppeStigNielsen just throws in the completed blueprints when we are still contemplating the floor area. – KalleMP – 2018-01-06T21:25:10.483