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 <[email protected]> wrote: > Here's why it works: > > genbin 3 = replicateM 3 "01" = (unfold replicateM) do x1 <- "01"; x2 > <- "01" ; x3 <- "01"; return [x1,x2,x3] = your desired result > (enumerate all combinations of x1,x2,x3 with each being 0 or 1). > > 2010/10/15 Eugene Kirpichov <[email protected]>: >> genbin = flip replicateM "01" >> >> 2010/10/15 rgowka1 <[email protected]>: >>> Hi - >>> >>> How can I generate all binary string of a given length? The type >>> signature would something like - >>> >>> genbin :: Int -> [String] >>> >>> For example genbin 2 would give ["00","11","01","10"] and genbin 3 >>> would give ["000","001","010","011","100","101","110","111"] etc.. >>> >>> thanks.. >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> [email protected] >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >> >> >> >> -- >> Eugene Kirpichov >> Senior Software Engineer, >> Grid Dynamics http://www.griddynamics.com/ >> > > > > -- > Eugene Kirpichov > Senior Software Engineer, > Grid Dynamics http://www.griddynamics.com/ > _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
