Hamming numbers are numbers that do not have any simple factors greater than 5. Ie they have the form 2 ^ i * 3 ^ j * 5 ^ k. The first 20 of them:
[1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36]
500,000th:
1962938367679548095642112423564462631020433036610484123229980468750
The program that printed the 500,000th (after a brief moment of calculation):
merge xxs@ (x:xs) yys@ (y:ys) = case (x`compare`y) of LT -> x:merge xs yys EQ -> x:merge xs ys GT -> y:merge xxs ys hamming = 1 : m 2 `merge` m 3 `merge` m 5 where mk = map (k *) hamming main = print (hamming !! 499999)
Longer than 5 lines of code you like. Of course, it can be a game of golf, but I would prefer to write it naturally and see how many lines you need to calculate this number in any other language with a reasonable lead time.
source share