mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
Compare commits
No commits in common. "48e0f356769056089caf19584f67762b961cc04b" and "885e8db94a3c7cd85f491da0393bf503bebc56d0" have entirely different histories.
48e0f35676
...
885e8db94a
@ -27,8 +27,8 @@ def split_list(
|
|||||||
ValueError: Timings must be a list of numbers
|
ValueError: Timings must be a list of numbers
|
||||||
|
|
||||||
"""
|
"""
|
||||||
valid_timings: list[int | float] = []
|
valid_timings = list[int | float]
|
||||||
for current_element in timings:
|
for current_element in enumerate(timings):
|
||||||
if (
|
if (
|
||||||
isinstance(current_element, str)
|
isinstance(current_element, str)
|
||||||
and current_element.replace(".", "", 1).isdigit()
|
and current_element.replace(".", "", 1).isdigit()
|
||||||
@ -41,7 +41,6 @@ def split_list(
|
|||||||
elif isinstance(current_element, (int, float)):
|
elif isinstance(current_element, (int, float)):
|
||||||
valid_timings.append(abs(current_element))
|
valid_timings.append(abs(current_element))
|
||||||
else:
|
else:
|
||||||
print(type(current_element))
|
|
||||||
raise ValueError("Timings must be a list of numbers")
|
raise ValueError("Timings must be a list of numbers")
|
||||||
|
|
||||||
if len(valid_timings) == 0:
|
if len(valid_timings) == 0:
|
||||||
@ -56,8 +55,7 @@ def split_list(
|
|||||||
indices = [j for j in range(n) if i & (1 << j) != 0]
|
indices = [j for j in range(n) if i & (1 << j) != 0]
|
||||||
distributed_timings_1 = [valid_timings[j] for j in indices]
|
distributed_timings_1 = [valid_timings[j] for j in indices]
|
||||||
distributed_timings_2 = [valid_timings[j] for j in range(n) if j not in indices]
|
distributed_timings_2 = [valid_timings[j] for j in range(n) if j not in indices]
|
||||||
diff = abs(sum(distributed_timings_1) - sum(distributed_timings_2))
|
diff = abs(sum([distributed_timings_1]) - sum(distributed_timings_2))
|
||||||
|
|
||||||
if diff < smallest_diff:
|
if diff < smallest_diff:
|
||||||
smallest_diff = diff
|
smallest_diff = diff
|
||||||
result = (
|
result = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user