Fast Hamming sequence generation in HaskellLazy computation of primes in HaskellMultiplication table using a...
Prevent a directory in /tmp from being deleted
N.B. ligature in Latex
Is there a minimum number of transactions in a block?
Japan - Plan around max visa duration
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
Are white and non-white police officers equally likely to kill black suspects?
Are tax years 2016 & 2017 back taxes deductible for tax year 2018?
Is there really no realistic way for a skeleton monster to move around without magic?
A Journey Through Space and Time
What would happen to a modern skyscraper if it rains micro blackholes?
Are there any consumables that function as addictive (psychedelic) drugs?
Schwarzchild Radius of the Universe
Is Social Media Science Fiction?
What would the Romans have called "sorcery"?
Chess with symmetric move-square
Patience, young "Padovan"
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
How old can references or sources in a thesis be?
Is it possible to do 50 km distance without any previous training?
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
How to report a triplet of septets in NMR tabulation?
Can I interfere when another PC is about to be attacked?
How long does it take to type this?
Email Account under attack (really) - anything I can do?
Fast Hamming sequence generation in Haskell
Lazy computation of primes in HaskellMultiplication table using a list comprehensionLongest non-decreasing subsequence, in HaskellBetter or more idiomatic way to apply a sequence of functions in HaskellProject Euler Problem 50 in HaskellCode Generation with Template HaskellPorting Haskell list comprehensions to Standard MLConverting numbers to words in HaskellHaskell Hamming Sequence LogicSubtracting composits from wheel for primes in Haskell
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
I found some months ago that I could generate Hamming multiples of 3 and 5 multiples (3^x & 5^x) in one list comprehension. There are many fewer 3 and 5 Hamming multiples in a Hamming sequence. I did not have to be concerned with duplicate multiples as it is 2 disparate lists.
All I needed to do was add the Hamming 2 multiples.
When I did, it was chaos. Multiples of the 3 and 5 multiples with the 2^x produced clean Hamming numbers but left even more at the end of the list that had missing Hamming numbers between them.
The problem was the Cartesian product of the 2 multiples and the 3&5 multiples.
I had used the 3^x times 5^x’s in another algorithm successfully. I had limited the list with some involved calculation.
Then, I encountered the same problem working with primes. I wanted a list to subtract from a wheel but the list contained much excess. It was another huge Cartesian product of values.
I didn’t know which elements to eliminate from either list and I thought them intermixed.
Then it dawned on me. I tried it with the primes and it worked. Then with the Hamming 2s and it worked.
First I rewrote the 3 & 5 multiples list comprehension with the much simpler logic and way less calculation.
What was the solution? All it is, is using the end value of the generated first list to limit values of subsequent lists. List comprehensions take the first value of the first list and apply it to all values in the second list thus making a list. It is the first list end value that is the limit of each subsequent list. These limited lists do not generate any excess at the end of any list
The prime’s composite list to subtract is top and bottom diagonal to form a rouge triangle. In it x and y are identical. The Hammings lists are bottom, irregular diagonal only. The x and y are different.
My problem, now, is how to specify how many Hammings I want instead of thex in 2^x as the parameter. Is it just practical to use take with some derived value of x (in 2^x) to get the number of Hammings wanted? How can x be derived from specified n number of Hamming wanted? The second thing is how fast is this compared to the fastest Hamming list generators?
Thanks for any help you can offer.
The Hamming functions follow
gnf n f = scanl (*) 1 $ replicate f n
mk35 n = (c-> [m| t<- gnf 3 n, f<- gnf 5 n, m<- [t*f], m<= c]) (2^(n+1))
mkHams n = (c-> sort [m| t<- mk35 n, f<- gnf 2 (n+1), m<- [t*f], m<= c]) (2^(n+1))
last $ mkHams 50
2251799813685248
(0.03 secs, 12,869,000 bytes)
2^51
2251799813685248
4/5/2019
@Will Ness on SO suggested limiting early.
gnf n f| f==2= scanl (*) 1 $ replicate n 2
| f==3= takeWhile (<=2^(n+1))$ scanl (*) 1$ replicate n 3
| f==5= takeWhile (<=2^ n) $ scanl (*) 1$ replicate n 5
Thank @E-Coms for suggesting short circuit limiting very large lists generated.
hams2' n c d = [ takeWhile (<=d) [ m*f| m<- gnf c 2 ]| f<- [a*b| a <-gnf n 3, b<-gnf n 5] ]
hams2 n = sort.concat $ hams2' n (n+1) (2^(n+1))
last $ hams2 100
2535301200456458802993406410752
(0.09 secs, 69,227,792 bytes)
2 ^ 101
2535301200456458802993406410752
haskell
$endgroup$
|
show 8 more comments
$begingroup$
I found some months ago that I could generate Hamming multiples of 3 and 5 multiples (3^x & 5^x) in one list comprehension. There are many fewer 3 and 5 Hamming multiples in a Hamming sequence. I did not have to be concerned with duplicate multiples as it is 2 disparate lists.
All I needed to do was add the Hamming 2 multiples.
When I did, it was chaos. Multiples of the 3 and 5 multiples with the 2^x produced clean Hamming numbers but left even more at the end of the list that had missing Hamming numbers between them.
The problem was the Cartesian product of the 2 multiples and the 3&5 multiples.
I had used the 3^x times 5^x’s in another algorithm successfully. I had limited the list with some involved calculation.
Then, I encountered the same problem working with primes. I wanted a list to subtract from a wheel but the list contained much excess. It was another huge Cartesian product of values.
I didn’t know which elements to eliminate from either list and I thought them intermixed.
Then it dawned on me. I tried it with the primes and it worked. Then with the Hamming 2s and it worked.
First I rewrote the 3 & 5 multiples list comprehension with the much simpler logic and way less calculation.
What was the solution? All it is, is using the end value of the generated first list to limit values of subsequent lists. List comprehensions take the first value of the first list and apply it to all values in the second list thus making a list. It is the first list end value that is the limit of each subsequent list. These limited lists do not generate any excess at the end of any list
The prime’s composite list to subtract is top and bottom diagonal to form a rouge triangle. In it x and y are identical. The Hammings lists are bottom, irregular diagonal only. The x and y are different.
My problem, now, is how to specify how many Hammings I want instead of thex in 2^x as the parameter. Is it just practical to use take with some derived value of x (in 2^x) to get the number of Hammings wanted? How can x be derived from specified n number of Hamming wanted? The second thing is how fast is this compared to the fastest Hamming list generators?
Thanks for any help you can offer.
The Hamming functions follow
gnf n f = scanl (*) 1 $ replicate f n
mk35 n = (c-> [m| t<- gnf 3 n, f<- gnf 5 n, m<- [t*f], m<= c]) (2^(n+1))
mkHams n = (c-> sort [m| t<- mk35 n, f<- gnf 2 (n+1), m<- [t*f], m<= c]) (2^(n+1))
last $ mkHams 50
2251799813685248
(0.03 secs, 12,869,000 bytes)
2^51
2251799813685248
4/5/2019
@Will Ness on SO suggested limiting early.
gnf n f| f==2= scanl (*) 1 $ replicate n 2
| f==3= takeWhile (<=2^(n+1))$ scanl (*) 1$ replicate n 3
| f==5= takeWhile (<=2^ n) $ scanl (*) 1$ replicate n 5
Thank @E-Coms for suggesting short circuit limiting very large lists generated.
hams2' n c d = [ takeWhile (<=d) [ m*f| m<- gnf c 2 ]| f<- [a*b| a <-gnf n 3, b<-gnf n 5] ]
hams2 n = sort.concat $ hams2' n (n+1) (2^(n+1))
last $ hams2 100
2535301200456458802993406410752
(0.09 secs, 69,227,792 bytes)
2 ^ 101
2535301200456458802993406410752
haskell
$endgroup$
1
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
mkHams 50will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values.cThis could be `2^i * 3^j * 5^k
$endgroup$
– fp_mora
Apr 3 at 16:09
1
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
1
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
1
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52
|
show 8 more comments
$begingroup$
I found some months ago that I could generate Hamming multiples of 3 and 5 multiples (3^x & 5^x) in one list comprehension. There are many fewer 3 and 5 Hamming multiples in a Hamming sequence. I did not have to be concerned with duplicate multiples as it is 2 disparate lists.
All I needed to do was add the Hamming 2 multiples.
When I did, it was chaos. Multiples of the 3 and 5 multiples with the 2^x produced clean Hamming numbers but left even more at the end of the list that had missing Hamming numbers between them.
The problem was the Cartesian product of the 2 multiples and the 3&5 multiples.
I had used the 3^x times 5^x’s in another algorithm successfully. I had limited the list with some involved calculation.
Then, I encountered the same problem working with primes. I wanted a list to subtract from a wheel but the list contained much excess. It was another huge Cartesian product of values.
I didn’t know which elements to eliminate from either list and I thought them intermixed.
Then it dawned on me. I tried it with the primes and it worked. Then with the Hamming 2s and it worked.
First I rewrote the 3 & 5 multiples list comprehension with the much simpler logic and way less calculation.
What was the solution? All it is, is using the end value of the generated first list to limit values of subsequent lists. List comprehensions take the first value of the first list and apply it to all values in the second list thus making a list. It is the first list end value that is the limit of each subsequent list. These limited lists do not generate any excess at the end of any list
The prime’s composite list to subtract is top and bottom diagonal to form a rouge triangle. In it x and y are identical. The Hammings lists are bottom, irregular diagonal only. The x and y are different.
My problem, now, is how to specify how many Hammings I want instead of thex in 2^x as the parameter. Is it just practical to use take with some derived value of x (in 2^x) to get the number of Hammings wanted? How can x be derived from specified n number of Hamming wanted? The second thing is how fast is this compared to the fastest Hamming list generators?
Thanks for any help you can offer.
The Hamming functions follow
gnf n f = scanl (*) 1 $ replicate f n
mk35 n = (c-> [m| t<- gnf 3 n, f<- gnf 5 n, m<- [t*f], m<= c]) (2^(n+1))
mkHams n = (c-> sort [m| t<- mk35 n, f<- gnf 2 (n+1), m<- [t*f], m<= c]) (2^(n+1))
last $ mkHams 50
2251799813685248
(0.03 secs, 12,869,000 bytes)
2^51
2251799813685248
4/5/2019
@Will Ness on SO suggested limiting early.
gnf n f| f==2= scanl (*) 1 $ replicate n 2
| f==3= takeWhile (<=2^(n+1))$ scanl (*) 1$ replicate n 3
| f==5= takeWhile (<=2^ n) $ scanl (*) 1$ replicate n 5
Thank @E-Coms for suggesting short circuit limiting very large lists generated.
hams2' n c d = [ takeWhile (<=d) [ m*f| m<- gnf c 2 ]| f<- [a*b| a <-gnf n 3, b<-gnf n 5] ]
hams2 n = sort.concat $ hams2' n (n+1) (2^(n+1))
last $ hams2 100
2535301200456458802993406410752
(0.09 secs, 69,227,792 bytes)
2 ^ 101
2535301200456458802993406410752
haskell
$endgroup$
I found some months ago that I could generate Hamming multiples of 3 and 5 multiples (3^x & 5^x) in one list comprehension. There are many fewer 3 and 5 Hamming multiples in a Hamming sequence. I did not have to be concerned with duplicate multiples as it is 2 disparate lists.
All I needed to do was add the Hamming 2 multiples.
When I did, it was chaos. Multiples of the 3 and 5 multiples with the 2^x produced clean Hamming numbers but left even more at the end of the list that had missing Hamming numbers between them.
The problem was the Cartesian product of the 2 multiples and the 3&5 multiples.
I had used the 3^x times 5^x’s in another algorithm successfully. I had limited the list with some involved calculation.
Then, I encountered the same problem working with primes. I wanted a list to subtract from a wheel but the list contained much excess. It was another huge Cartesian product of values.
I didn’t know which elements to eliminate from either list and I thought them intermixed.
Then it dawned on me. I tried it with the primes and it worked. Then with the Hamming 2s and it worked.
First I rewrote the 3 & 5 multiples list comprehension with the much simpler logic and way less calculation.
What was the solution? All it is, is using the end value of the generated first list to limit values of subsequent lists. List comprehensions take the first value of the first list and apply it to all values in the second list thus making a list. It is the first list end value that is the limit of each subsequent list. These limited lists do not generate any excess at the end of any list
The prime’s composite list to subtract is top and bottom diagonal to form a rouge triangle. In it x and y are identical. The Hammings lists are bottom, irregular diagonal only. The x and y are different.
My problem, now, is how to specify how many Hammings I want instead of thex in 2^x as the parameter. Is it just practical to use take with some derived value of x (in 2^x) to get the number of Hammings wanted? How can x be derived from specified n number of Hamming wanted? The second thing is how fast is this compared to the fastest Hamming list generators?
Thanks for any help you can offer.
The Hamming functions follow
gnf n f = scanl (*) 1 $ replicate f n
mk35 n = (c-> [m| t<- gnf 3 n, f<- gnf 5 n, m<- [t*f], m<= c]) (2^(n+1))
mkHams n = (c-> sort [m| t<- mk35 n, f<- gnf 2 (n+1), m<- [t*f], m<= c]) (2^(n+1))
last $ mkHams 50
2251799813685248
(0.03 secs, 12,869,000 bytes)
2^51
2251799813685248
4/5/2019
@Will Ness on SO suggested limiting early.
gnf n f| f==2= scanl (*) 1 $ replicate n 2
| f==3= takeWhile (<=2^(n+1))$ scanl (*) 1$ replicate n 3
| f==5= takeWhile (<=2^ n) $ scanl (*) 1$ replicate n 5
Thank @E-Coms for suggesting short circuit limiting very large lists generated.
hams2' n c d = [ takeWhile (<=d) [ m*f| m<- gnf c 2 ]| f<- [a*b| a <-gnf n 3, b<-gnf n 5] ]
hams2 n = sort.concat $ hams2' n (n+1) (2^(n+1))
last $ hams2 100
2535301200456458802993406410752
(0.09 secs, 69,227,792 bytes)
2 ^ 101
2535301200456458802993406410752
haskell
haskell
edited 2 days ago
fp_mora
asked Apr 1 at 17:57
fp_morafp_mora
1215
1215
1
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
mkHams 50will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values.cThis could be `2^i * 3^j * 5^k
$endgroup$
– fp_mora
Apr 3 at 16:09
1
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
1
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
1
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52
|
show 8 more comments
1
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
mkHams 50will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values.cThis could be `2^i * 3^j * 5^k
$endgroup$
– fp_mora
Apr 3 at 16:09
1
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
1
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
1
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52
1
1
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
mkHams 50 will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values. c This could be `2^i * 3^j * 5^k$endgroup$
– fp_mora
Apr 3 at 16:09
$begingroup$
mkHams 50 will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values. c This could be `2^i * 3^j * 5^k$endgroup$
– fp_mora
Apr 3 at 16:09
1
1
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
1
1
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
1
1
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52
|
show 8 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216671%2ffast-hamming-sequence-generation-in-haskell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216671%2ffast-hamming-sequence-generation-in-haskell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
What are "Hamming multiples of 3 and 5 multiples"? What is "a Hamming sequence"? There's a lot of explanation here of your path to the current version of the code, but I can't find an intelligible explanation of the problem it's trying to solve.
$endgroup$
– Peter Taylor
Apr 3 at 14:48
$begingroup$
mkHams 50will generate 6911 Hamming #s in sequence. Here is a link to the well understood Hamming sequence generation rosettacode.org/wiki/Hamming_numbers#Haskell The entry "Direct calculation through triples enumeration" is what this is trying to solve but in a more direct & simpler way. There is a Wiki, too. They are also known as ugly or regular numbers. I first was using involved calculation like the code in Rosetta Code but then I found the value of the end point of the first list of a Cartesian product as a limit of all other list values.cThis could be `2^i * 3^j * 5^k$endgroup$
– fp_mora
Apr 3 at 16:09
1
$begingroup$
It's slow as you need to screen or filter in each subStep. When you calculate the fold of 3 and all those larger than 2^(n+1) needed to be removed. same for the 5 .same for the 3*5 , you did it but maybe too late. The final steps also has such problems. you need to early stop guard. How about add a where clause some where to do it. Actually both questions has one answer. Build a queue with [1,2,3,5], every popped one multiple(2, 3, 5) and then insert back to the queue but keep unique value for the queue. The result is all popped ones. It is countable without extra number.
$endgroup$
– E.Coms
Apr 3 at 17:18
1
$begingroup$
Yes. Still it's slow. try the queue one should be 100 times fast than this one as you have to visit many unnecessary big numbers. In order to get it faster, you may cache three positions and then insert from there respectively, which will be very attractive.
$endgroup$
– E.Coms
Apr 3 at 17:37
1
$begingroup$
It is great to hear that.
$endgroup$
– E.Coms
Apr 3 at 17:52