# An Idea on A Language Version of Project Euler: Programming for Poets

Today, I chanced upon a Facebook comment by Brent Yorgey on another entry by another Facebook user on an online article in the online version of *The Atlantic* magazine describing how one person, James Somers, initially failed at learning programming, but later succeeded as a result of Project Euler (“How I Failed, Failed, and Finally Succeeded at Learning How to Code – James Somers – Technology – The Atlantic”).

(For those who aren’t aware, Project Euler is a site containing a series of mathematical/computer programming problems designed to be solved on a computer subject to the requirement that each problem must not take more than one minute to run.)

For some reason, I was unable to find the comment later on Yorgey’s Facebook profile (probably because his entry was a comment posted to another user, instead of a post). Therefore, I created my own Facebook post citing the original article, as follows:

It would be nice to have a non-mathematical version of this site for poets. One type of project that I would be especially interested in would be a site that used an online version of an Alice’s Adventures in Wonderland-style interactive dialog, a la _The Little Schemer,_ to teach how to think recursively. This could be expanded to teaching how to think functionally, then how to think in message-passing terms, etc.

Then I remembered a description that I had read in the late 1980’s, circa 1987, in a computer magazine (probably *Byte*) on a program for creating English sentences based on simple grammar rules and a lexicon, and added a (rather lengthy) comment to my post:

More specifically, one idea would be to create a site with challenges for manipulating words to form sentences of various types. I remember having once read a description of a program that used a set of simple grammatical rules combined wi…th a database of words to create sentences, some of which were very funny. For example, English has an SVO (Subject, Verb, Object) sentence order. Using such a setup, one might create a program that wrote nonsense sentences such as, “John waves music.” Adding adjectives could then create “John waves green music.” Adding adverbs could then create “John waves green music hungrily.” Adding subordinate clauses could then create “John waves green music hungrily because Jill eats hungry music sleepily.” Such nonsense sentences could form a basic for, say, a fun logic programming assignment. Then creating two objects to converse with each other using such sentences could form a basis for a message-passing assignment. There is no reason that sentences could not substitute for functions in a fun programming challenge.

If I were to create such a site, I would give challenges such as the following:

“John Aldebaran and Jill Betelgeuse are aliens from another planet. They learn by example, and want to study human communication by reading English sentences. Create a program that outputs simple sentences, using the following simple rule:

Sentence = Subject + Predicate,

where Predicate = Verb + ObjectTry to create a program that models realistic human communication. The better your program, the more John and Jill will learn.”

The benefit of this type of assignment is that it also appeals to poets who feel frightened by mathematics, because on the surface, it does not look like mathematics at all. A challenge is to create assignments that teach structured thinking to mathematically-frightened poets without causing them to realize that they are actually learning a different form of mathematics.

The problem with a mathematical programming site such as Project Euler is that it doesn’t attract most poets. I used to study English poetry in college, and wrote a number of English *haiku* that my writing professor, Steven Davis, enjoyed enough to print out and post on his wall at home (he actually showed the wall to me). He even walked with me once to the Sterling Memorial Library at my college to show me the microfiche devices, then used to browse profiles of graduate programs, in order to recommend that I apply to a graduate program in English. While I do not claim to be a poet, I have always been interested in writing poetry, and consider myself a poet-aspirant.

From my experience in speaking with other students in the English Department at my college and, later, with my English students at Berlitz (where I used to work as an English teacher before becoming a translator), the majority of English language students that I have encountered do not seem to enjoy studying mathematics in general. The problem is that most of them are Myers-Briggs “Feeler” types (as opposed to “Thinker” types), who tend to seek emotional meaning in everything, and it is difficult for them to find emotional expression *per se* in most mathematics. As a result, most of them seem to consider mathematics, and any branch of study that does not involve emotional expression, in general, to be a “dry” field. (Prior to matriculation, I myself had mathematics phobia, but thanks to Andrew Barnes, an extremely enthusiastic then-student of mathematics, I was able to conquer this phobia as a result of a self-paced study focusing on writing proofs and thinking theoretically.)

However, there should be a way to motivate such students to study programming. One possible solution is to use language, instead of mathematics, as a tool.

In fact, the idea of using a language model for a programming challenge is not new. In another comment on Facebook, I continued:

In fact, the idea of word play as a challenge in programming is nothing new; Douglas Hofstadter used many language-based examples in his work, _Fluid Concepts and Creative Analogies: Computer Models of the Fundamental Mechanisms of Thought_… (see http://en.wikipedia.org/wiki/Fluid_Concepts_and_Creative_Analogies). Hofstadter even wrote a book on poetic word-play, _

Le Ton Beau De Marot: In Praise of The Music of Language_ (see http://www.amazon.com/Ton-Beau-Marot-Praise-Language/dp/0465086438/ref=sr_1_1?s=books&ie=UTF8&qid=1307577619&sr=1-1).Personally, I find it a pity that most exercises on programming do not explore word-play; I once had a fellow student in a logic class explain that she disliked mathematics, but liked logic (even though, in fact, mathematics itself is a form of logic). Word-play can be considered a form of logic, too. Exploring word-play in programming could attract more poets to the field.

After further thought, I remembered that I had used to study elements of another language that seemed quite suited for modeling natural language: Prolog. For example, according to the site “Introduction to Prolog – The Mind Project,” modeling certain types of English sentences in Prolog can be quite straightforward:

Let’s tell the computer some facts about a family we know. We’ll put the Prolog statement after the English statement.

EnglishPrologJohn is the father of Susan. `father(john,susan).`

John is the husband of Martha. `husband(john,martha).`

John eats pizza. `eats(john,pizza).`

Susan eats pizza. `eats(susan,pizza).`

Martha eats pizza. `eats(martha,pizza).`

Susan eats oranges. `eats(susan,oranges).`

John bought pizza for Martha. `bought(john,pizza,martha).`

Susan is tired. `tired(susan).`

The problem with Prolog is that the language is almost a DSL (Domain-Specific Language) designed for modeling logic relationships. Inn fact, according to the Wikipedia entry for the language,

The name “Prolog” was chosen by Philippe Roussel as an abbreviation for

programmation en logique(French for programming in logic).

While many consider Prolog to be, in fact, a general-purpose programming language, the language tends to be much harder to use than certain functional or pseudo-functional programming languages for modeling mathematical functions. For example, consider writing a function for computing the Fibonacci sequence:

A naive Haskell version (identical to the version at “The Fibonacci sequence – HaskellWiki,” except with an added type annotation):

fib :: Int -> Int fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2)

A naive Scheme version (created by the author):

(define (fibonacci n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fibonacci (- n 2)) (fibonacci (- n 1))))))

A naive Prolog version (see “Prolog Guide – Metainterpreters”):

fibo_td(0,0). fibo_td(1,1) fibo_td(N,F):- N>1, N1 is N-1, N2 is N-2, fibo_td(N1,F1), fibo_td(N2,F2), F is F1+F2.

While this is a matter of personal taste, in terms of readability, I find the Haskell version to be the easiest to read, the Scheme version the second easiest, and the Prolog version the least easiest. Therefore, I do not find Prolog to have an advantage for readability for at least some kinds of mathematical functions.

However, Prolog does seem suited for modeling English sentences.

It may be an interesting exercise to create a version of Project Euler to substitute various kinds of English sentences or other language constructs for mathematical functions. Such a site could prove effective in attracting poets (and other poet-aspirants), as well as students with mathematics phobia in general, to programming.

## Trackbacks & Pingbacks