3 ms·
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
by dahart 10y ago
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 http://ideone.com/WFv4f
- kwk236 10y agoThat's just beautiful. I'll reference that.
- in9 10y agowouldnt 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/generators.html http://numba.pydata.org/numba-doc/0.18.1/developer/generator...