Den söndag 15 mars 2015 kl. 19:32:02 UTC+1 skrev Joel Goldstick:
> On Sun, Mar 15, 2015 at 2:07 PM,  <jonas.thornv...@gmail.com> wrote:
> > <SCRIPT LANGUAGE="Javascript">
> >
> > function naiveAdd(base,arrOne,arrTwo) {
> > if (arrOne.length>=arrTwo.length) {length=arrOne.length;} else 
> > {length=arrTwo.length;}
> > out="";
> > remainder=0;
> > for (i=0;i<length;i++){
> > one=arrOne[i];
> > two=arrTwo[i];
> > one=parseInt(one);
> > two=parseInt(two);
> > if (isNaN(one)) one = 0;
> > if (isNaN(two)) two = 0;
> > sum=one+two+remainder;
> >
> > if (sum>=base) { sum=sum-base; remainder=1;} else {remainder=0;}
> > out=","+sum+out;
> > }
> > if (remainder==1) out=remainder+out;
> > return out;
> > }
> > base=16;
> > strOne="2,2";
> > strTwo="13,13";
> > arrOne=strOne.split(",");
> > arrTwo=strTwo.split(",");
> > arrOne.reverse();
> > arrTwo.reverse();
> > naiveAdd(base,arrOne,arrTwo);
> > document.write("Sum = ",out,"<BR>");
> > </SCRIPT>
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> I'm guessing less, if your question is whether this code would be
> fewer lines in python.  However, it would be nice if you formatted it
> so that it is readable, and gave a description of what you think the
> code is doing, or should be doing.  Its an odd question in that python
> generally runs on a server and javascript in a browser
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com

It add two postive numbers working in any base you prefer. There is no 
restriction on the size of operands, it dependens upon the memory of your 
computer or string limitations in the implementation of ECMASCRIPT.(If there 
is).

Basicly the function doing addition in Python shell, but you can chose base you 
work in.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to