News for hackers. Stuff that matters.
Re:Minimal examples of data structures and algorithms in Python by dahart on Monday April 24, 2017 @08:24PM (#14189744)
I quite like how minimal these are, very nice for understanding and for quick coding!

With minimal code like this, I'm a little torn between declaring a class with members and using an anonymous data structure. A tree for example can be a tuple in python, and doesn't need to be declared. How big do you let it get before taking the time to declare a class?

Re: primes_sieve_of_eratosthenes.py, after doing more primes problems on Project Euler than I care to admit, I ended up with this pretty minimal sieve. The repo's indexing and .append in the loop slow it down.

    sieve = [True] * n
    for i in xrange(2,int(n**0.5)+1): 
        if sieve[i]: sieve[i*i::i] = [False] * ((n-i*i-1)/(i)+1)
And total tangent but have you guys seen the amazing and extremely memory efficient postponed sieve generator? http://ideone.com/WFv4f
Re:Minimal examples of data structures and algorithms in Python by in9 on Monday April 24, 2017 @10:34PM (#14190309)
wouldnt this version you suggested, along with the postponed sieve generator, be Numba complaint code? From a quick read through, i think so. So then you could achieve, minimal JIT compiled code for your Project Euler problems :D

http://numba.pydata.org/numba-doc/0.18.1/developer/generator...

Re:Minimal examples of data structures and algorithms in Python by kwk236 on Monday April 24, 2017 @08:36PM (#14189809)
That's just beautiful. I'll reference that.