A list is created by writing all the positive integers from 1 to 3999 inclusively in Roman numerals in order.
Devise an algorithm that isolates all the perfect squares from the list and writes the corresponding square roots in Roman numerals.
Assume that:
- The algorithm will process a Roman Numeral directly without converting it to decimal when determining if it is a perfect square.
- The algorithm knows how to derive the square root of an integer.
- The algorithm is aware of the corresponding base ten value of all the six individual Roman numerals I, V, X, L, C, D, and M. For example, it knows that: X=10, C=100, D=500 and, so on.
- The algorithm knows the corresponding base ten value of a given Roman numeral representation. For example, it knows that: XVI = 10+5+1 =16
Since you have an array or list of Roman Numerals, in order, you can exploit the index of the list, since you know (or do you?) that the difference between subsequent squares is the next odd number.
So starting from zero, add the first odd number (1) to get both the index of the square and of it's square root.
Then increment the index for the square root by 1 each time, but increment the index for the next square by the next odd number.
Then you get the Roman Numeral from the array or list by means of the index.
Edited on May 15, 2022, 10:31 am
|
Posted by Larry
on 2022-05-15 10:30:12 |