[Haskell-cafe] Re: How would you hack it?
Achim Schneider
barsoap at web.de
Wed Jun 4 16:32:28 EDT 2008
Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> I have a file that contains several thousand words, seperated by
> white space. [I gather that on Unix there's a standard location for
> this file?]
>
Looking at /usr/share/dict/words, I'm assured that the proper seperator
is \n.
> Clearly, what I *should* have done is think more about a good
> abstraction before writing miles of code. ;-) So how would you guys
> do this?
>
Generate a Map Int [String] map, with the latter list being an infinite
list of words with that particular size.
Now assume that you want to have a 100 character sentence. You start by
looking if you got any 100 character word, if yes it's your sentence,
if not you divide it in half (maybe offset by a weighted random
factor [1]) and start over again.
You can then specify your whole document along the lines of
(capitalise $ words 100) ++ ". " ++ (capitalise $ words 10) ++ "?" ++
(capitalise $ words 20) ++ "oneone1!"
[1] Random midpoint displacement is a very interesting topic by itself.
--
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited.
More information about the Haskell-Cafe
mailing list