Not so many moons ago, I decided to see if I could make my own version of the recent hit online game, Wordle. There’s an easy way to do this and hard way to do it. I chose to build my own version the hard way.

The easy way involves something called Github and cloning. The hard way involves teaching myself to build webpages from scratch using CSS and Javascript. I mentioned my folly to a knowledgeable friend. The knowledgeable friend laughed.

The knowledgeable friend writes software for a government agency. I’m not allowed to tell you which agency – suffice to say it’s the sort of agency that can’t risk using any old software so they write their own. Anyway, knowledgeable friend, let’s call him Keith from now on, explained why Javascript is a terrible choice of language for a novice programmer to choose to as a first language – especially if you’re intent on teaching yourself to code.

Now, unfortunately Keith (not his real name) isn’t going to teach me Javascript, but he is going to help me to learn the principles of coding. His favoured method of teaching seems to consist of calling me Grasshopper and setting me a series of progressively difficult problems. I must solve these problems without resorting to Google and with very minimal input from my knowledgeable friend and instructor Keith.

The first problem was to write some code that identifies if a string is a palindrome or not (A string? That’s a sequence of characters to you and me, or in other words – a word. And a palindrome is a word or phrase that reads the same backwards as it does forwards).

I was quite pleased with my attempt – you can test my solution here. It currently works with words but not phrases containing spaces e.g. A man a plan a canal Panama will fool my code.

The second problem was a little more challenging. Compare two strings and determine if they are anagrams e.g. CHEATING and TEACHING. Again, teaching myself means not cheating by googling to see how others had solved this classic beginners coding problem. This one took me a little longer. And I learned that coding is a little like proofreading an a email. For no sooner had Grasshopper sent his code off to Master Keith than I discovered a problem.

Can you spot the problem?

Type CHEAT and TEACH into my user interface and my code will confidently declare that they are anagrams. However, if the words you type in repeat any letters, a potential uncertainty arises.

For example, if Johnny types in REDRUM and MURDER, my code won’t tell you that The Shining was a frightening film but it will tell you (quite correctly) that they are anagrams. But if Johnny decides to commit bovicide by replacing one of the R’s in MURDER with a U so that you’ve got a MUUDER on your hands. My code won’t notice the foul play and declare they are still anagrams.

In the next installment I’m going to tell you how I fixed this problem and why Master Keith preferred Grasshopper’s imperfect solution.

Leave a comment

About the Podcast

Welcome to The Nullius in Verba podcast, your ultimate guide to making up your own mind. I don’t intend to please all of the people all of the time, so listen and ye shall find comedy, complexity, controversy, and clever and colourful characters who may open your mind to new ways of thinking.

Explore the episodes

Latest posts