def hamming(n):
    """Returns the nth hamming number"""
    hamming = {1}
    x = 1
    while len(hamming) <= n * 3.5:
        new_hamming = {1}
        for i in hamming:
            new_hamming.add(i * 2)
            new_hamming.add(i * 3)
            new_hamming.add(i * 5)
        # merge new number into hamming set
        hamming = hamming.union(new_hamming)
    hamming = sorted(list(hamming))
    return hamming[n - 1]