Python3 Program to Generate all rotations of a number Last Updated : 05 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Given an integer n, the task is to generate all the left shift numbers possible. A left shift number is a number that is generated when all the digits of the number are shifted one position to the left and the digit at the first position is shifted to the last.Examples: Input: n = 123 Output: 231 312Input: n = 1445 Output: 4451 4514 5144 Approach: Assume n = 123.Multiply n with 10 i.e. n = n * 10 = 1230.Add the first digit to the resultant number i.e. 1230 + 1 = 1231.Subtract (first digit) * 10k from the resultant number where k is the number of digits in the original number (in this case, k = 3).1231 - 1000 = 231 is the left shift number of the original number.Below is the implementation of the above approach: Python3 # Python3 implementation of the approach # function to return the count of digit of n def numberofDigits(n): cnt = 0 while n > 0: cnt += 1 n //= 10 return cnt # function to print the left shift numbers def cal(num): digit = numberofDigits(num) powTen = pow(10, digit - 1) for i in range(digit - 1): firstDigit = num // powTen # formula to calculate left shift # from previous number left = (num * 10 + firstDigit - (firstDigit * powTen * 10)) print(left, end = " ") # Update the original number num = left # Driver code num = 1445 cal(num) # This code is contributed # by Mohit Kumar Output4451 4514 5144Time Complexity: O(log10(num))Auxiliary Space: O(1)Please refer complete article on Generate all rotations of a number for more details! Comment More infoAdvertise with us Next Article Python3 Program to Generate all rotations of a number K kartik Follow Improve Article Tags : Mathematical Python Python Programs DSA Akamai number-digits rotation +3 More Practice Tags : Mathematicalpython Similar Reads Python3 Program to Rotate bits of a number Bit Rotation: A rotation (or circular shift) is an operation similar to a shift except that the bits that fall off at one end are put back to the other end. In the left rotation, the bits that fall off at the left end are put back at the right end. In the right rotation, the bits that fall off at th 3 min read Python3 Program to Rotate digits of a given number by K INTRODUCTION:One important point to consider when working with the algorithm to rotate the digits of a given number by k positions is the time complexity.If we were to implement this algorithm using the approach shown in the previous example, the time complexity would be O(n), where n is the number 4 min read Python3 Program to Print all possible rotations of a given Array Given an integer array arr[] of size N, the task is to print all possible rotations of the array.Examples: Input: arr[] = {1, 2, 3, 4} Output: {1, 2, 3, 4}, {4, 1, 2, 3}, {3, 4, 1, 2}, {2, 3, 4, 1} Explanation: Initial arr[] = {1, 2, 3, 4} After first rotation arr[] = {4, 1, 2, 3} After second rotat 3 min read Python3 Program to Count rotations divisible by 4 Given a large positive number as string, count all rotations of the given number which are divisible by 4. Examples: Input: 8Output: 1Input: 20Output: 1Rotation: 20 is divisible by 4 02 is not divisible by 4Input : 13502Output : 0No rotation is divisible by 4Input : 43292816Output : 55 rotations are 2 min read Python3 Program to Check if two numbers are bit rotations of each other or not Given two positive integers x and y, check if one integer is obtained by rotating bits of other. Input constraint: 0 < x, y < 2^32 Bit Rotation: A rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end.More info 3 min read Like