At long last -
I've only just managed to find some further solutions!
I generate triples of P5s,
such that P5(a) + P5(b) = P5(c) for triple (a,b,c)
and check for which of them P5(d) = P5(a) + P5(c) for an integer d:
|:Ptriples 30
4 7 12 19
7 23 22 22
8 24 25 29
Here are some timings on my laptop; the first result is dotted out
to observe Project Euler’s no spoiler convention. I don't think they'll mind
the higher
values being shared. (This was all aligned on the laptop, but I’m
having to send from this iPad, which isn’t offering fixed width.)
NB. timer'solve 2500' about 0.05 sec..
NB. timer'solve 10000'
NB. ┌────────┬───────────────────┐
NB. │0.467995│...................│
NB. └────────┴───────────────────┘
NB. timer'solve 50000'
NB. ┌──────┬───────────────────┐
NB. │26.209│...................│
NB. └──────┴───────────────────┘
NB. timer'solve 150000'
NB. ┌─────────┬──────────────────────────┐
NB. │11 59.412│ .........................│
NB. │ │52430 75172 91650 105587│
NB. │ │73745 106084 129198 148763│
NB. └─────────┴──────────────────────────┘
Even at this running time, I believe 99% of the time is
consumed by Ptriples ! Finding the quadruples is trivial.
Mike
On 13/07/2019 00:31, Skip Cave wrote:
> Another approach to Euler 44:
> NB. make a pentagonal number generator verb:
> *pn=.3 :'y*(1-~3*y)%2'*
>
> NB. Generate the first 5000 pentagonal numbers and store them in p. Then
> find all possible pair combinations of the first 5000 pentagonal numbers
> and store the pairs in p2. Then store the two integers in each pair in the
> vectors a & b respectively:
> * 'a b'=.|:p2=.(2 comb 5000){p=:pn>:i.5000x*
>
> NB. Find and mark all pairs where a+b and a-b are both pentagonal numbers.
> Store that mark vector in m. Also sum the marks in m to see how many
> solution pairs we have:
> * +/m=.(p e. ~a+b) *. p e. ~|a-b*
>
> *1*
>
> NB. So there is only one solution pair in the first 5000 pentagonal
> numbers. Now use the mark vector to extract that one pair of pentagonal
> numbers we found that meets all the criteria, store the pair in n, and
> display them.
> * ]n=.m#p2*
>
> *..............*
>
>
> NB. List a, b, a+b, & a-b of the discovered pair in n=a,b:
>
> * (,n),(+/"1 n),(|-/"1 n) *
>
> *.........................*
>
>
> NB. Are the four integers a, b, a+b, & a-b all pentagonal numbers?
>
> *p e.~(,n),(+/"1 n),(|-/"1 n) *
>
> *1 1 1 1*
>
>
> NB. Yes. So what is "D" (the difference between the pair) which is required
> to get the final answer in the euler question?
>
>
> *]D=.|-/"1 n*
>
> *...........*
>
>
> However the Euler 44 question wants to find a pentagonal pair where D is
> minimised, so we will need to expand our search so see if there are
> pentagonal pairs with a smaller D. Unfortunately, I run into memory limits
> when I try to examine a larger range of pentagonal numbers. So I'll need to
> break the one-shot approach into a loop and segment the array of pentagonal
> numbers (sigh). I'll leave that exercise for the reader...
>
>
> Skip Cave
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
.
Sent from my iPad
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm