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
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
  • 3,746
  • 9
  • 47
  • 82
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
  • 961
  • 5
  • 15
  • 32
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

Finding Hamming Numbers - not code or distance

I'm currently learning C++. I am looking for Hamming numbers (numbers whose prime divisors are less or equal to 5). When I input a number n, the program should output the n-th Hamming number. Following numbers are input, and output: 1 2 3 4 5 6 7…
1
vote
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
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
  • 125
  • 1
  • 7
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,418
  • 9
  • 64
  • 98
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,418
  • 9
  • 64
  • 98
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

How to determine if given number is Hamming number by combining two functions in JavaScript?

The goal is to determine if a number is Hamming number?! As we know Hamming number is a number that contains only 2, 3 and 5 as factors. That means that a number must not contain any prime number greater than 5! So I created a function isPrimeNumber…
Ivan Vrzogic
  • 125
  • 1
  • 7
-1
votes
3 answers

How can I convert hamming number code in a while or for loop python

def is_hamming_numbers(x): if x == 1: return 1 if x % 2 == 0: return is_hamming_numbers(x/2) if x % 3 == 0: return is_hamming_numbers(x/3) if x % 5 == 0: return is_hamming_numbers(x/5) return 0 …