[Haskell-cafe] Need some help with an infinite list
Ross Mellgren
rmm-haskell at z.odi.ac
Tue Jun 16 20:47:02 EDT 2009
Here's a way using list comprehensions:
Prelude Data.List> take 1000 $ concat.concat $ [ [ replicate n c | c
<- ['a'..'z'] ] | n <- [1..] ]
"abcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvw
wxxyyzzaaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzzaaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzzaaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrssssstttttuuuuuvvvvvwwwwwxxxxxyyyyyzzzzzaaaaaabbbbbbccccccddddddeeeeeeffffffgggggghhhhhhiiiiiijjjjjjkkkkkkllllllmmmmmmnnnnnnooooooppppppqqqqqqrrrrrrssssssttttttuuuuuuvvvvvvwwwwwwxxxxxxyyyyyyzzzzzzaaaaaaabbbbbbbcccccccdddddddeeeeeeefffffffggggggghhhhhhhiiiiiiijjjjjjjkkkkkkklllllllmmmmmmmnnnnnnnooooooopppppppqqqqqqqrrrrrrrssssssstttttttuuuuuuuvvvvvvvwwwwwwwxxxxxxxyyyyyyyzzzzzzzaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhhiiiiiiiijjjjjjjjkkkkkkkkllllllllmmmmmmmmnnnnnnnnooooooooppppppppqqqqqqqqrrrrrrrrssssssssttttttttuuuuuuuuvvvvvvvvwwwwwwwwxxxxxxxxyyyyyyyyzzzzzzzzaaaaaaaaabbbbbbbbbcccccccccdddddddddeeeeeeeeefffffffffgggggggggh"
-Ross
On Jun 16, 2009, at 8:39 PM, Daniel Peebles wrote:
> One (rather ugly) option is:
>
> tail . map (\y -> showIntAtBase 26 (\x -> chr (x + 96)) y "") $ [0..]
>
> but I'm sure there's a prettier one out there :)
>
> On Tue, Jun 16, 2009 at 8:28 PM, GüŸnther
> Schmidt<gue.schmidt at web.de> wrote:
>> Hi guys,
>>
>> I'd like to generate an infinite list, like
>>
>> ["a", "b", "c" .. "z", "aa", "ab", "ac" .. "az", "ba", "bb",
>> "bc" .. "bz",
>> "ca" ...]
>>
>> When I had set out to do this I thought, oh yeah no prob, in a
>> heartbeat.
>>
>> Uhm.
>>
>> Help, pls!
>>
>> Günther
>>
>> PS: I know this should be a no-brainer, sry
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list