You can use a loop to iterate through the list of roman numerals and detect consecutive ones. For this, you can convert the roman numerals to integers using a dictionary and then check if the current element is greater than or equal to the previous one. If they are consecutive, you can add them to a set, otherwise, create a new set. Here's an implementation:
main.swift688 chars21 lines
Here's an example usage:
main.swift204 chars4 lines
This will output [[I, I], [V], [X, X, X], [I, V], [I]]
, which is a list of sets of consecutive roman numerals.
gistlibby LogSnag