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, and proposed a solution, of how to efficiently enumerate them in increasing numeric order:

  • 1 is a Hamming number.
  • If n is a Hamming number, then so are 2*n, 3*n, and 5*n.

They are a particular case of more general smooth numbers.

See also .

34 questions
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
  • 4,046
  • 2
  • 29
  • 69
2
votes
1 answer

How to display first N natural numbers, knowing the divisors in Lisp

Display first N natural numbers, the divisors of which are only 2, 3 and 7. I wrote something like that. I am a beginner in Lisp. Thank you! defvar x 1 (defun numbers(n) if(mod x 2 ) (loop for x from 1 to n do(print x) …
2
votes
1 answer

Time Complexity to find first N numbers only divisible by 2, 3 and 5

Problem - What is the complexity to find first N numbers that are only divisible by 2, 3, 5 ? My effort Code - void printFirstNNumbers(int N) { int numbersFound = 0; // loop#1 for(int cnt = 0; ; cnt++) { int currentNumber =…
devsda
  • 4,112
  • 9
  • 50
  • 87
2
votes
2 answers

Hamming numbers in Haskell

I need to define the list of the numbers whose only prime factors are 2, 3 and 5, the Hamming numbers. (I.e. numbers in the form of 2^i * 3^j * 5^k. The sequence starts with 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …) I may do it using the factors…
john stamos
  • 1,054
  • 5
  • 17
  • 36
2
votes
2 answers

Merge of lazy streams (using generators) in Python

I'm playing with functional capacities of Python 3 and I tried to implement classical algorithm for calculating Hamming numbers. That's the numbers which have as prime factors only 2, 3 or 5. First Hamming numbers are 2, 3, 4, 5, 6, 8, 10, 12, 15,…
1
vote
1 answer

there's a problem when dealing with prime factorization

I've done this exercise, it was about finding if a number is "ugly" or not. A number is ugly if it has only 2, 3, or 5 as factors. otherwise, it's not ugly. this is my solution: include #include bool is_prime(unsigned int num)…
1
vote
1 answer

Hamming with lists in Haskell

I want to write a hamming function in Haskell that gets a list as Input. I already have this: merge :: [Integer] -> [Integer] -> [Integer] merge (x:xs)(y:ys) | x == y = x : merge xs ys | x < y = x : merge xs (y:ys) |…
beginner334
1
vote
7 answers

algorithm to find products of a set of primes, in order, greater than x

Consider the finite set {2,3,5,...,n}. I am interested in primes but the question could apply to any set of numbers. I want to find all possible products of these numbers in ascending order, and in particular greater than or equal to some number x.…
1
vote
2 answers

Haskell Hamming numbers, works but shows duplicates

I am trying to generate hamming numbers in haskell, the problem is I get duplicate #'s in my output list and I cannot figure out why exactly. Should I just create a remove duplicates function or am I just missing something simple? Also in the…
user1311286
0
votes
4 answers

How to find if any element within an array is different than 2, 3 and 5 in JavaScript?

The goal is to determine whether a number input is a Hamming number?! Hamming numbers are all numbers that factorized contain just prime numbers 2, 3 and 5. If a number factorized contains any number different than either of 2, 3 and 5 is NOT…
Ivan Vrzogic
  • 157
  • 1
  • 8
0
votes
2 answers

Haskell List comprehensions infinite list problem

I'm trying to learn Haskell and comprehension lists but cannot find solution on this: mylist = [x*y | x <- [1..], y <- [1..]] After my trials the result is something like this mylist = [1,2,3,4,5,...] because in list comprehensions, x takes the…
0
votes
3 answers

Calculating Hamming Sequence in C++ (a sequence of numbers that has only 2, 3, and 5 as dividers)

Possible Duplicate: Generating a sequence using prime numbers 2, 3, and 5 only, and then displaying an nth term (C++) I've been brainstorming over this forever, and I just can't figure this out. I need to solve the following problem: Generate…
B.K.
  • 9,982
  • 10
  • 73
  • 105
0
votes
4 answers

Generating a sequence using prime numbers 2, 3, and 5 only, and then displaying an nth term (C++)

I'm working on a problem that asks to generate a sequence using prime numbers 2, 3, and 5, and then displaying then nth number in the sequence. So, if I ask the program to display the 1000th number, it should display it. I can't be using arrays or…
B.K.
  • 9,982
  • 10
  • 73
  • 105
0
votes
1 answer

Print a list, in ascending order and with no duplicate, of positive integers that have no prime factor other than 2, 3, or 5

This is a programming question on my homework for one of my courses. I haven't programmed in a couple years and I wasn't that great to begin with. I'm currently going through tutorials to get back up to speed, but it will take some time. If you guys…
JessieM
  • 11
  • 3
-1
votes
1 answer

Hamming numbers in python

I came across a question in codewars which asked to find the nth smallest Hamming Number. Basically the number can only have 2, 3, and/or 5 as factors. Below is the code that I made for it. def hamming(n): if n == 1: return 1 elif n…