How trolls count in Kotlin
‘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:
- The whole numeric system is consisted of five different words. These are:
one
,two
,three
,many
andlots
- Simple troll numbers use one word, such as
one
,many
, orlots
- Complex troll numbers use several…