Question: I have a few interests, and among them belong fiction, math and computer science, and so naturally I like to imagine/think about the possibility of a piece of fiction living in the intersection of these fields. I wonder, what does it mean to "code a novel"? Is there already such a thing as algorithmic fiction?

Answer: 
Thirty or more years ago, a computer program named [Racter](http://en.wikipedia.org/wiki/Racter) "wrote" a very interesting book called *[The Policeman's Beard is Half Constructed](https://www.amazon.com/dp/0446380512/ref=as_li_ss_til?tag=dalehemer-20&camp=0&creative=0&linkCode=as4&creativeASIN=0446380512&adid=1SPQQDER225G5K44S4EQ&).*

The programmer plugged in a variety of sentence, paragraph, story, and poem templates, and a bunch of words and the relationships among them. Every time he ran Racter, he got a different pseudo-random story.

Then the programmer selected the ones that were worth putting in a book.

Mostly the stories and poems were delightfully weird. This is my favorite:

> 
> More than iron, more than lead, more than gold I need electricity.  
> 
>  I need it more than I need lamb or pork or lettuce or cucumber.  
> 
>  I need it for my dreams.
> 
> 
> 

Very eerie, that one.

Racter also had a short story published in *Omni* magazine.

There was also Gahan Wilson's delightful "[Science Fiction Horror Movie Pocket Calculator](http://buzzdixon.com/writing-2/the-gahan-wilson-sci-fi-horror-movie-pocket-computer/)," a flowchart for generating stories.

I used that to learn programming. My favorite story was

> 
> Earth falls into the sun and nearly everybody dies.
> 
> 
>
If by "code a novel," you meant "write computer code that makes a novel," then it is (sort-of) already being commonly done, in two different ways. One type is called computer games, and they have become quite sophisticated, both as code and as (partly interactive) novels. The other type is called "CGI animation," and is used to make movies.

But in these two types, the computer code is completely hidden from the consumer, who would have zero interest in it. Besides which, you don't *read* computer games and movies. Besides, I'm pretty sure you know about those two types! So perhaps you are asking instead if there is computer code that the consumer actually reads, and which is also a novel. If you could pull that off (successfully), you'd deserve both a Nobel and a Pulitzer! But, alas, the set of your target audience would be the intersection of the set of literati and the set of geeks. That does not bode well for sales. :-)