Word Addition Program, 2012-06

foe + gun = mir

foe + gun = mir

 

In a conversation with a friend I wondered if one word added to another word would result in a third word. To figure it out, I made a python word addition program. Each word is converted to a base 26 number with A=0, and Z=25. Then you convert each number to base 10, add them together, and convert the result back into base26, convert that into letters, and see if it is a word.

Word Addition Project Challenges

This project had a couple of interesting challenges. I made a custom class to store the base26 words, and I overloaded the addition method to let me add instances together. The program took ~ 4 hours to run, when it was adding a list of 5,000 nouns to each other because it was done by brute force. Once the program ran I had a long list of word1 + word2 = word3, but many of those words were obscure. So for example, I’d rather see:

band + road = song

Rather than the obscure:

adit + crim = curf

Scoring Words and Finding the Best Solutions

So I had to make a way to score my solutions. A friend suggested that I look into natural language processing (nlp). I used the nltk library, which has a method which lets you check how many times a word occurs in a library. I used Wikipedia as my library, then scored each solution using each word’s frequency. Note: my word scoring code is linked to at the bottom of this post. Scoring solutions with Wikipedia yielded much more interesting non-obscure results. I then read through them and kept the most interesting solutions, which appear below:

foe + gun = mir
alp^2 = fear
band + road = song
kid + two = beer
belt + seal = time
hell + meat = time
gang + life = risk
man + sky = bell
cash + rock = tour
car + dog = fox
hand + load = song
guns + thing = today
coin + dame = four
bush + duck = four
homer + inn = house
air + poem = pond
gin + time = tour
baby + soup = town
dog + man = pot
cow + pub = six
math + star = betty
dog + gas = joy
dad + food = frog
camp + jail = lava
brandy + men = brazil
bee + rat = sex
body + fang = gore
eel + hand = hero
hag + tbs = baby
owl + pig = beer
cult + fish = idea
art + gin = hag
gun + hag = nut
fear + hag = flax

If you want to assign a score to a noun based on how frequently it is used, use the code I wrote.
I posted it in a Github repository here.

Leave a Reply

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