Skip to main content

Rude Word Hunt

This post is inspired by a post a friend shared with me on Twitter. It shows a set of famous chocolate bar wrappers that have been cut and reglued together.



That immediately got me thinking if I could get a computer to do this for me. There are so many other situations where this could come in handy. For example, have you ever found yourself alone with a letterboard and wondered what fun you could make by rearranging the letters? Wonder no more.

There will be some rude words in this article. If you’re not too worried about that, read on.

The source code for this article can be found on Github.

Some Ins and Outs

The program takes a list of everyday words and returns a list of rude words.

Each rude word returned will have a pipe character inserted at points where an input word would have to be cut to form the rude word. For example, let’s say the program was given “twix” and “kit kat”. It would return “tw|at”. It would be up to the user to figure out from which input words the “tw” and the “at” came from.

Getting the Thrust of it

How does the matching work? We use a shrinking sliding window. In this section we’ll go through the concept, with examples.

The program will try to build each rude word one at a time from the list of given words. Let’s imagine that the program is trying to build the word “twat”.

The program starts by trying to find instances of the whole word “twat” in the given words. Unless the user had passed in one of the nine lucky English words that contain the letter sequence t-w-a-t within them, the program will keep looking.

The next step is key. The program will shrink the search word by one character and keep shrinking until it’s eventually just looking for the rude word’s individual letters. An example helps understand this.
  • 4 letters: twat
  • 3 letters: twa, wat
  • 2 letters: tw, wa, at
  • 1 letter: t, w, a, t
Let’s say we have our favourite input words “twix” and “kit kat”.
  1. “twat” is not found in the input words, so try looking for something smaller. 
  2. Neither “twa” nor “wat” are found, shrink the search words again. 
  3. Aha! “tw” and “at” are found. 
This technique will give you longer fragments first, meaning there is less chopping to do if you are cutting the words out of a magazine or poster.

Massaging the Input Words

How do we stop parts of the input words being used multiple times for one rude word? We remove them from the list, that’s how.

Let’s say we have the input words “tap” and “water” and we need to remove “wat”.

First, we remove “water” from the list of input words, then add in any parts of that word which aren’t matched by the rude word fragment. In our example, we remove “water” and then add “er”. Thus, the list of words available for further matches will be “tap” and “er”.

It’s just like cutting letters out of a magazine for a ransom note.

Getting Busy With Some On The Side

There is one more key piece of this puzzle we need to go through for it to work - what happens when a portion of a rude word is matched?

Say we want to try build the word “threesome” and the program has just matched up the letters “eeso”. We still need to match “thr” and “me” before we can say the word threesome can be built from the input words.

The good news is that we can do this with very little effort... because we have already done most of it. All we need to do is to try build the rude word “thr” with the updated list of input words. Same again for “me”. Once we have all the parts we just put them together with the pipe separator. Word found.

This technique is another example of recursion which is quite commonly used where a problem can be divided into smaller and smaller parts.

Finishing Off

Once we have a list of rude words, we can order them in several different ways.

Some ways to order them are:

  • By max fragment length from the input words - useful when you want to impressive that special someone with the longest chunk from the input words.
  • By the longest rude word that can be formed - also useful when trying to use as many letters as possible.

If You Feel Up For Round Two

One way to take this little program further is to find multiple rude words for the input words and try to optimise for the most number of rude words, or the most letters used. To do that will require a little extra grunt.

Comments

  1. I guess I am the only one who comes here to share my very own experience guess what? I am using my laptop for almost the post 2 years.
    RemoveWAT Crack
    Wondershare DVD Creator Crack
    MainStage Crack

    ReplyDelete
  2. Top 10 best slots to play online for real money | Mapyro
    No deposit casino, no free spins, No 영천 출장안마 Deposit 당진 출장샵 Slots, real 광주 출장마사지 money mobile games and 광주광역 출장샵 a 광명 출장안마 wide range of progressive jackpot slots for real money.

    ReplyDelete
  3. Luckily, there are lots of|there are numerous} live casinos from relevant jurisdictions like MGA accepting gamers from South Korea, so they'll have no points taking part in} at these sites. The web site boasts of at present offering the best slots with the best RTPs available in the market}, which in the end will increase the players’ payout percentages in lengthy run|the long term}. The in style card game is played by a number of} gamers and a supplier. Every participant plays towards the supplier and not towards another participant. Many 카지노사이트 gamblers favor taking part in} blackjack in brick-and-mortar casinos as the game demands human interplay. However, online blackjack is the popular alternative of experienced gamblers as gamers cannot apply methods corresponding to card counting.

    ReplyDelete

Post a Comment

Popular posts from this blog

Depth First Search - For Babies!

Old MacDonald Had A Farm

I wanted to play around with AWS Polly, which is a service that converts text into speech for you.  What better way to test this out than with an "Old MacDonald Had A Farm" song generator.  But first, I needed to do some research. Song Variations There are actually many different ways to sing this song.  I spent a few minutes listening to various versions and here are some important differences I discovered: The list of animals is different every time. The Wiggles version shortens the previous animal sounds so there is no "here a woof, there a woof, everywhere a woof woof".  They simple sing "woof woof here, woof woof there". The previous animal sounds can either be in order, reversed or left out entirely. Generator Program The code to generate the lyrics is quite simple.  I have it uploaded on Github . For every animal in the given list of animal names/sounds, it writes a verse.  Each verse has a intro lines ("Old MacDonald had a f...

Word Changer

I found this little challenge in a puzzle booklet and instantly thought "I wonder if I can get a computer to figure this out for me?". Not long after that first thought, I had a second thought "I wonder if I can get a computer to give me the LONGEST chain of words!". The source code for this project is on  Github . Version 1: Find Longest Path I figured that finding the longest chain will probably take a lot of compute, so designing for performance was a priority. Dictionary words We need a list of English words and we need to be able to quickly check if a word of a certain length is a real word. For this, I created a hashmap where the key is the length of words and the values are a set of all words of that length. A set gives us constant-time lookups, which we definitely need. Search Algorithm Next, I needed to decide an overall approach to take to find the longest path. For this, I decided to use a depth-first-search algorithm. This algorith...