On Fri, 15 Oct 2010 09:16:58 -0400, rgowka1 wrote:
>But genbin 32 gives an empty list.. works till 31.
That's because Daniel uses values of type Int as intermediate storage
during the computation, and Int values are only 32 bits long. By
replacing Int with Integer (which does not have that limit
Thanks Daniel.
But genbin 32 gives an empty list.. works till 31.
On Fri, Oct 15, 2010 at 9:05 AM, Daniel Gorín wrote:
> I expect this one to run in constant space:
>
> import Data.Bits
>
> genbin :: Int -> [String]
> genbin n = map (showFixed n) [0..2^n-1::Int]
> where showFixed n i = map (b
I expect this one to run in constant space:
import Data.Bits
genbin :: Int -> [String]
genbin n = map (showFixed n) [0..2^n-1::Int]
where showFixed n i = map (bool '1' '0' . testBit i) [n-1,n-2..0]
bool t f b = if b then t else f
Daniel
On Oct 15, 2010, at 9:43 AM, Eugene Kirpicho
Actually my ghci doesn't crash for genbin 25 (haven't tried further),
though it eats quite a bit of memory.
How are you going to use these bit strings? Do you need all of them at once?
2010/10/15 Aleksandar Dimitrov :
> On Fri, 15 Oct 2010 14:34:42 +0200, rgowka1 wrote:
>
>> Amazing, will never f
On Fri, 15 Oct 2010 14:34:42 +0200, rgowka1 wrote:
Amazing, will never find this in any other languagw. But ghci crashes
for bigger input. Like genbin 20. How to scale this function?
Well, "scaling" this isn't really possible, because of its complexity. It
generates all permutations of a gi
Amazing, will never find this in any other languagw. But ghci crashes
for bigger input. Like genbin 20. How to scale this function?
On 10/15/10, Eugene Kirpichov wrote:
> Here's why it works:
>
> genbin 3 = replicateM 3 "01" = (unfold replicateM) do x1 <- "01"; x2
> <- "01" ; x3 <- "01"; return [