Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artemis: 'title': 'Simplified and Optimized Code' #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions src/llm_benchmark/algorithms/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ def sort_list(v: List[int]) -> None:
Args:
v (List[int]): List of integers
"""
for i in range(len(v)):
for j in range(i + 1, len(v)):
if v[i] > v[j]:
v[i], v[j] = v[j], v[i]
v.sort()

@staticmethod
def dutch_flag_partition(v: List[int], pivot_value: int) -> None:
Expand All @@ -23,16 +20,18 @@ def dutch_flag_partition(v: List[int], pivot_value: int) -> None:
v (List[int]): List of integers
pivot_value (int): Pivot value
"""
next_value = 0

for i in range(len(v)):
if v[i] < pivot_value:
v[i], v[next_value] = v[next_value], v[i]
next_value += 1
for i in range(next_value, len(v)):
if v[i] == pivot_value:
v[i], v[next_value] = v[next_value], v[i]
next_value += 1
low, mid, high = 0, 0, len(v) - 1

while mid <= high:
if v[mid] < pivot_value:
v[low], v[mid] = v[mid], v[low]
low += 1
mid += 1
elif v[mid] > pivot_value:
v[mid], v[high] = v[high], v[mid]
high -= 1
else:
mid += 1

@staticmethod
def max_n(v: List[int], n: int) -> List[int]:
Expand All @@ -45,15 +44,4 @@ def max_n(v: List[int], n: int) -> List[int]:
Returns:
List[int]: List of maximum n values
"""
tmp = v.copy()
ret = [-maxsize - 1] * n
for i in range(n):
max_val = tmp[0]
max_idx = 0
for j in range(1, len(tmp)):
if tmp[j] > max_val:
max_val = tmp[j]
max_idx = j
ret[i] = max_val
tmp.pop(max_idx)
return ret
return sorted(v, reverse=True)[:n]