![]() |
|
|
#2399 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
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]) |
|
|
|
|
|
|
#2400 |
|
Jul 2013
Brazil
100112 Posts |
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])
};
|
|
|
|
|
|
#2401 |
|
Jun 2003
5,087 Posts |
Code:
vec2int(a)={my(s=""); for(i=1,#a,s=Str(s,a[i])); eval(s)}
|
|
|
|
|
|
#2402 |
|
Jul 2013
Brazil
19 Posts |
Another great help, axn, thank you.
I was doing some test here, axn is a faster, however, both are excellent and helps a lot. |
|
|
|
|
|
#2403 |
|
Aug 2006
3×1,993 Posts |
There's an even faster version available if your numbers are only a digit each:
Code:
subst(Pol(a), 'x, 10) |
|
|
|
|
|
#2404 |
|
Jul 2013
Brazil
19 Posts |
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. Last fiddled with by ismillo on 2013-07-24 at 00:23 |
|
|
|
|
|
#2405 | |
|
Aug 2006
3·1,993 Posts |
Quote:
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
};
|
|
|
|
|
|
|
#2406 | |
|
Aug 2006
3·1,993 Posts |
Quote:
Code:
subst(Polrev(digits(123)), 'x, 10) |
|
|
|
|
|
|
#2407 | ||
|
Jul 2013
Brazil
19 Posts |
Quote:
Quote:
Last fiddled with by ismillo on 2013-07-24 at 11:43 |
||
|
|
|
|
|
#2408 |
|
Jul 2013
Brazil
1316 Posts |
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.
:/ Last fiddled with by ismillo on 2013-07-24 at 20:48 |
|
|
|
|
|
#2409 |
|
Aug 2006
3×1,993 Posts |
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.
|
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |