Skip to content

Commit

Permalink
Update solution.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Nov 7, 2024
1 parent 80d913b commit a65f6d3
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions kyu_4/range_extraction/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,14 @@ def solution(args: list) -> str:

for i, a in enumerate(args):

# case 1
if current[1] == a:
continue

if a == current[1] + 1:
current[1] = a
current[2] = False
else:
current[2] = True

if abs(current[1] - current[0]) >= 2 and i != 1:
result += str(current[0]) + '-' + str(current[1]) + ','
else:
result += str(current[0]) + ','
if current[0] != current[1]:
result += str(current[1]) + ','

current[0] = a
current[1] = a
# case 2
result = case_2(a, i, current, result)

# case 3
if i == len(args) - 1 and not current[2]:
if current[1] + 1 == a:
current[1] = a
Expand All @@ -46,7 +35,36 @@ def solution(args: list) -> str:
elif current[0] != current[1]:
result += ',' + str(current[1])

# case 4
if i == len(args) - 1 and current[-1] != a and current[2]:
result += str(a)

return result


def case_2(a: int, i: int, current: list, result: str) -> str:

Check notice on line 45 in kyu_4/range_extraction/solution.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_4/range_extraction/solution.py#L45

Argument name "a" doesn't conform to snake_case naming style (invalid-name)
"""
Case #2
:param i:
:param a:
:param current:
:param result:
:return:
"""
if a == current[1] + 1:
current[1] = a
current[2] = False
else:
current[2] = True

if abs(current[1] - current[0]) >= 2 and i != 1:
result += str(current[0]) + '-' + str(current[1]) + ','
else:
result += str(current[0]) + ','
if current[0] != current[1]:
result += str(current[1]) + ','

current[0] = a
current[1] = a

return result

0 comments on commit a65f6d3

Please sign in to comment.