Skip to content

Instantly share code, notes, and snippets.

@SimplGy SimplGy/hamming.go
Created Sep 4, 2016

Embed
What would you like to do?
A beautiful piece of code I didn't write
// https://programmingpraxis.com/2011/08/30/hamming-numbers/
// cosmin said
// October 30, 2012 at 7:14 PM
// Another solution based upon Dijkstra’s paper:
def hammingSeq(N):
h = [1]
i2, i3, i5 = 0, 0, 0
for i in xrange(1, N):
x = min(2*h[i2], 3*h[i3], 5*h[i5])
h.append(x)
if 2*h[i2] <= x: i2 += 1
if 3*h[i3] <= x: i3 += 1
if 5*h[i5] <= x: i5 += 1
return h
print hammingSeq(1000)
@SimplGy

This comment has been minimized.

Copy link
Owner Author

commented Sep 4, 2016

I think 12-14 can just be == instead of <=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.