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 arabic2moronic() that takes a positive integer (not a string) in the range [1, 3071] and returns a string consisting of the Moronic representation of that number. (Note that 3, 071 = (512 5) + (512 64) + (64 8) + (8 1) is FFFFFSFESIE.) To get started, consider how you could build up the output string piece-by-piece. Start with an empty string for the output. The basic idea is to take the input number, append one or more numerals to the output, and subtract out the value of those numerals from the input. As an example, suppose you start with 2000 as the input value. You subtract out 3 Fs (3 512 = 1536), leaving you with 464. Since 448 464 < 512, you then append SF to the output and subtract out 448 from the 464, leaving 16. 16 is expressed as EE, so we append EE to the result. The final answer is, therefore, FFFSFEE. So in general you proceed in this manner, starting with the input value, appending numerals to the output and correspondingly reducing the value of the input number until it becomes 0. First check if the value is 512 and if so, repeatedly subtract 512 from the input value until it becomes < 512. Each time you subtract 512, append one F to the output. Then look for the special subtractive combinations SF and SSF, appending numerals as needed and decreasing the input value. Next subtract out multiples of 64, appending the letter S to the output. Continue in this manner with smaller numerals and subtractive combinations of numerals until the input value is reduced to zero. Finally, return the representation of the original number as Moronic numerals.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
