Follow

Okay, here is a fun one. We've all seen Fibonacci sequences. But they are all played out. Let's look at a different sequence. They are called Hamming Numbers after Richard Hamming, who proposed the problem of finding computer algorithms for generating these numbers in ascending order.

For number H is equal to 2**i * 3**j * 2**k where i,k,k are all non negative.

For example
2**0 * 3**0 * 5**0 = 1
2**1 * 3**0 * 5**0 = 2
2**0 * 3**1 * 5**0 = 3
2**2 * 3**0 * 5**0 = 4
2**0 * 3**0 * 5**1 = 5
2**2 * 3**1 * 5**0 = 6
2**3 * 3**0 * 5**0 = 8

So hopefully that explains what the sequence looks like. Your challenge, if you choose to accept it is to generate the first 25 of them. An arbitrary nth one such as 1700th. And given a number X determine if it is or is not a valid hamming number.

Here is the wiki article on them:

en.wikipedia.org/wiki/Regular_

Python Solution: Not the best, but the best I could come up with since I already saw someone else's solution and didn't want to just copy it :( 

Show thread

Python Solution: Not the best, but the best I could come up with since I already saw someone else's solution and didn't want to just copy it :( 

Never Mind. That doesn't work.

Show thread

Python Solution: Not the best, but the best I could come up with since I already saw someone else's solution and didn't want to just copy it :( 

Works now, but more like the code I didn't want to copy :)

Show thread
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.