Skip to main content
Commonmark migration
Source Link

APL (Dyalog Extended), 28 bytes

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵}

Try it online!

###How:

How:

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵} ⍝ Monadic function, takes an argument ⍵
       ⍭⍵                     ⍝ Prime factors and exponents of ⍵
     `↓                        ⍝ split the resulting matrix in 2 vectors
 f p←                          ⍝ assign the factors to f and the powers to p
         ⋄                     ⍝ then
                          ⍳⍵   ⍝ range [1..⍵]
                        1⍭     ⍝ primality check for each element in the vector
                       ⍸        ⍝ where; returns the indices of truthy values
                     f⍷         ⍝ find the factors; returns a boolean vector
                   ∨/           ⍝ logical OR reduction
                  ∧             ⍝ logical AND
           (   ∪p)              ⍝ unique members of the powers
              ≢                 ⍝ tally; returns the number of elements in the vector
            1=                  ⍝ check if there's only one element

APL (Dyalog Extended), 28 bytes

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵}

Try it online!

###How:

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵} ⍝ Monadic function, takes an argument ⍵
       ⍭⍵                     ⍝ Prime factors and exponents of ⍵
     `↓                        ⍝ split the resulting matrix in 2 vectors
 f p←                          ⍝ assign the factors to f and the powers to p
         ⋄                     ⍝ then
                          ⍳⍵   ⍝ range [1..⍵]
                        1⍭     ⍝ primality check for each element in the vector
                       ⍸        ⍝ where; returns the indices of truthy values
                     f⍷         ⍝ find the factors; returns a boolean vector
                   ∨/           ⍝ logical OR reduction
                  ∧             ⍝ logical AND
           (   ∪p)              ⍝ unique members of the powers
              ≢                 ⍝ tally; returns the number of elements in the vector
            1=                  ⍝ check if there's only one element

APL (Dyalog Extended), 28 bytes

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵}

Try it online!

How:

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵} ⍝ Monadic function, takes an argument ⍵
       ⍭⍵                     ⍝ Prime factors and exponents of ⍵
     `↓                        ⍝ split the resulting matrix in 2 vectors
 f p←                          ⍝ assign the factors to f and the powers to p
         ⋄                     ⍝ then
                          ⍳⍵   ⍝ range [1..⍵]
                        1⍭     ⍝ primality check for each element in the vector
                       ⍸        ⍝ where; returns the indices of truthy values
                     f⍷         ⍝ find the factors; returns a boolean vector
                   ∨/           ⍝ logical OR reduction
                  ∧             ⍝ logical AND
           (   ∪p)              ⍝ unique members of the powers
              ≢                 ⍝ tally; returns the number of elements in the vector
            1=                  ⍝ check if there's only one element
Source Link
J. Sallé
  • 3.5k
  • 9
  • 24

APL (Dyalog Extended), 28 bytes

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵}

Try it online!

###How:

{f p←`↓⍭⍵⋄(1=≢∪p)∧∨/f⍷⍸1⍭⍳⍵} ⍝ Monadic function, takes an argument ⍵
       ⍭⍵                     ⍝ Prime factors and exponents of ⍵
     `↓                        ⍝ split the resulting matrix in 2 vectors
 f p←                          ⍝ assign the factors to f and the powers to p
         ⋄                     ⍝ then
                          ⍳⍵   ⍝ range [1..⍵]
                        1⍭     ⍝ primality check for each element in the vector
                       ⍸        ⍝ where; returns the indices of truthy values
                     f⍷         ⍝ find the factors; returns a boolean vector
                   ∨/           ⍝ logical OR reduction
                  ∧             ⍝ logical AND
           (   ∪p)              ⍝ unique members of the powers
              ≢                 ⍝ tally; returns the number of elements in the vector
            1=                  ⍝ check if there's only one element