Writing Love Letters, Christmas Greetings and Postcards by algorithm

Create a creative algorithm that writes love letters or christmas card greetings to learn about how programs can be creative and learn about english grammar and writing. Do it as unplugged programming using index cards. For classes that can program, have them then write the program. 

The first ever attempt to write a creative program was probably written by Christopher Strachey in the 1950s. It was a love letter writing program that wrote very flowery, gushing letters such as:

BELOVED CHICKPEA, YOU ARE MY EAGER BURNING, MY FONDEST WISH, MY EAGER HEART, MY BREATHLESS THIRST. MY FONDEST FANCY LOVINGLY ATTRACTS YOUR AVID ENTHUSIASM. YOURS BEAUTIFULLY, M.U.C

Read more about it in the cs4fn article here: and see a version of it in action here [EXTERNAL] as well as see the word lists Strachey used.

Activity: Love Letter writer

Write your own version of the love letter program. By changing the templates and word lists perhaps you can improve on Strachey’s version. Here is one of the offerings from my attempt to write a love letter writing program:

Beloved Little Cabbage,

I cling to your anxious fervour. I want to hold you forever. You are my fondest craving. You are my fondest enthusiasm. My affection lovingly yearns for your loveable passion.

Yours, keenly Q

Have students work out the templates Strachey and I used. Mine were:

salutation1 + ” ” + salutation2 + “,”

“I ” + verb + ” your ” + adjective + ” ” + noun + “.”

“You are my ” + noun + “.”

“I want ” + verb + ” you forever.”

“I ” + verb + ” your ” + adjective + ” ” + noun + “.”

“My ” + noun1 + ” ” + adverb + ” ” + verb  + ” your ” + adjective + ” ” + noun2 + “.”

“Yours, ” + adverb + ” Q”

Have them work then out their own templates and word lists to fit them.

Write out the templates on large pieces of paper leaving gaps labelled with the grammatical category (e.g. verb, noun) for the missing words. Write the word lists on index cards, labelled on the back with the grammatical category. Keep the cards in separate piles corresponding to their grammatical category.

To generate a love letter, use the following algorithm:

  1. Shuffle the template sheets and lay them out in a random order (apart from salutation and sign off ones which go at start and end).
  2. Repeat the following until all gaps are filled:
    1. Take the appropriate pile of cards  for a word gap and shuffle them.
    2. Take a word at random from the pile.
    3. Place it in the space.

Evaluate your templates and word lists thoroughly be doing this repeatedly, improving it as needed. A variation of this kind of paper and card prototyping is a common way professionals do early prototyping and user testing of algorithms and interfaces, to get them right before too much time and effort is put into creating the actual implementation.

For groups that can program, have them now implement their love letter generator in a programming language of their choice.

Activity: Christmas Greeting writer

“Mrs Ashman ‏@GH_CompSci I had a similar idea and was going to use the Mr Bean clip where he is sending Xmas cards to himself as a starter”

You can do the above activity with other kinds of letter. For example at Christmas why not do the activity to generate christmas card messages. You will never have to write a christmas card again. Here is an example from my first attempt:

Season’s Greetings!

    I wish you a wonderful holiday.

    I hope to catch up with you in the new year.

with love Q

I used the templates:

“I wish you a ” + adjective + ” ” + noun + “.”

“I hope ” + verb + ” you ” + adverb + “.”

My word lists were:

salutations = {“Happy Christmas”, “Merry Christmas”, “Season’s Greetings”, “Happy New Year”}
adjectives = {“wonderful”, “joyous”, “peaceful”, “relaxing”}
nouns = {“holiday”, “time”, “few weeks”, “christmas”}
verbs = {“to see”, “to catch up with”, “to be with”, “to snog”}
adverbs = {“soon”, “in the new year”, “sometime soon”, “before long”}
endings = {“with love”, “best wishes”, “all my love”}

Here is a slightly later version of my algorithm implemented as a program in Python

Either try to write it yourself from scratch, or modify it with different word lists and new sentence templates.

Can your class do better? Perhaps they can create a christmas love letter writing algorithm.

Activity: Postcard writer

Do the same for other kinds of writing. For example, why not create one that writes postcards for you so you don’t have to interrupt reading that thriller by the poolside.