![]() |
[QUOTE=science_man_88;240214]wonder how fast each is.
tested both with the equivalent of 36^577-1 and they came up equal.[/QUOTE] I've tested both variants with (on older system): yours: for(x=1,100000,convert(12345678901234567890,10,16)) done in 19.6 secs mine: for(x=1,100000,convert1("12345678901234567890",10,16)) done in 10.5 secs The main difference is: You're using the power function and I only the multiplication: power: a= x1*b^e1 + x2*b^e2 + x3*b^e3 + .... multiplication: a= ((x1*b + x2)*b + x3 ... |
[QUOTE=kar_bon;240255]I've tested both variants with (on older system):
yours: for(x=1,100000,convert(12345678901234567890,10,16)) done in 19.6 secs mine: for(x=1,100000,convert1("12345678901234567890",10,16)) done in 10.5 secs The main difference is: You're using the power function and I only the multiplication: power: a= x1*b^e1 + x2*b^e2 + x3*b^e3 + .... multiplication: a= ((x1*b + x2)*b + x3 ...[/QUOTE] I knew you'd be better than me in like 2 seconds lol. |
No big deal, he knew Horner form and you didn't.
|
[QUOTE=CRGreathouse;240286]No big deal, he knew Horner form and you didn't.[/QUOTE]
he should put his up, yeah I had no power this morning but it's back up now I'm kinda worried my mom supposedly had hypercapnia last night and they think codeine ( methyl-morphine) may have helped it unsurprising with morphine allergies in the family history. I know more terms than my sisters so I can describe it but I haven't gone in to see her yet. I was told to a few times I'm not sure if I have something, They think the flu shot may have triggered her so hopefully I don't do the same. they haven't given water, I think it's from the fact that unless they give a lot they acidify the blood by production of carbonic acid. |
I think I found something interesting to talk about with the lucaslehmer() axn came up with. Mind if I see what you think ?
|
Go for it.
|
[QUOTE=CRGreathouse;240370]Go for it.[/QUOTE]
if you replace 0 with s and do: [CODE]for(x=1,100,print(lucaslehmer2(x)%x","x))[/CODE] you get many answers printed but: [CODE]for(x=1,100,print(lucaslehmer2(x)%11","x))[/CODE] gets you only 2 results as far as I see. |
never mind I see a pattern forming but I bet it's well known.
|
Here are some string maipulation functions, because I missed them much:
- String to upper case - String to lower case - Left string - Right string - Mid string Functions like Find or Replace are therefore possible, too. More suggestions: - StrFlip: lower to upper and upper to lower in one string - StrCap: only first character of string/word capitalize - StrTrim: delete spaces from beginning/end of string I think StrReverse or CheckPalindrome were done, right? [code] addhelp(StrToUp, "StrToUp(str): Convert a string str in upper case."); StrToUp(str)={ my(sup=Vecsmall(str),s=""); for(n=1,#sup, if(sup[n]>=97 && sup[n]<=122, s=concat(s,Strchr(sup[n]=sup[n]-32)), s=concat(s,Strchr(sup[n]))) ); s }; addhelp(StrToLow, "StrToLow(str): Convert a string str in lower case."); StrToLow(str)={ my(sup=Vecsmall(str),s=""); for(n=1,#sup, if(sup[n]>=65 && sup[n]<=90, s=concat(s,Strchr(sup[n]=sup[n]+32)), s=concat(s,Strchr(sup[n]))) ); s }; addhelp(StrLeft, "StrLeft(str,n): Gives back n characters from left of string str."); StrLeft(str,n)={ my(strh=Vecsmall(str),s=""); if(n<1, return(s)); \\ n too small: return empty string if(n>=#strh, return(str)); \\ n to big: return str for(x=1,n, s=concat(s,Strchr(strh[x])) ); s }; addhelp(StrRight, "StrRight(str,n): Gives back n characters from right of string str."); StrRight(str,n)={ my(strh=Vecsmall(str),s=""); if(n<1, return(s)); \\ n too small: return empty if(n>#strh, return(str)); \\ n too big: return str for(x=#strh-n+1,#strh, s=concat(s,Strchr(strh[x])) ); s }; addhelp(StrMid, "StrMid(str,n,m): Gives back m characters from position n of string str."); StrMid(str,n,m)={ my(strh=Vecsmall(str),s=""); if(n<1, n=1); \\ n too small: set n=start of string if(n>#strh, return(s)); \\ n too big: return empty string if(n+m>#strh, m=#strh-n+1); \\ m too big: set m maximum length available for(x=n,n+m-1, s=concat(s,Strchr(strh[x])) ); s }; [/code] Notes: - The expression "sup[n]=sup[n]+32" won't work with "sup[n]+=32" ! - Typing in characters like German Umlaute are not allowed/not doable in PARI! |
[QUOTE=kar_bon;240412]
I think StrReverse or CheckPalindrome were done, right? [/QUOTE] So is FaR lol |
[QUOTE=kar_bon;240412]- The expression "sup[n]=sup[n]+32" won't work with "sup[n]+=32" ![/QUOTE]
It should... [CODE]> v=vector(3,n,n);v[2]+=10;v %1 = [1, 12, 3] > v=vectorsmall(3,n,n);v[2]+=10;v %2 = Vecsmall([1, 12, 3])[/CODE] [QUOTE=kar_bon;240412]- Typing in characters like German Umlaute are not allowed/not doable in PARI![/QUOTE] Right, it uses C strings rather than Unicode. A person who cared should be able to hack together a solution with enough care, but since I avoid Pari for string processing I haven't though about it much. (I have run into it, though, like when I mention French or German authors in addhelp() lines and can't use accents in their names.) |
| All times are UTC. The time now is 23:06. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.