r/dailyprogrammer • u/oskar_s • Sep 03 '12
[9/03/2012] Challenge #95 [intermediate] (Filler text)
Your intermediate task today is to write a function that can create "filler text", i.e. text that doesn't actually mean anything, but from a distance could plausibly look like a real language. This is very useful, for instance, if you're a designer and want to see what a design would look like with text in it, but you don't actually want to write the text yourself.
The rules are:
- The argument to function is the approx number of words.
- The text is made up of sentences with 3-8 words
- Each word is made up of 1-12 chars
- Sentences have first word capitalized and a period at the end
- After each sentence there is a 15% chance of a linebreak and an additional 50% chance of this line break being a paragraph break.
An example of what the text might look like can be found here.
Bonus: Make it so that the character frequency roughly matches the English language. I.e. more e's and t's than x's and z's. Also, modify your code so that it will insert commas, exclamation points, question marks and the occassional number (as a separate word, obviously).
- Thanks to Racoonie for suggesting this problem at /r/dailyprogrammer_ideas!
5
u/nagasgura 0 0 Sep 03 '12 edited Sep 04 '12
Python with Bonus:
Example output with 1000 words: http://pastebin.com/PD55bH86
1
u/andkerosine Sep 03 '12
It's unclear whether using a corpus and Markov chains would be a valid solution to this challenge. Is this supposed to test one's ability to very roughly model the English language without training data?
2
u/PiereDome Sep 03 '12
Javascript: bonus(letter frequency, random punctuation, and 5% chance of a number for a word)
2
u/Unh0ly_Tigg 0 0 Sep 03 '12
My Java solution: http://pastebin.com/FiV4KVza
EDIT: did this in about 5-10 minutes. :D
2
u/capncanuck Sep 04 '12 edited Sep 04 '12
[That] (http://pastebin.com/Z9Lhu1PZ) was a lot of fun to write in Haskell.
It prints out exactly the number of words as the value of the argument.
I did half of the bonus.
1
u/thenullbyte 0 0 Sep 03 '12 edited Sep 03 '12
Some more ruby stuff. I wish I had more time to study this. Ruby seems like such a fascinating language (everything as an object is awesome).
1
u/skeeto -9 8 Sep 03 '12
In Emacs Lisp. Does everything in the bonus except commas,
Example output,
1
u/shivasprogeny Sep 04 '12
Java, with the letter frequency bonus.
I got my frequency chart here. I noticed that looking at the results the words are often too long to look Englisheque. I would like to improve this using a similar frequency table for word length.
1
u/[deleted] Sep 04 '12
In Python
and makes this:
1
u/ananthakumaran Sep 04 '12 edited Sep 04 '12
C with bonus.
output
https://gist.github.com/3624328
1
u/abecedarius Sep 04 '12
Some Javascript I'd already written in this vein (including the bonus punctuation), but using dictionary words and satisfying some additional requirements :) -- http://wry.me/sonnetron/
1
u/Puzzel Sep 05 '12
Python 3 solution, please critique!
1
u/[deleted] Sep 05 '12
Python 3 with bonus.
1
u/oskar_stephens Sep 05 '12
Ruby, with Bonus:
It's kind of cheating to use the built in word dictionary, but it was sooo much easier.
1
u/bschlief 0 0 Sep 06 '12
I'm digging all the ruby solutions. Here's mine. I used a bag of letters approach, similar to scrabble.
Example output available here
1
u/spacemoses 1 1 Sep 06 '12
F#, with bonus but without randomly adding numbers. I realized that the way I picked letter frequency was probably more complicated than it needed to be. Please critique!
1
u/minimalist_lvb Sep 06 '12
GO with bonus:
1
u/[deleted] Sep 07 '12
Java - no bonus and primitive, but it works
1
u/kirsybuu 0 1 Sep 11 '12
D with Bonus
1
u/jkoers29 0 0 Dec 26 '12
}
1
u/[deleted] Sep 03 '12
[removed] — view removed comment