![]() |
[QUOTE=science_man_88;346974] [CODE]
a=[1,2,3];b=#a;until(#a==1,a[1]=concat(Str(a[1]),Str(a[2]));if(#a==b,a[b-1]=a[b]);a=vector(#a-1,n,a[n]));a=eval(a[1]) [/CODE] [/QUOTE] the correct version is: [CODE]a=[1,3,7,15,31,63];until(#a==1,a[1]=concat(Str(a[1]),Str(a[2]));for(b=3,#a,a[b-1]=a[b]);a=vector(#a-1,n,a[n]));a=eval(a[1])[/CODE] |
Thank you very much, Sir. This will help a lot.
PARI is a great languague for mathematics no doubts, however let's be honest, it's some times so much complicated. For anyone who has the same problem I had, here is the function, only if you may, science_man_88, all credits for you. [CODE] vectoint(a)={ until(#a==1,a[1]=concat(Str(a[1]),Str(a[2]));for(b=3,#a,a[b-1]=a[b]); a=vector(#a-1,n,a[n])); a=eval(a[1]) }; [/CODE] Once again, thank you very much, for solving my problem and for quick reply as well. |
[CODE]vec2int(a)={my(s=""); for(i=1,#a,s=Str(s,a[i])); eval(s)}[/CODE]
|
1 Attachment(s)
Another great help, axn, thank you.
I was doing some test here, axn is a faster, however, both are excellent and helps a lot. [ATTACH]10041[/ATTACH] |
There's an even faster version available if your numbers are only a digit each:
[code]subst(Pol(a), 'x, 10)[/code] |
Awesome, this will help a lot with large palindromics numbers.
I usually compare palindromes making vectors and never knew how I could manipulate the numbers. Edit: One last question, how do I return the position of a specific character from a word? For example 'a = "ABC"' and return "A". PS.: I know PARI isn't the right language for strings, but in the end, it's all about Mathematics. |
[QUOTE=ismillo;347172]One last question, how do I return the position of a specific character from a word?
For example 'a = "ABC"' and return "A". PS.: I know PARI isn't the right language for strings, but in the end, it's all about Mathematics.[/QUOTE] PARI is bad at this. The best method it has to offer is Vec("ABC")[1]. For finding a string, you can try [code]find(source, target)={ source=Vec(source); target=Vec(target); for(i=0,#source-#target, for(j=1,#target, if(target[j]!=source[i+j],next(2)) ); return(i+1) ); -1 };[/code] |
[QUOTE=ismillo;347172]Awesome, this will help a lot with large palindromics numbers.
I usually compare palindromes making vectors and never knew how I could manipulate the numbers.[/QUOTE] I should also mention the commands Vecrev and Polrev, then. [code]subst(Polrev(digits(123)), 'x, 10)[/code] gives 321. |
[QUOTE=CRGreathouse;347187]I should also mention the commands Vecrev and Polrev, then.
[code]subst(Polrev(digits(123)), 'x, 10)[/code] gives 321.[/QUOTE] Nice, I didn't knew I could reverse vector with function from PARI, so I made my own. :D [QUOTE=CRGreathouse;347185]PARI is bad at this. The best method it has to offer is Vec("ABC")[1]. For finding a string, you can try [code]find(source, target)={ source=Vec(source); target=Vec(target); for(i=0,#source-#target, for(j=1,#target, if(target[j]!=source[i+j],next(2)) ); return(i+1) ); -1 };[/code][/QUOTE] This is perfect, I guess. Later I will give it a shot, if I succeed then I notify you guys. |
Well, I'm having an issue with 2 equal letters, I'll keep trying, if can't do it I will try make in C.
:/ |
[QUOTE=ismillo;347250]Well, I'm having an issue with 2 equal letters, I'll keep trying, if can't do it I will try make in C.
:/[/QUOTE] Can you give an example of the input, the expected output, and the actual output? I'll admit that I didn't test my script at all, just typed it up, so bugs are certainly possible. |
| All times are UTC. The time now is 22:37. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.