Skip to main content

Posts

Depth First Search - For Babies!

Recent posts

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...

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 word...

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...

Clueless

Clueless is a popular style of crossword puzzle where there are no clues, only numbers.  It is also known as “Code Words” and “Crack the Code”. Each square on the crossword contains numbers and each number maps to a letter and the puzzler needs to figure out which number is which letter. The ultimate goal is to figure out the "final word", seperate from the main puzzle. Clueless puzzle This post will describe how to get a computer to solve Clueless puzzles for you. Clues The clues themselves can be represented using integer arrays. For example  {20, 21, 4, 9, 23, 25} . That's it.  There is no need to create a two dimensional array to reproduce the layout with all the digits and black squares. There is no need to track whether the clue goes across or down. Depending how the program goes, it might not even be required to input all the clues to get to the final solution. I once solved a puzzle using only four clues. Writing down all (or even some) of the clues...