The king of Ancient Rome is having difficulties determining if a magic square is valid or not, because the magic square he is checking does not include any separators between the numbers. He has hired a software engineer to help him determine if a magic square is valid or not.
Input Description
Input comes in on STDIN or command line arguments. You cannot have the input pre-initialised in a variable (e.g. "this program expects the input in a variable x
"). Input is in the following format:
<top>,<middle>,<bottom>
Each of <top>
, <middle>
, and <bottom>
is a string that will only ever contain the uppercase characters I
, V
, and X
. It will not contain spaces or any other characters. Each string represents three Roman numerals, thus resulting in a 3x3 matrix of numbers. However, these Roman numerals may (but not necessarily) be ambiguous. Allow me to illustrate this with an example. Consider the following example row of three Roman numerals, with no spaces between each number:
IVIIIIX
Because there are no spaces between the letters, there are two possibilites to the numbers here:
- 1, 8, 9 (
I VIII IX
) - 4, 3, 9 (
IV III IX
)
When you consider that all three rows of the matrix can be ambigious, there is the potential for there to be many different 3x3 matrixes from a single input.
Note that sequences such as 1, 7, 1, 9 (I VII I IX
) are not possible because each row will always represent three Roman numerals. Also note that the Roman numerals must be valid, so sequences such as 1, 7, 8 (I VII IIX
) are also not possible.
Output Description
Output:
- An integer
A
, whereA
is the number of unique 3x3 matrixes that can be formed from the ambigious input, and: - A truthy value if any of the unique 3x3 matrixes form a magic square, or:
- A falsy value if none of the unique 3x3 matrixes form a magic square.
The truthy and falsy values must be consistent. They are seperated by a comma.
Some explanation is required on what is counted as unique. As long as a matrix does not have exactly the same numbers in exactly the same positions as a previously found matrix, it is counted as unique. This means that reflections, etc. of previously found matrixes are counted as unique.
Example Inputs and Outputs
In these examples, I use true
as my truthy value and false
as my falsy value.
Input: VIIIIVI,IIIVVII,IVIXII
Output: 24,true
(The magic triangle is 8-1-6, 3-5-7, 4-9-2.)
Input: IIIXVIII,IVIII,VIIII
Output: 210,false
Extras
- You are not allowed to use inbuilt Roman Numeral conversion functions if your chosen language has one.