Given a positive number n
, rotate its base-10 digits m
positions rightward. That is, output the result of m
steps of moving the last digit to the start. The rotation count m
will be a non-negative integer.
You should remove leading zeroes in the final result, but not in any of the intermediate steps. For example, for the test case 100,2 => 1
, we first rotate to 010
, then to 001
, then finally drop the leading zeroes to get 1
.
Tests
n,m => Output
123,1 => 312
123,2 => 231
123,3 => 123
123,4 => 312
1,637 => 1
10,1 => 1
100,2 => 1
10,2 => 10
110,2 => 101
123,0 => 123
9998,2 => 9899
add ecx,ecx
/ror eax, cl
rotates byn
2-bit digits, in 4 bytes of machine code. Nothing in the question actually says you have to rotate base-10 digits, which would be inconvenient if you get input as anint
or something. But I suspect you meant that? \$\endgroup\$