Guest User

Perfect powers in J

a guest
Mar 14th, 2012
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NB. Perfect powers
  2.  
  3. NB. Integer logs and roots; work for extended precision.
  4. ilog=: <.@^.
  5. iroot=: <.@%:
  6.  
  7. NB. 'x isEvenRoot y' is true if the xth root of y is an integer.
  8. isEvenRoot=: ] = iroot ^ [
  9.  
  10. NB. 'primesTo y' returns the primes up to the first prime >= y.
  11. primesTo=: 3 : 'p: i.>: _1 p: y'
  12.  
  13. NB. Return a list of the prime powers that "factor" y.
  14. perfectPowersOf=: 3 : '(primesTo 2 ilog y) (isEvenRoot # [) y'
  15.  
  16. NB. Just check if that list is longer than 0.
  17. isPerfectPower=: 3 : '0<#perfectPowersOf y'
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×