Skip to content

Commit 644073d

Browse files
authored
Merge branch 'master' into patch-2
2 parents 0abd90a + 788d95b commit 644073d

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
libhdf5-dev
1818
libopenblas-dev
1919
- uses: actions/checkout@v5
20-
- uses: astral-sh/setup-uv@v6
20+
- uses: astral-sh/setup-uv@v7
2121
with:
2222
enable-cache: true
2323
cache-dependency-glob: uv.lock

.github/workflows/project_euler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
libhdf5-dev
2323
libopenblas-dev
2424
- uses: actions/checkout@v5
25-
- uses: astral-sh/setup-uv@v6
25+
- uses: astral-sh/setup-uv@v7
2626
- uses: actions/setup-python@v6
2727
with:
2828
python-version: 3.14
@@ -40,7 +40,7 @@ jobs:
4040
libhdf5-dev
4141
libopenblas-dev
4242
- uses: actions/checkout@v5
43-
- uses: astral-sh/setup-uv@v6
43+
- uses: astral-sh/setup-uv@v7
4444
- uses: actions/setup-python@v6
4545
with:
4646
python-version: 3.14

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v5
15-
- uses: astral-sh/setup-uv@v6
15+
- uses: astral-sh/setup-uv@v7
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
libhdf5-dev
3434
libopenblas-dev
3535
- uses: actions/checkout@v5
36-
- uses: astral-sh/setup-uv@v6
36+
- uses: astral-sh/setup-uv@v7
3737
- uses: actions/setup-python@v6
3838
with:
3939
python-version: 3.14
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
def rotate_array(arr: list[int], steps: int) -> list[int]:
2+
"""
3+
Rotates a list to the right by steps positions.
4+
5+
Parameters:
6+
arr (List[int]): The list of integers to rotate.
7+
steps (int): Number of positions to rotate. Can be negative for left rotation.
8+
9+
Returns:
10+
List[int]: Rotated list.
11+
12+
Examples:
13+
>>> rotate_array([1, 2, 3, 4, 5], 2)
14+
[4, 5, 1, 2, 3]
15+
>>> rotate_array([1, 2, 3, 4, 5], -2)
16+
[3, 4, 5, 1, 2]
17+
>>> rotate_array([1, 2, 3, 4, 5], 7)
18+
[4, 5, 1, 2, 3]
19+
>>> rotate_array([], 3)
20+
[]
21+
"""
22+
23+
n = len(arr)
24+
if n == 0:
25+
return arr
26+
27+
steps = steps % n
28+
29+
if steps < 0:
30+
steps += n
31+
32+
def reverse(start: int, end: int) -> None:
33+
"""
34+
Reverses a portion of the list in place from index start to end.
35+
36+
Parameters:
37+
start (int): Starting index of the portion to reverse.
38+
end (int): Ending index of the portion to reverse.
39+
40+
Returns:
41+
None
42+
43+
Examples:
44+
>>> example = [1, 2, 3, 4, 5]
45+
>>> def reverse_test(arr, start, end):
46+
... while start < end:
47+
... arr[start], arr[end] = arr[end], arr[start]
48+
... start += 1
49+
... end -= 1
50+
>>> reverse_test(example, 0, 2)
51+
>>> example
52+
[3, 2, 1, 4, 5]
53+
>>> reverse_test(example, 2, 4)
54+
>>> example
55+
[3, 2, 5, 4, 1]
56+
"""
57+
58+
while start < end:
59+
arr[start], arr[end] = arr[end], arr[start]
60+
start += 1
61+
end -= 1
62+
63+
reverse(0, n - 1)
64+
reverse(0, steps - 1)
65+
reverse(steps, n - 1)
66+
67+
return arr
68+
69+
70+
if __name__ == "__main__":
71+
examples = [
72+
([1, 2, 3, 4, 5], 2),
73+
([1, 2, 3, 4, 5], -2),
74+
([1, 2, 3, 4, 5], 7),
75+
([], 3),
76+
]
77+
78+
for arr, steps in examples:
79+
rotated = rotate_array(arr.copy(), steps)
80+
print(f"Rotate {arr} by {steps}: {rotated}")

0 commit comments

Comments
 (0)