Consider tasks like counting, sorting, and arithmetic. We humans learn algorithms for these processes so that we can apply them in all kinds of situations. For instance, while memorising the multiplication table works well for small numbers (0–9), learning the multiplication algorithm is far more efficient when dealing with larger numbers. This approach allows us to generalise and solve problems beyond the scope of memorised examples, taking advantage the principles of the algorithm itself.

I wanted to demonstrate that ChatGPT would fail on a simple example, so I asked it: “Count how many times each letter in ‘anders hast’ occurs and give a sorted list of letters.” To my surprise, it provided the correct answer by producing Python code to solve the problem! In doing so, ChatGPT unexpectedly proved my point: algorithms can sometimes be superior to AI models trained solely on data.

Here is the code:

>>> from collections import Counter
>>> text = “anders hast”
>>> letter_counts = Counter(text.replace(” “, “”)) # Ignore spaces
>>> sorted_counts = sorted(letter_counts.items())
>>> sorted_counts

And the output was:
[(‘a’, 2), (‘d’, 1), (‘e’, 1), (‘h’, 1), (‘n’, 1), (‘r’, 1), (‘s’, 2), (‘t’, 1)]

Leave a comment