I can follow Henry's clever solution.

0 ": 6 %~ (-: 999998 * 999999) + 3 * -: 999998

83333333333

I tried to replicate Roger's partition approach, and ran into memory
issues. Roger must have more memory on his machine:

pnk

4 : 0"0

n=. 0>.x [ k=. y

if. 1>:n<.k do. x: (0<n)*1=k else. ((n-1) pnk k-1) + (n-k) pnk k end.

)

1e2 pnk 3

833

1e3 pnk 3

83333

1e4 pnk 3

|stack error: pnk

| ((n-1)pnk k-1)+(n-k) pnk k

However, as Roger points out, this still does show the trend that the
answer is likely 83333333333.

Then I tried to replicate Roger's second approach:

+/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e2

_2207

+/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e3

_247007

+/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e4

_24970007


Engine: j807 /j64/windows Beta-c: commercial/2018-03-13T17:40:01 Library:
8.07.09 Qt IDE: 1.7.1/5.9.4 Platform: Win 64


Something's wrong here, as I can't replicate Roger's results, but I'm not
sure what is going wrong.


Skip




On Sun, May 20, 2018 at 9:31 AM Henry Rich <henryhr...@gmail.com> wrote:

> Taking advantage of the fact that thepartitions have only 3 elements.
>
> If the first number is i, the second number can be anything from 1 to
> 999999-iand the third number is then uniquely fixed.
>
> Since ican run from 1 to 999998, the total number of such choices is (-:
> 999998 * 999999).
>
> But this counts triplets more than once.  Any triplet in which the
> numbers are unique will be counted 6 times.
>
> Any triplet containing a repetition will be counted 3 times: once when i
> is the unrepeated number and twice when i is the repeated number.  This
> happens here whenever i is even, thus
> (-:999998) times.
>
> Any triplet containing all 3 numbers equal will be counted just once,
> but there aren't any of them.
>
> To find the unique triplets, we take (-: 999998 * 999999), add in 3 *
> (-:999998) to bring the 3-times-repeated cases up to 6-times-repeated,
> then divide by 6:
>
> 0 ": 6 %~ (-: 999998 * 999999) + 3 * -: 999998
>
> 83333333333
>
>
> Henry Rich
>
>
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to