Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87482
| References | <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> |
|---|---|
| Date | 2015-03-15 14:31 -0400 |
| Subject | Re: More or less code in python? |
| From | Joel Goldstick <joel.goldstick@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.399.1426444300.21433.python-list@python.org> (permalink) |
On Sun, Mar 15, 2015 at 2:07 PM, <jonas.thornvall@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 11:07 -0700
Re: More or less code in python? Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-15 14:31 -0400
Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 11:56 -0700
Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:00 -0700
Re: More or less code in python? Paul Rubin <no.email@nospam.invalid> - 2015-03-15 12:01 -0700
Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:03 -0700
Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:09 -0700
Re: More or less code in python? Dave Angel <davea@davea.name> - 2015-03-16 03:32 -0400
Re: More or less code in python? Chris Angelico <rosuav@gmail.com> - 2015-03-16 18:36 +1100
Re: More or less code in python? Dave Angel <davea@davea.name> - 2015-03-16 03:44 -0400
Re: More or less code in python? Peter Otten <__peter__@web.de> - 2015-03-15 20:15 +0100
csiph-web