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 inte
Ahhh, the anti-base is clever. Now I get it.
3 4 #: 0 6 7
0 0
1 2
1 3
While the spare-array trick is great, I think this answer resonates as more
in keeping with an array-oriented 'style' that I'm trying to internalize.
It also succinctly does what I was trying to do with modulus/division hack
Sorry, that tacit form got butchered in copy/pasting through different
mediums and is actually
(|@-)/@(0&{)@(a {~ (b {~ I.@(a e.~ (|@:-)/"1@:(a {~ b=:4&$.@$.@(a e.~ (
wrote:
> Mike, thanks for thinking like I had a analytic insight, but I made a
> mistake.
>
> In my defense, I did know to divide
Mike, thanks for thinking like I had a analytic insight, but I made a
mistake.
In my defense, I did know to divide by 2, but at the time I was exploring
what forms of verbs could automatically be inverted (obverted?) to create a
possible "is_pentagonal" predicate and accidentally copied my truncat
Trying out Pascal Jasmin’s brute-force approach (beware his spoiler!) runs out
of memory on this iPad.
Some of the solvers’ forum messages, from 2005 and later, boast of times as
low as 0.2sec (Delphi)
I’ve just worked up something akin to Oleg Kolobchenko’s approach; it takes
about 12 sec on
It looks as if Daniel was solving the problem for pentagonal numbers * 2.
Clearly, if there’s a solution in true Pn for a pair of indices, m > n,
ie, (-/ Pn m,n) = +/ Pn m,n,
it will also be a solution for 2 * Pn .
I suppose there might be some half-integral solutions for 2 * Pn which don’t
your definition of pentagonal doesn't do the divide by 2 step
pentagonal =: [ -:@* ( 1 -~ 3 * ])
this combines (,:) the +/ and -/ tables into 2, then finds intersection (*./).
4$.$. returns index(es)
4 $. $. *./@:(e.~ -/~ ,: +/~) pentagonal >: i.20115
2166 1019
On Thursday, July 11, 201
Sorry - I see Louis has just posted a very similar comment, but I'll
persist!...
I usually use something more basic and more boring!
The idea is that you use the shape of your input as the basis for a
representation of the indices of the ravelled version of the array.
Here goes:
] toy =: 3 4
Hi Daniel,
If the ravel indices into the array M are stored in I, the multi-dimensional
indices are then
($M) #: I
So for your toy example a possible verb is
v=: $ #: , I.@:= _1:
Cheers,
Louis
> On 12 Jul 2019, at 02:11, Daniel Eklund wrote:
>
> Double thanks.
>
> One for that sparse arra