Adventures in Digital History

Here We Go Again…

I find myself diving into the word of code yet again.

And this time, it’s for an English class. Joy.

Jokes and sarcasm aside, we have started a journey into computational coding and I really am excited. The examples we were working with in class are very similar to what we did last semester in Creative Coding, and I loved that class. While I’m sure a lot of people are going to write about their apprehension with coding, I’m going to use it to explore some more examples. I’m already pretty familiar with the basics of coding, especially after taking two classes with Dr. Whalen where he put an emphasis on it. Thank you Dr. Whalen! You made me slightly more confident in my coding abilities over the past year!

We were given some poetry templates to work with to generate every possible combination of words in a short phrase. The first was ‘KICK’, ‘THAT’, ‘HABIT’, ‘MAN’. The code looks a little something like this:

#!/usr/bin/python

# Permutation Poems, copyright (c) 2014 Nick Montfort <nickm@nickm.com>
# Original by Brion Gysin & Ian Sommerville, 1960
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Updated 31 May 2018 to add compatibility with Python 3 (Python 2 still works)

def permutations(elements):
    if len(elements) < 2:
        yield elements
    else:
        for i in range(len(elements)):
            for result in permutations(elements[:i] + elements[i+1:]):
                yield [elements[i]] + result

words = ['KICK', 'THAT', 'HABIT', 'MAN']

for parts in list(permutations(words)):
    print(' '.join(parts))

I used this exact code, changing the phrase to ‘HERE’, ‘I’, ‘AM’, ‘AGAIN’. I’ll provide my example next to the original below:

Original: Kick That Habit Man

KICK THAT HABIT MAN
KICK THAT MAN HABIT
KICK HABIT THAT MAN
KICK HABIT MAN THAT
KICK MAN THAT HABIT
KICK MAN HABIT THAT
THAT KICK HABIT MAN
THAT KICK MAN HABIT
THAT HABIT KICK MAN
THAT HABIT MAN KICK
THAT MAN KICK HABIT
THAT MAN HABIT KICK
HABIT KICK THAT MAN
HABIT KICK MAN THAT
HABIT THAT KICK MAN
HABIT THAT MAN KICK
HABIT MAN KICK THAT
HABIT MAN THAT KICK
MAN KICK THAT HABIT
MAN KICK HABIT THAT
MAN THAT KICK HABIT
MAN THAT HABIT KICK
MAN HABIT KICK THAT
MAN HABIT THAT KICK
Modified: Here I Am Again

HERE I AM AGAIN
HERE I AGAIN AM
HERE AM I AGAIN
HERE AM AGAIN I
HERE AGAIN I AM
HERE AGAIN AM I
I HERE AM AGAIN
I HERE AGAIN AM
I AM HERE AGAIN
I AM AGAIN HERE
I AGAIN HERE AM
I AGAIN AM HERE
AM HERE I AGAIN
AM HERE AGAIN I
AM I HERE AGAIN
AM I AGAIN HERE
AM AGAIN HERE I
AM AGAIN I HERE
AGAIN HERE I AM
AGAIN HERE AM I
AGAIN I HERE AM
AGAIN I AM HERE
AGAIN AM HERE I
AGAIN AM I HERE

Another one I had fun playing around with was:

#!/usr/bin/python

# Stochastic Texts, copyright (c) 2014 Nick Montfort <nickm@nickm.com>
# Original by Theo Lutz, 1959; translation by Helen MacCormack
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Updated 31 May 2018 to add compatibility with Python 3 (Python 2 still works)

from random import choice

subjects = ['COUNT', 'STRANGER', 'LOOK', 'CHURCH', 'CASTLE', 'PICTURE',
            'EYE', 'VILLAGE', 'TOWER', 'FARMER', 'WAY', 'GUEST', 'DAY',
            'HOUSE', 'TABLE', 'LABOURER']
predicates = ['OPEN', 'SILENT', 'STRONG', 'GOOD', 'NARROW', 'NEAR',
              'NEW', 'QUIET', 'FAR', 'DEEP', 'LATE', 'DARK', 'FREE',
              'LARGE', 'OLD', 'ANGRY']
conjunctions = [' AND ', ' OR ', ' THEREFORE ', '. ', '. ', '. ', '. ', '. ']
operators = ['A', 'EVERY', 'NO', 'NOT EVERY']

def phrase():
    text = choice(operators) + ' ' + choice(subjects)
    if text == 'A EYE':
        text = 'AN EYE'
    return text + ' IS '

print('')
print(phrase() + choice(predicates) + choice(conjunctions) +
       phrase() + choice(predicates) + '.')
print('')

This one produces a single sentence instead of all possible variations. Here’s a few of the results I got:

NO CASTLE IS GOOD. NOT EVERY HOUSE IS GOOD.

A TOWER IS DEEP. NO COUNT IS OPEN.

EVERY LABOURER IS DARK. A HOUSE IS GOOD.

NOT EVERY HOUSE IS LARGE. A GUEST IS QUIET.

The results tend to be nonsensical, but you can search for meaning. That’s one of the things I love most about computer generated poetry and literature.

For some more examples of similar things I’ve done to this, check out my Creative Coding Portfolio! I have made some poetry and novels using code, which is similar to this in many way!

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php