[Jprogramming] Perfect powers

Raul Miller rauldmiller at gmail.com
Wed Jan 30 05:33:28 HKT 2008


On 1/29/08, R.E. Boss <r.e.boss at planet.nl> wrote:
> pp2=: 3 : '1,/:~~.;<@(^~ 2+i.@<:)/"1 (](],.<.@%:~) 2(+i. at -@<:) 2<.@^.]) y'

A variation on this approach which requires slightly less space:

num2=:- i.@<:
pp3=: 1, /:~@~.@;@((] (^~ num2)&.> <.@%:~) 2 num2@<.@^. ])

     10 ts 'pp2 2000000'
0.00050174 91712
     10 ts 'pp3 2000000'
0.000478301 78848

Or, if you would like to avoid ~ and hooks:
pp4=: 1, /:~@~.@;@((2 num2@<.@^. ]) ([ (num2@] ^ [)&.> <.@%:) ])


-- 
Raul


More information about the Programming mailing list