Skip to main content
added 45 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 71 bytes

f=\(n,m=2,l=0)`if`(n%%m,-sort(-c(if(l)l,if(n>1)f(n,m+1))),f(n/m,m,l+1)) 

Attempt This Online!

Recursive function that directly calculates prime exponents, and sorts them on every recursive call (which is unneccessary except for the outermost call, so overflows the stack for large inputs).


R, 7474 67 bytes

\(n,f=\(n,m)if(n>1)`if`(n%%m,f(n,m+1),c(m,f(n/m,m))))-sort(-table(f(n,2))) 

Edit: -7 bytes thanks to pajonk

\(n,`?`=\(n,m)if(n>1)`if`(n%%m,n?m+1,c(m,n/m?m)))-sort(-table(n?2)) 

Attempt This Online!Attempt This Online!

Uses recursive helper function f? to calculate prime factors, and then sorts their exponents a single time (and thus copes with much larger inputs, but at the expense of 3 more bytes of code).

R, 71 bytes

f=\(n,m=2,l=0)`if`(n%%m,-sort(-c(if(l)l,if(n>1)f(n,m+1))),f(n/m,m,l+1)) 

Attempt This Online!

Recursive function that directly calculates prime exponents, and sorts them on every recursive call (which is unneccessary except for the outermost call, so overflows the stack for large inputs).


R, 74 bytes

\(n,f=\(n,m)if(n>1)`if`(n%%m,f(n,m+1),c(m,f(n/m,m))))-sort(-table(f(n,2))) 

Attempt This Online!

Uses recursive helper function f to calculate prime factors, and then sorts their exponents a single time (and thus copes with much larger inputs, but at the expense of 3 more bytes of code).

R, 71 bytes

f=\(n,m=2,l=0)`if`(n%%m,-sort(-c(if(l)l,if(n>1)f(n,m+1))),f(n/m,m,l+1)) 

Attempt This Online!

Recursive function that directly calculates prime exponents, and sorts them on every recursive call (which is unneccessary except for the outermost call, so overflows the stack for large inputs).


R, 74 67 bytes

Edit: -7 bytes thanks to pajonk

\(n,`?`=\(n,m)if(n>1)`if`(n%%m,n?m+1,c(m,n/m?m)))-sort(-table(n?2)) 

Attempt This Online!

Uses recursive helper function ? to calculate prime factors, and then sorts their exponents a single time (and thus copes with much larger inputs, but at the expense of 3 more bytes of code).

Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 71 bytes

f=\(n,m=2,l=0)`if`(n%%m,-sort(-c(if(l)l,if(n>1)f(n,m+1))),f(n/m,m,l+1)) 

Attempt This Online!

Recursive function that directly calculates prime exponents, and sorts them on every recursive call (which is unneccessary except for the outermost call, so overflows the stack for large inputs).


R, 74 bytes

\(n,f=\(n,m)if(n>1)`if`(n%%m,f(n,m+1),c(m,f(n/m,m))))-sort(-table(f(n,2))) 

Attempt This Online!

Uses recursive helper function f to calculate prime factors, and then sorts their exponents a single time (and thus copes with much larger inputs, but at the expense of 3 more bytes of code).