On Mon, Aug 9, 2010 at 3:59 PM, Emil Chacko wrote:
> This implementation is really good.It's really fast compared to the initial
> one I posted but i didn't understand much about this memoize.I asked one of
> my friend he told it's python decorators.Can anyone please explain what the
> function m
This implementation is really good.It's really fast compared to the initial
one I posted but i didn't understand much about this memoize.I asked one of
my friend he told it's python decorators.Can anyone please explain what the
function memoize does.
>
> > Readability counts. Here is my attempt.
On Fri, Aug 6, 2010 at 8:56 PM, Anand Chitipothu wrote:
> Readability counts. Here is my attempt.
>
> def memoize(f):
>cache = {}
>def g(a):
>if a not in cache:
>cache[a] = f(a)
>return cache[a]
>return g
>
> @memoize
> def solve(n):
>if n == 1:
>
Readability counts. Here is my attempt.
def memoize(f):
cache = {}
def g(a):
if a not in cache:
cache[a] = f(a)
return cache[a]
return g
@memoize
def solve(n):
if n == 1:
return 1
elif n%2 == 0:
return 1 + solve(n/2)
else:
>
>
>
> Your python code as is clocked about 72 seconds on my notebook. The
> following came in at about 4.6 seconds (just has a small trick of reusing
> earlier results)
>
> import time
> start =time.time()
> longest = None
> longest_elements = 0
> solved = {}
> for val in xrange(1,100) :
>
On Fri, Aug 6, 2010 at 3:00 AM, Dhananjay Nene wrote:
> On Fri, Jul 23, 2010 at 1:26 PM, Emil Chacko wrote:
>
> > Below given is solution to a puzzle(
> > http://projecteuler.net/index.php?section=problems&id=14) in python and
> c
> >
> > Python:
> >
> > import time
> > startT=time.time()
> > max
On Fri, Jul 23, 2010 at 1:26 PM, Emil Chacko wrote:
> Below given is solution to a puzzle(
> http://projecteuler.net/index.php?section=problems&id=14) in python and c
>
> Python:
>
> import time
> startT=time.time()
> maxlen=0
> longest=0
> for i in xrange(1,100):
> last=i
> cnt=0
> while(
IronPython (on .NET) and Jython (on Java) capable to use the multi core
processors in your PC and they works faster than the CPython.
Beware that not all the python packages shall be working with IronPython or
Jython.
Regards,
Krish,
http://www.stacked.in
___
Try "extending" with python.
-V-
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers
On Fri, Jul 23, 2010 at 1:51 PM, Baishampayan Ghose wrote:
> Emil,
>
> > Below given is solution to a puzzle(
> > http://projecteuler.net/index.php?section=problems&id=14) in python and
> c
> >
> > Python:
> >
> > import time
> > startT=time.time()
> > maxlen=0
> > longest=0
> > for i in xrange(1,
BTW the problem is known as 3n+1 problem and you can find it in ACM archives
too.
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36
___
BangPypers mailing list
BangPypers@python.org
http://mail.p
Emil,
> Below given is solution to a puzzle(
> http://projecteuler.net/index.php?section=problems&id=14) in python and c
>
> Python:
>
> import time
> startT=time.time()
> maxlen=0
> longest=0
> for i in xrange(1,100):
> last=i
> cnt=0
> while(last <> 1):
> cnt=cnt+1
> if(last%2==0):
>
Below given is solution to a puzzle(
http://projecteuler.net/index.php?section=problems&id=14) in python and c
Python:
import time
startT=time.time()
maxlen=0
longest=0
for i in xrange(1,100):
last=i
cnt=0
while(last <> 1):
cnt=cnt+1
if(last%2==0):
last=last/2
else:
last=3*last
13 matches
Mail list logo