Back on the laptop,  running J903 rather than J701 which crashed on the less compendious iPad. Here's a somewhat speedier version of Bob Theriault's approach.  (I wasn't seeking to speed it up,
but it wouldn't complete in reasonable time without a tweak or two.)

rt =: 3 : 0
N  =. y
n  =. >: i. N
NB. +/ @:(*./"1)@:(= <.)@:(3 %~ (* (0 -.~ _&q:))) n NB. RT's Original answer for the list up to n^n
+/ @:(3 (0*/"1@:=|) (*{:"2@:(__&q:))) n NB. more space-efficient equivalent
)

I'll repeat the definition of qprob here for convenience:
qprob =: 3 : 0
N   =. y
t1  =. N <.@% 3.   NB. Floor (N % 3)
t2  =. N <.@^ %3   NB. Floor (N ^ 1%3)
t3  =. 3 <.@%~ N <.@^ %3  NB. Floor ( (N ^ 1%3) % 3)
(;~ +/) t1, t2, -t3
)

And here are the comparisons:
   (<@rt, qprob)"0 ] 10 100 10000 100000 NB. Theriault's and my results
+-----+-----+------------+
|5    |5    |3 2 0       |   NB. No type 3s <: 10 (added comment!)
+-----+-----+------------+
|36   |36   |33 4 _1     |
+-----+-----+------------+
|3347 |3347 |3333 21 _7  |
+-----+-----+------------+
|33364|33364|33333 46 _15|
+-----+-----+------------+

Mike



On 21/03/2021 11:25, 'Mike Day' via Programming wrote:
OK...
here’s what I should have sent earlier:
1. The required number includes all nn = n raised to n for which n are 
multiples of 3.
2. It also includes all nn for which n are already powers of 3
3. But we need to avoid double-counting nn for which both 1 & 2 apply.

So:
qprob =: 3 : 0
N   =. y
t1  =. N <.@% 3.   NB. Floor (N % 3)
t2  =. N <.@^ %3  NB. Floor (N ^ 1%3)
t3  =. 3 <.@%~ N <.@^ %3  NB. Floor ( (N ^ 1%3) % 3)
(;~ +/) t1, t2, -t3
)

    qprob 1000
+---+---------+
|340|333 10 _3|
+---+---------+
    qprob 10000
+----+----------+
|3347|3333 21 _7|
+----+----------+
    qprob 100000
+-----+------------+
|33364|33333 46 _15|
+-----+------------+

Consistent with Bob’s results for 1000 and 10000.  The iPad’s J session crashed 
checking
his method for 100000;  not his fault!

Sorry, this looks crummy on the iPad.

Mike

Sent from my iPad

On 21 Mar 2021, at 08:41, 'robert therriault' via Programming 
<programm...@jsoftware.com> wrote:

    n=. >: i. 1000 NB. set up list from 1 to 1000
   _&q: 1000   NB. returns the prime exponents of 1000
3 0 3
   (* _&q:) 1000 NB. returns the prime exponents of 1000^1000
3000 0 3000
   (= <.)@:(3 %~ (* _&q:)) 1000 NB. divides the exponents by 3 then returns 1 
for integer result
1 1 1
   (*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. if all exponents are divisible by 
3 then it is a cube
1
   +/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. sum up the number of cubes - 
returns 1 since 1000^1000 is a cube
1
   +/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) n NB. answer for the list up to n^n
340

as it turns out the 340 are these

    17 20 $ >: I. *./"1@:(= <.)@:(3 %~ (* _&q:)) n
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to