Questions tagged [hamming-numbers]

Hamming Numbers are numbers whose only prime factors are 2, 3 and 5. They are named after Richard Hamming but became famous (or notorious) after Edsger Dijkstra posed the question of how to efficiently enumerate them in numeric order.

Hamming Numbers (a.k.a. regular numbers) are numbers whose only prime factors are 2, 3 and 5. They are named after Richard Hamming but became famous (or notorious) after Edsger Dijkstra posed the question of how to efficiently enumerate them in numeric order. They are a particular case of more general smooth numbers.

31 questions
170
votes
21 answers

Tricky Google interview question

A friend of mine is interviewing for a job. One of the interview questions got me thinking, just wanted some feedback. There are 2 non-negative integers: i and j. Given the following equation, find an (optimal) solution to iterate over i and j in…
Chris Eberle
  • 44,989
  • 12
  • 77
  • 112
44
votes
13 answers

nᵗʰ ugly number

Numbers whose only prime factors are 2, 3, or 5 are called ugly numbers. Example: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... 1 can be considered as 2^0. I am working on finding nth ugly number. Note that these numbers are extremely sparsely…
Anil Katti
  • 1,305
  • 1
  • 14
  • 26
23
votes
9 answers

Find the Kth least number for expression (2^x)*(3^y)*(5^z)

In the expression 2x * 3y * 5z The x, y and z can take non negative integer value (>=0). So the function would generate a series of number 1,2,3,4,5,6,8,9,10,12,15,16.... I have a brute force solution. I would basically iterate in a loop…
deeKay
  • 277
  • 3
  • 9
15
votes
4 answers

how to generate numbers given their prime factors, but with unknown exponents?

Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y *…
Bakuriu
  • 85,459
  • 18
  • 168
  • 202
12
votes
4 answers

Generating integers in ascending order using a set of prime numbers

I have a set of prime numbers and I have to generate integers using only those prime factors in increasing order. For example, if the set is p = {2, 5} then my integers should be 1, 2, 4, 5, 8, 10, 16, 20, 25, … Is there any efficient algorithm to…
nims
  • 3,381
  • 1
  • 21
  • 27
11
votes
8 answers

Find the smallest regular number that is not less than N

Regular numbers are numbers that evenly divide powers of 60. As an example, 602 = 3600 = 48 × 75, so both 48 and 75 are divisors of a power of 60. Thus, they are also regular numbers. This is an extension of rounding up to the next power of two. I…
finnw
  • 45,253
  • 22
  • 134
  • 212
7
votes
1 answer

Hamming numbers for O(N) speed and O(1) memory

Disclaimer: there are many questions about it, but I didn't find any with requirement of constant memory. Hamming numbers is a numbers 2^i*3^j*5^k, where i, j, k are natural numbers. Is there a possibility to generate Nth Hamming number with O(N)…
vladon
  • 7,412
  • 1
  • 35
  • 75
7
votes
3 answers

Performance of seq vs Lazy> in F#

There is a well known solution for generating an infinite stream of Hamming numbers (i.e. all positive integers n where n = 2^i * 3^j * 5^k). I have implemented this in two different ways in F#. The first method uses seq. The solution is…
Fysx
  • 695
  • 1
  • 5
  • 11
6
votes
3 answers

New state of the art in unlimited generation of Hamming sequence

(this is exciting!) I know, the subject matter is well known. The state of the art (in Haskell as well as other languages) for efficient generation of unbounded increasing sequence of Hamming numbers, without duplicates and without omissions, has…
Will Ness
  • 62,652
  • 8
  • 86
  • 167
4
votes
2 answers

Hamming numbers and double precision

I was playing around with generating Hamming numbers in Haskell, trying to improve on the obvious (pardon the naming of the functions) mergeUniq :: Ord a => [a] -> [a] -> [a] mergeUniq (x:xs) (y:ys) = case x `compare` y of …
0xd34df00d
  • 1,364
  • 1
  • 5
  • 17
4
votes
6 answers

How do you find the list of all numbers that are multiples of only powers of 2, 3, and 5?

I am trying to generate a list of all multiples which can be represented by the form , where a, b, and c are whole numbers. I tried the following, [ a * b * c | a <- map (2^) [0..], b <- map (3^) [0..], c <- map (5^) [0..] ] but it only lists…
robbie
  • 1,075
  • 1
  • 10
  • 18
4
votes
0 answers

Vivaldi's number

A Vivaldi's number is a number that can be factored by only 2, 3 and 5 ( V = 2^a * 3^b * 5^c, a, b, c = 0,1,...; also known as Hamming number). The task is to find the Nth Vivaldi number. The algorithm isn't too bad for small inputs, but N ranges…
3
votes
2 answers

Trouble understanding / visualising SICP streams Hamming numbers program

I'm basically stuck at excercise 3.56 in SICP. The problem goes like this: Exercise 3.56. A famous problem, first raised by R. Hamming, is to enumerate, in ascending order with no repetitions, all positive integers with no prime factors other than…
ashishmax31
  • 101
  • 2
  • 9
3
votes
1 answer

Hamming numbers by intervals

Here's a somewhat different approach to generating the sequence of Hamming numbers (aka regular numbers, 5-smooth numbers) based on the interval from one number in the sequence to the next. Here's an example plot of said intervals: So there is a…
Joe Knapp
  • 302
  • 2
  • 9
3
votes
1 answer

Hamming number using custom functions instead of prime

Hamming Problem is a famous problem which basically generates all integers which prime factors are {2,3,5} only. (And it can be extended to any set of prime factors I think) To find the n-th Hamming number, there is a clever O(N) constructing…
shole
  • 3,873
  • 1
  • 22
  • 60
1
2 3