![]() |
|
|
#1805 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Code:
longmultiply(a,b)= c=eval(Vec(Str(a)));d=eval(Vec(Str(b)));carry=0;answer=vector(length(d)+length(c));forstep(x=#d,1,[-1],forstepn=((c[y]*d[x])+carry)%10;answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);carry=floor((c[y]*d[x])/10)));forstep(w=#answer,1,-1,if(w>1,answer[w-1]=answer[w-1]+floor(answer[w]/10));answer[w]=answer[w]%10;if(w<#answer,answer[w+1]=answer[w])) Last fiddled with by science_man_88 on 2010-11-29 at 21:41 |
|
|
|
|
|
#1806 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Code:
longmultiply(a,b)= c=eval(Vec(Str(a)));d=eval(Vec(Str(b)));carry=0;answer=vector(length(d)+length(c));forstep(x=#d,1,[-1],forstep(y=#c,1,[-1],n=((c[y]*d[x])+carry)%10;answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);carry=floor((c[y]*d[x])/10)));forstep(w=#answer,1,-1,if(w>1,answer[w-1]=answer[w-1]+floor(answer[w]/10));answer[w]=answer[w]%10;if(w<#answer,answer[w+1]=answer[w])) |
|
|
|
|
|
#1807 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
add
Code:
;answer[2]=answer[1]%10;answer[1]=floor(answer[1]/10);answer |
|
|
|
|
|
#1808 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
Code:
longmultiply(a,b)= c=eval(Vec(Str(a)));d=eval(Vec(Str(b)));carry=0;answer=vector(length(d)+length(c));forstep(x=#d,1,[-1],forstep(y=#c,1,[-1],n=((c[y]*d[x])+carry)%10;answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);carry=floor((c[y]*d[x])/10)));forstep(w=#answer,1,-1,if(w>1,answer[w-1]=answer[w-1]+floor(answer[w]/10));answer[w]=answer[w]%10;if(w<#answer,answer[w+1]=answer[w]));answer[2]=answer[1]%10;answer[1]=floor(answer[1]/10);answer found a flaw in my add on. without the addon lower ones work with it low ones don't. But for higher ones it messes it up the other way round I think. 4now I've got 33*33 not working man I suck at this. Last fiddled with by science_man_88 on 2010-11-29 at 23:10 |
|
|
|
|
|
|
#1809 |
|
"Forget I exist"
Jul 2009
Dumbassville
838410 Posts |
Code:
longmultiply(a,b)= c=eval(Vec(Str(a)));d=eval(Vec(Str(b)));carry=0;answer=vector(length(d)+length(c));forstep(x=#d,1,[-1],forstep(y=#c,1,[-1],n=((c[y]*d[x])+carry)%10;answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);carry=floor((c[y]*d[x])/10)));forstep(w=#answer,2,-1,answer[w-1]=answer[w-1]+floor(answer[w]/10);answer[w]=answer[w]%10;if(w<#answer,answer[w+1]=answer[w]));answer[2]=answer[1]%10;answer[1]=floor(answer[1]/10);answer Last fiddled with by science_man_88 on 2010-11-29 at 23:29 |
|
|
|
|
|
#1810 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
Code:
*** bug in PARI/GP (Segmentation Fault), please report |
|
|
|
|
|
#1811 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
if(answer==eval(Vec(Str(a*b))),print(answer)) Code:
[1, 0, 0, 1] [1, 0, 1, 2] [1, 0, 2, 3] [1, 0, 3, 4] [1, 0, 4, 5] [1, 0, 5, 6] [1, 0, 6, 7] [1, 0, 7, 8] [1, 0, 8, 9] [1, 0, 0, 8] [1, 0, 2, 0] [1, 0, 3, 2] [1, 0, 4, 4] [1, 0, 5, 6] [1, 0, 0, 1] [1, 0, 0, 8] [1, 0, 2, 2] [1, 0, 3, 6] [1, 0, 5, 0] [1, 0, 6, 4] [1, 0, 7, 8] [1, 0, 0, 8] [1, 0, 2, 4] [1, 0, 4, 0] [1, 0, 5, 6] [1, 0, 0, 7] [1, 0, 2, 6] [1, 0, 4, 5] [1, 0, 1, 2] [1, 0, 0, 8] [1, 0, 3, 2] [1, 0, 5, 6] [1, 0, 2, 3] [1, 0, 2, 4] [1, 0, 5, 6] [1, 0, 2, 3] [1, 0, 5, 6] [1, 0, 8, 9] [1, 0, 1, 2] [1, 0, 3, 4] [1, 0, 0, 8] [1, 0, 5, 6] [1, 0, 2, 9] [1, 0, 7, 8] [1, 0, 0, 1] [1, 0, 1, 2] [1, 0, 2, 3] [1, 0, 3, 4] [1, 0, 4, 5] [1, 0, 5, 6] [1, 0, 6, 7] [1, 0, 7, 8] [1, 0, 8, 9] Code:
for(x=1,100,for(y=1,100,longmultiply(x,y))) |
|
|
|
|
|
|
#1812 |
|
Aug 2006
3·1,993 Posts |
First of all, your code seems to be nearly there -- it works in many cases. Some of the cases where it doesn't work are as simple as having an initial 0 -- in those cases you can just replace the final
Code:
;answer Code:
;if(answer[1],answer,vecextract(answer,2^#answer-2)) I'm not sure what the problem is in the other case; I've avoided looking at your code since it's not formatted. But keep looking at the cases that it fails at -- why those and not others? What's going wrong there? |
|
|
|
|
|
#1813 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
longmultiply(a,b)= {
c=eval(Vec(Str(a)));
d=eval(Vec(Str(b)));
carry=0;
answer=vector(length(d)+length(c));
forstep(x=#d,1,[-1],
forstep(y=#c,1,[-1],
n=((c[y]*d[x])+carry)%10;
answer[#answer-((#d-x+1)+(#c-y+1)-1)]=(answer[#answer-((#d-x+1)+(#c-y+1)-1)]+n);
carry=floor((c[y]*d[x])/10)));
forstep(w=#answer,2,-1,
answer[w-1]=answer[w-1]+floor(answer[w]/10);
answer[w]=answer[w]%10;
if(w<#answer,answer[w+1]=answer[w]));
answer[2]=answer[1]%10;
answer[1]=floor(answer[1]/10);
answer
}
Last fiddled with by science_man_88 on 2010-11-30 at 01:43 |
|
|
|
|
|
|
#1814 |
|
Aug 2006
3×1,993 Posts |
A little. Here's how I'd format it:
Code:
longmultiply(a,b)= {
my(c=eval(Vec(Str(a))),d=eval(Vec(Str(b))),carry=0,answer=vector(#c+#d));
forstep(x=#d,1,[-1],
forstep(y=#c,1,[-1],
n=((c[y]*d[x])+carry)%10;
answer[#answer-((#d-x+1)+(#c-y+1)-1)] += n;
carry=(c[y]*d[x])\10
)
);
forstep(w=#answer,2,-1,
answer[w-1] += answer[w]\10;
answer[w]=answer[w]%10;
if(w<#answer,answer[w+1]=answer[w])
);
answer[2]=answer[1]%10;
answer[1]=answer[1]\10;
answer
};
Last fiddled with by CRGreathouse on 2010-11-30 at 01:44 |
|
|
|
|
|
#1815 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Last fiddled with by science_man_88 on 2010-11-30 at 01:51 |
|
|
|
|
![]() |
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 |