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.
  • Value 1 will move forward 1 number. (It will be inserted behind 2.) So, the number will be 213. 1 will be marked as chased.
  • Likewise, 2 will also be moved. It will be moved forward twice, so the number will be 132.
  • 3 will 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 132.

Also, take 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.

Test Cases:

123 -> 132
12345 -> 14253
3141 -> 3141
123123 -> 312132
94634 -> 96434
1277 -> 7172
10 -> 1

Please comment for me if this question is too vague!

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – DJMcMayhem Jun 7 '19 at 17:01
  • \$\begingroup\$ For added clarity I would suggest showing the steps involved for each of your test cases. \$\endgroup\$ – Shaggy Jun 8 '19 at 0:21
  • \$\begingroup\$ Why does the EnScript link lead to the talk page? \$\endgroup\$ – CalculatorFeline Jun 10 '19 at 4:06

Python 3, 262 ... 170 bytes

This program outputs the result via Stderr.

I'm a bit out of practice at golfing, since I have not been too active lately, so I'm sure it can be golfed more.

L=[[c,int(c)]for c in input()]
while 1:i=L.index(min([x for x in L if x[1]]or exit(str(int("".join(x[0]for x in L))))));L[i][1]-=1;q=i+1<len(L)and-~i;L.insert(q,L.pop(i))

Try it online


# Index to shift, Times remaining
def Shift(i, t):
    if t<1:
    if i+1<len(L):
L=[[c,1]for c in input()]
while 1:
    t=[x for x in L if x[1]]or exit("".join(x[0]for x in L).lstrip('0'))
    i=L.index(min(t,key=lambda x:x[0]))
  • \$\begingroup\$ str(int(...)) is two bytes shorter than ....lstrip('0') \$\endgroup\$ – ArBo Jun 9 '19 at 8:29
  • \$\begingroup\$ @UserA The comments on that page seem to suggest that the short version doesn't actually work. Also, that's just a utility function used in the longer code below, which is actually the solution. Mine looks shorter than that. \$\endgroup\$ – mbomb007 Jun 13 '19 at 15:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.