More or less code in python?
jonas.thornvall at gmail.com
jonas.thornvall at gmail.com
Sun Mar 15 15:00:36 EDT 2015
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.thornvall at 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
I though it would be interesting doing comparissons in timing adding massive digits in different bases. Especially in Python.
More information about the Python-list
mailing list