mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
Compare commits
2 Commits
885e8db94a
...
48e0f35676
Author | SHA1 | Date | |
---|---|---|---|
|
48e0f35676 | ||
|
4eccaec9ff |
@ -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 enumerate(timings):
|
for current_element in timings:
|
||||||
if (
|
if (
|
||||||
isinstance(current_element, str)
|
isinstance(current_element, str)
|
||||||
and current_element.replace(".", "", 1).isdigit()
|
and current_element.replace(".", "", 1).isdigit()
|
||||||
@ -41,6 +41,7 @@ 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:
|
||||||
@ -55,7 +56,8 @@ 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