Bill Allombert on Sun, 19 Dec 2021 15:58:34 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: factorint_as_string()


On Sun, Dec 19, 2021 at 03:24:15PM +0100, Ruud H.G. van Tol wrote:
> 
> sf() = my(v=Vec(factorint(n)~)); if(!#v, v=Vec([1;1])); for(i=1, #v,
> v[i]=if(v[i][2]>1, strjoin(v[i],"^"), v[i][1])); strjoin(["(", strjoin(v," *
> "), ")"])

Hello Ruud, thanks for your code!

You forgot to list the argument name (n) in sf(n)

You can use Str instead of the second strjoin:

sf(n) =
{
   my(v=Vec(factorint(n)~)); 
   if(!#v, v=Vec([1;1])); 
   for(i=1, #v,
     v[i]=if(v[i][2]>1, strjoin(v[i],"^"), v[i][1])); 
   Str("(", strjoin(v," * "), ")")
}

Cheers,
Bill