Roman Numerals

Summary: Integers expressed by Roman numerals: testing of correctness and generating random expressions.
Author: Jan Vlk
Owner: Jan Vlk (jvl)
Co-maintainers: <None>
Categories:
Homepage:
PackageInfo name: LittleThings2
RSS feed:

Description:

Are you good at Roman numerals?

Good or not, you can download LittleThings2 package and play around with them Romans for a while. The package contains a new Squeak class called 'RomanToArabic'providing means for testing of correctness of the numeric expressions consisting of Roman numerals and also for random generating of arbitrary amounts of such expressions.

It all started with the idea of recoding - just for the heck of it - my old R2A (Roman to Arabic) converting utility (something I wrote a few years ago when learning Visual C++) to Squeak. I found out the 'String' class already contains a 'romanNumber' method doing similar thing as R2A and for a while I almost abandoned the whole idea. Fortunately it did not take me long to realise this method (written on 5/20/2000 by sma) pays for its elegant leannes by entirely liberal attitude to its arguments: it willingly converts to integers any strings consisting solely of characters I, V, X, L, C, D, and M. In other words beside converting meaningful sequences of Roman numerals it also converts a lot of trash. So I finally decided to recode my old C++ application anyway. The result was a new Squeak class called 'RomanToArabic' containing the 'romanNumberStrict' plus a few supporting methods. Actually 'romanNumberStrict' method wraps around the original 'romanNumber' and checks the string argument for correctness letting through only actual Roman numeric expressions.

When 'romanNumberStrict' started to work reliably I added one more method - 'giveMeRomans' which produced a hundred of random correct Roman numeric expressions of constant length. Then it occured to me to set the required number of Roman numeric expressions and their size by way of arguments used with this method. I started playing with it and the result was the 'giveMeRomans:min:max:' method not only generating the required number of expressions with randomly changeable or constant lengths and announcing generated numbers by the Speaker woman (this can be switched-off by replacing 'ts size 0' with 'ts size 15' in 'singleTestFrom:To:') but also - in the best traditions of defensive programming - ready to cope with any nonsensical input in place of proper integer arguments (including negative integers, strings, single characters, nil, and even Boolean values).


Releases


Back