JonoCode9374 had almost completely implemented my language EnScript except for the CHS command. I was impatient of waiting for them to implement this command, so I chose to put this question here.
Write a solution that takes an input and returns the chased output. Standard loopholes are forbidden.
This is the CHS instruction reference copied from the website:
CHS means to chase all of the numbers inside an accumulator.
Chasing a number means to move a number forward inside the accumulator that-number of times.
Chasing an accumulator means to move all of the numbers inside an accumulator from the lowest number (0) to the highest number (9) sequentially, without repeating. Sequentially means: the values are moved in a sequential order that was presented in the accumulator, which is from left to right.
Here is an important note: The number is still there while the number is moved, and that number will be removed from the original number if and only if the currently chased number has been put in place.
Here is an extra note: A number with the lower magnitude should be "chased" first in the accumulator. For example, the number 1 should be chased prior to the numbers 2, 3, 4, etc.
One more note: Accumulators should be unbounded, i.e. without an upper limit. Also, they cannot and should not support negative numbers. The implementation does not have to detect that; it can assume that the input is valid.
The type of the accumulators should be in the unbounded integer form; The value of an accumulator should not be a floating-point integer.
If zeroes are in front of the number at the end of the process, they are deleted by default.
- Take A=123 as an example.
1will move forward 1 number. (It will be inserted behind
2.) So, the number will be
213. 1 will be marked as chased.
2will also be moved. It will be moved forward twice, so the number will be
3will also be chased. It will move forward 1 time (finding that the end of the list is reached), and then it will go to the place before
1. Then, it will go back to where it was.
- Accumulator A "chased" will be
3112 as an example, which is quite vague. Some people may ask: which '1' gets "chased" first?
Answer: The first '1' from left to right gets "chased" first. See the notes from above.
So, the chase after 1 iteration will be: 31121324→31131224
Another example. 10 will be chased to 01, as 0 cannot be moved and 1 will be moved for 1 digit. Then, this preceding 0 will be deleted, leaving a 1 to the accumulators.
123 -> 132 12345 -> 14253 3141 -> 3141 123123 -> 312132 94634 -> 96434 1277 -> 7172 10 -> 1
Please comment for me if this question is too vague!