15
4
Introduction
A pentagonal number (A000326) is generated by the formula Pn= 0.5×(3n2-n). Or you can just count the amount of dots used:
You can use the formula, or the gif above to find the first few pentagonal numbers:
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, 176, 210, 247, 287, 330, 376, 425, 477, etc...
Next, we need to compute the sum of x consecutive numbers.
For example, if x = 4, we need to look at Pn + Pn+1 + Pn+2 + Pn+3 (which consists of 4 terms). If the sum of the pentagonal numbers also is a pentagonal number, we will call this a pentagonal pentagon number.
For x = 4, the smallest pentagonal pentagon number is 330
, which is made of 4 consecutive pentagonal numbers: 51, 70, 92, 117
. So, when the input is 4
, your program of function should output 330
.
Task
- When given an integer greater than 1, output the smallest pentagonal pentagon number.
- You may provide a function or a program.
- Note: There are no solutions for e.g. x = 3. This means that if a number cannot be made from the first 10000 pentagonal numbers, you must stop computing and output whatever fits best for you.
- This is code-golf, so the submission with the least amount of bytes wins!
Test cases:
Input: 2
Output: 1926 (which comes from 925, 1001)
Input: 3
Output: ?
Input: 4
Output: 330 (which comes from 51, 70, 92, 117)
Input: 5
Output: 44290 (which comes from 8400, 8626, 8855, 9087, 9322)
Input: 6
Output: 651 (which comes from 51, 70, 92, 117, 145, 176)
Input: 7
Output: 287 (which comes from 5, 12, 22, 35, 51, 70, 92)
Input: 8
Output: ?
Input: 9
Output: 12105 (which comes from 1001, 1080, 1162, 1247, 1335, 1426, 1520, 1617, 1717)
Input: 10
Output: ?
Also bigger numbers can be given:
Input: 37
Output: 32782
Input: 55
Output: 71349465
Input: 71
Output: 24565290
4IMO it's crazy to penalise anyone who comes up with an analytic solution which can solve the harder cases by requiring them to check whether the solution is less than
10001-x
– Peter Taylor – 2015-12-21T21:41:19.3601@PeterTaylor With harder cases you mean like
x = 3
, which has no solutions? – Adnan – 2015-12-21T21:46:57.1374The largest test case that yields a result:
9919
-->496458299155
– Martin Ender – 2015-12-21T22:00:53.167No, I mean cases which have solutions but which use larger pentagonal numbers in the sum. – Peter Taylor – 2015-12-21T22:27:33.263
1I'm not sure about the 10,000 limit: Do the numbers that build the sum have to come from the first 10,000 pentagonal numbers, but not the sum itself, or has the sum also to be within the first 10,000? – nimi – 2015-12-21T22:32:10.493
@nimi Only the numbers that build the sum have to come from the first 10000 pentagonal numbers. The sum itself may exceed this amount. – Adnan – 2015-12-21T22:33:09.173
@PeterTaylor That means you need to prove that the x value has a solution in the first place. Or else it would run infinitely on non-solution integers. – Adnan – 2015-12-21T22:45:49.313
So what's the big deal? – Peter Taylor – 2015-12-21T22:47:40.630