Question
PLEASE CODE IN PYTHON Youve heard of Roman numerals, but have you heard of Moronic numerals? Probably not because weve invented them for this homework
PLEASE CODE IN PYTHON
Youve heard of Roman numerals, but have you heard of Moronic numerals? Probably not because weve invented them for this homework assignment. Moronic numerals are similar to Roman numerals in that numbers are formed by combining symbols and adding the values. In Moronic numerals, each numeral has a fixed value representing a power of 8 (rather than a power of 10 or half of a power of 10, as in Roman numerals):
Symbol: I, E, S, F
Value: 1, 8, 64, 512
Symbols are placed from left to right in order of value, starting with the largest. For example, FFFFSSSEEEEEIIII is 2, 284 : (512 4) + (64 3) + (8 5) + (4 1). In a few specific cases, to avoid having six or more characters being repeated in succession (such as IIIIII or EEEEEE), subtractive notation is used, as in this table:
Number: 6, 7, 48 (64 - 28), 56 (64 - 18), 384 (512 - 264), 448 (512 - 164)
Notation: IIE, IE, EES, ES, SSF, SF
Thus, there must never be more than five copies of a single symbol next to each other in a Moronic numeral. Moreover, it is illegal for a symbol to be used in an additive manner after it has been used in a subtractive manner. To see why this is true, consider Roman numerals for a moment. CXC (190) is valid because C is used first in an additive way and then in a subtractive way. But XCXX is invalid because X is first used in a subtractive way and then in an additive way. In Moronic numerals, examples of analogous invalid cases would be expressions like SFSSS, ESEE and IEIII
Write a function moronic2arabic() that takes a string argument consisting of properly-formatted Moronic numerals and returns the integer represented by the Moronic numerals. The converted integer is guaranteed to be in the range [1, 3071]. Process the input string from left-to-right, looking for combinations of numerals (doubles and triples that indicate subtraction) or single numerals that are not involved in subtraction. Add the value of the numeral combination or singleton to a running total and move on to the remainder of the input string. To find combinations of numerals, examine two or three characters simultaneously (e.g., SSF or IE), taking care not to overrun the end of the string while doing this. Proceed in this manner until the rightmost numeral has been processed.
Examples:
Function Call, Return Value
moronic2arabic(SIE), 71
moronic2arabic(SSSSSEESIIII), 372
moronic2arabic(FSSFIIII), 900
moronic2arabic(FFFIIE), 1542
moronic2arabic(FFFSFEIE), 1999
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started