13m
comment Turning a tree into a heap in haskell
yes, I didn't try to run your program. I'll try to run it with my example and see what it produces. But in my reasoning this is exactly what I did - I assume it works; then heapify ([1,2,5]++[20,19..11]) = 1. doTop: produces ([5,2,1]++[20,19..11]) ; then 2. assuming heapify works, we get [5,20,18,...], and then 3. we have the last line to finish it up, adjustRight . adjustLeft. My understnding was, each call makes at most one swap. I'll re-read.
23m
comment Turning a tree into a heap in haskell
@AndrewC I think we were wrong in reopening this question. :) The OP doesn't give any decent description of the algorithm. In fact all that we have to go by, is the one word "heapify". Maybe you should leave it like it is, as an example code, and leave it to the OP to fiddle with the specifics of the algorithm by themselves. :)
5h
revised Visual Studio Standard Style as CSS
edited tags
9h
answered Haskell <<loop>>
9h
comment Haskell <<loop>>
likeThis -> whichIs ? :)
9h
revised Haskell <<loop>>
formatting, c/e to clarify
10h
comment Turning a tree into a heap in haskell
sorry, but you've missed that this datatype can not host any even number of elements. and, heapify does not guarantee heap property after its operation: example: [1,2,5]++[20,19..11]. node' will have 5 at its top ([5,20,18,...]) and it would take more than just two swaps at top to heapify that tree.
11h
revised Why do these folds stop at the head/tail?
correct the reduction sequence
1d
revised Haskell - list comprehension can't enumerate N × N
deleted 35 characters in body
1d
comment Haskell - list comprehension can't enumerate N × N
@sclv done! (it was closed before, was it?)
1d
answered Haskell - list comprehension can't enumerate N × N
1d
comment Sieve of Sundaram - list comprehension
sorry for barging in like that again, but I thought to try it, and indeed minus [1..n] $ foldi union [] [ [i+j+2*i*j | j<-[i..n]] | i<-[1..n]] runs almost as fast as the previous one, above (laziness FTW! :) ). [foldi union []](http://www.haskell.org/haskellwiki/Fold#Tree-like_folds) is more or less the same as Data.List.Ordered.unionAll from data-ordlist package, and union as minus is for ordered lists (not the Data.List.union).
1d
comment Sieve of Sundaram - list comprehension
[minus [1..n] . sort $ sSundDelete n](en.wikipedia.org/wiki/Haskell_98_features#minus) should be yet faster. :) looks like linearithmic vs quadratic in n, empirically.
1d
comment Factorize a number and check prime of the sum
@MarcClaesen but your instincts were right, you certainly do not need to test up to x/2. sqrt(x) is enough - when you divide the new found smallest factor out of the number being factorized.
1d
comment Factorize a number and check prime of the sum
@MarcClaesen 3*17 = 51. :)
2d
awarded Supporter
2d
answered Binding symbols and querying symbol values in Prolog
2d
comment Sieve of Eratosthenes Scheme
0 is still Boolean True in Racket, as in Scheme, in cond as in if. (/ (- v 1) 2) is just i ; (v*v - 1)/2 = (4i^2+4i+1 - 1)/2 = i(2i+2) = i(v+1). In for i in range iv+i to sz, maybe using j is less confusing? the value lm still corresponds to index (lm-1)/2. for i in range 1 to sz implies i>0 always. :) If it works up to 100 mln in an acceptable time, for a Scheme that's impressive. I wonder, how much time does it get for it to get to 15485864? 32452844?
May
19
comment Sieve of Eratosthenes Scheme
the inner for-each starting point corresponds to 3v, but it's OK to start from v*v. -- what is range? Which Scheme are you using? It is necessary to include (lm-1)/2 in the range, not lm (does range include its 2nd arg?). With all this, the code will be faster (probably about twice, because of lm). :)
May
19
comment Sieve of Eratosthenes Scheme
in the outer for-each loop, (if (vector-ref sv i) is always true. In Scheme, 0 stands for true value, no false, as in C. -- (map ... (2i+1) ... (filter ... combination is better. :)
1 2 3 4 5