hamming-numbers

Hamming numbers and double precision

可紊 提交于 2020-05-15 02:09:43
问题 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 EQ -> x : mergeUniq xs ys LT -> x : mergeUniq xs (y:ys) GT -> y : mergeUniq (x:xs) ys powers :: [Integer] powers = 1 : expand 2 `mergeUniq` expand 3 `mergeUniq` expand 5 where expand factor = (factor *) <$> powers I noticed that I can avoid the (slower) arbitrary precision

Hamming numbers and double precision

≯℡__Kan透↙ 提交于 2020-05-15 02:09:07
问题 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 EQ -> x : mergeUniq xs ys LT -> x : mergeUniq xs (y:ys) GT -> y : mergeUniq (x:xs) ys powers :: [Integer] powers = 1 : expand 2 `mergeUniq` expand 3 `mergeUniq` expand 5 where expand factor = (factor *) <$> powers I noticed that I can avoid the (slower) arbitrary precision

Hamming numbers and double precision

老子叫甜甜 提交于 2020-05-15 02:08:07
问题 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 EQ -> x : mergeUniq xs ys LT -> x : mergeUniq xs (y:ys) GT -> y : mergeUniq (x:xs) ys powers :: [Integer] powers = 1 : expand 2 `mergeUniq` expand 3 `mergeUniq` expand 5 where expand factor = (factor *) <$> powers I noticed that I can avoid the (slower) arbitrary precision

Trouble understanding / visualising SICP streams Hamming numbers program

て烟熏妆下的殇ゞ 提交于 2020-02-03 20:54:27
问题 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 2, 3, or 5. One obvious way to do this is to simply test each integer in turn to see whether it has any factors other than 2, 3, and 5. But this is very inefficient, since, as the integers get larger, fewer and fewer of them fit the requirement. As

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

别等时光非礼了梦想. 提交于 2020-01-03 16:51:20
问题 This question already has answers here : Generating integers in ascending order using a set of prime numbers (4 answers) Closed last year . 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 powers of 5 and never goes on to 2 or 3. Edit: My apologies, it seems that I did not clarify the question enough.

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

点点圈 提交于 2019-12-31 02:54:44
问题 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) ) ) print(numbers()) 回答1: Because I just had some time, you could have a look at this. Might not be the perfect solution but should be a good starting point for a beginner. Check out the books in the info tab to get into the syntax etc. (defun divisible-by (n m) "Returns T if N

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

若如初见. 提交于 2019-12-24 08:18:29
问题 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. Does anyone know a nice algorithm for this? EDIT to clarify: Each factor in the input set may be used any number of times. If the input were {2,3,5,7} the output would be {2,3,4,5,6,7,8,9,10,12,14,15,16,18,...}. The algorithm can stop as soon as it

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

六眼飞鱼酱① 提交于 2019-12-20 17:57:06
问题 This question already has answers here : Closed 8 years ago . 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 * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

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

╄→гoц情女王★ 提交于 2019-12-20 17:57:04
问题 This question already has answers here : Closed 8 years ago . 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 * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

Find the smallest regular number that is not less than N

喜欢而已 提交于 2019-12-18 23:13:33
问题 Regular numbers are numbers that evenly divide powers of 60. As an example, 60 2 = 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 have an integer value N which may contain large prime factors and I want to round it up to a number composed of only small prime factors (2, 3 and 5) Examples: f(18) == 18 == 2 1 * 3 2 f(19) == 20 == 2 2 * 5 1 f(257) == 270 == 2 1 * 3 3 * 5 1 What