Jump to content

Hamming numbers: Difference between revisions

Line 645:
===Alternate version using "Cyclic Iterators"===
The original author is Raymond Hettinger and the code was first published [http://code.activestate.com/recipes/576961/ here] under the MIT license. This implementation is quite memory efficient.
<lang python>from itertools import tee, chain, groupby, islice
from heapq import merge
 
Line 669:
output = no_repeats(combined) # eliminate duplicates
 
return result</lang>
 
print list(islice(raymonds_hamming(), 20))
print islice(raymonds_hamming(), 1689, 1690).next()
print islice(raymonds_hamming(), 999999, 1000000).next()</lang>
 
Results are the same as before.
 
===Alternate version from the Java version===
This is the fastest of the Python implementations, it uses a lot of memory.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.