011 Rosebud 64
You are approached by an eccentric billionaire with an interesting proposition. He wants you to write an emulator for the Rosebud 64, an obscure gaming console he played as a child. He has purchased the rights to the console and its game catalogue, and secured ROM dumps of all the games.
You accept the billionaire's offer, but as you begin analysing the ROM dumps, you notice something peculiar—the Rosebud 64 seems to use a proprietary compression scheme for its game data.
The Rosebud 64 compression scheme works as follows:
- Data is encoded as alphanumeric characters, where a number
Nindicates that the following character should be repeatedNtimes. For example, given the compressed stringa3bcthe uncompressed string should beabbbc. - Groups of characters, delimited with parentheses, can also be repeated; for
example, given the compressed string
a3(ab)cthe uncompressed string should beaabababc. - Groups can also contain both numbers and other groups, e.g.
2(3y2(ab))zshould decompress toyyyababyyyababz
Your task is to write a program that decompresses strings using the Rosebud 64
compression scheme. You can assume that all letters are lowercase (a-z), and
N is always greater than 0.
Here are some example inputs and outputs:
Input: 10a
Output: aaaaaaaaaa
Input: 2(a2(bc))
Output: abcbcabcbc
Input: x2(yz3a)b
Output: xyzaaayzaaab
Input: 2(2(2(a)))
Output: aaaaaaaa
Input: 2(3y2(ab))z
Output: yyyababyyyababz
Good luck!