How trolls count in Kotlin

Uzi Landsmann
Webstep
Published in
5 min readOct 26, 2020

--

Photo by Mark König on Unsplash

‘Everyone knows trolls can’t even count up to four!’*

*In fact, trolls traditionally count like this: one, two, three, many, and people assume this means they can have no grasp of higher numbers. They don’t realise that many can BE a number. As in: one, two, three, many, many-one, many-two, many-three, many many, many-many-one, many-many-two, many-many-three, many many many, many-many-many-one, many-many-many-two, many-many-three, LOTS.

I’ve read these wonderful lines in Terry Pratchett’s Men at Arms many years ago and while trying to learn different programming languages, I started using them as a challenge and as a way to investigate a programming language’s different aspects by trying to implement them in the language I’m currently learning. If you want to see how I implemented the troll numeric system in Kotlin, please read on.

Requirements

In order to implement the troll numeric system I needed some requirements. So I made a list which I will try to use later on when writing the code. And here it is — the complete set of requirements:

  1. The whole numeric system is consisted of five different words. These are: one, two, three, many and lots
  2. Simple troll numbers use one word, such as one, many, or lots
  3. Complex troll numbers use several…

--

--

Uzi Landsmann
Webstep

Software developer at Webstep. I write tech stuff and fiction in English and Swedish. Click on my lists to see more!