14 lines
433 B
Python
14 lines
433 B
Python
def circular_shift(x, shift):
|
|
"""Circular shift the digits of the integer x, shift the digits right by shift
|
|
and return the result as a string.
|
|
If shift > number of digits, return digits reversed.
|
|
>>> circular_shift(12, 1)
|
|
"21"
|
|
>>> circular_shift(12, 2)
|
|
"12"
|
|
"""
|
|
s = str(x)
|
|
if shift > len(s):
|
|
return s[::-1]
|
|
shift = shift % len(s)
|
|
return s[-shift:] + s[:-shift] if shift else s |