blob: c980b09aeb562f5f64a7574cce5d8757b4eaa7a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/python3
# Challenge 078
#
# TASK #2 > Left Rotation
# Submitted by: Mohammad S Anwar
# You are given array @A containing positive numbers and @B containing one or
# more indices from the array @A.
#
# Write a script to left rotate @A so that the number at the first index of @B
# becomes the first element in the array.
# Similarly, left rotate @A again so that the number at the second index of @B
# becomes the first element in the array.
#
# Example 1:
# Input:
# @A = (10 20 30 40 50)
# @B = (3 4)
# Explanation:
# a) We left rotate the 3rd index element (40) in the @A to make it 0th index
# member in the array.
# [40 50 10 20 30]
#
# b) We left rotate the 4th index element (50) in the @A to make it 0th index
# member in the array.
# [50 10 20 30 40]
#
# Output:
# [40 50 10 20 30]
# [50 10 20 30 40]
# Example 2:
# Input:
# @A = (7 4 2 6 3)
# @B = (1 3 4)
# Explanation:
# a) We left rotate the 1st index element (4) in the @A to make it 0th index
# member in the array.
# [4 2 6 3 7]
#
# b) We left rotate the 3rd index element (6) in the @A to make it 0th index
# member in the array.
# [6 3 7 4 2]
#
# c) We left rotate the 4th index element (3) in the @A to make it 0th index
# member in the array.
# [3 7 4 2 6]
#
# Output:
# [4 2 6 3 7]
# [6 3 7 4 2]
# [3 7 4 2 6]
import sys
A = [int(x) for x in sys.argv[1].split()]
B = [int(x) for x in sys.argv[2].split()]
for i in B:
a = [*A[i:], *A[:i]]
print("["+" ".join([str(x) for x in a])+"]")
|