Skip to content
Closed
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
19 changes: 8 additions & 11 deletions strings/min_cost_string_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def compute_transform_tables(
insert_cost: int,
) -> tuple[list[list[int]], list[list[str]]]:
"""
Finds the most cost efficient sequence
Finds the most cost-efficient sequence
for converting one string into another.

>>> compute_transform_tables("", "", 1, 2, 3, 3)
([[0]], [['0']])
Comment on lines +24 to +25

>>> costs, operations = compute_transform_tables("cat", "cut", 1, 2, 3, 3)
>>> costs[0][:4]
[0, 3, 6, 9]
Expand All @@ -30,10 +33,8 @@ def compute_transform_tables(
['0', 'Ic', 'Iu', 'It']
>>> operations[3][:4]
['Dt', 'Dt', 'Rtu', 'Ct']

>>> compute_transform_tables("", "", 1, 2, 3, 3)
([[0]], [['0']])
"""

source_seq = list(source_string)
destination_seq = list(destination_string)
len_source_seq = len(source_seq)
Expand Down Expand Up @@ -88,20 +89,16 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
>>> assemble_transformation(ops, x, y-1)
['Cc', 'Da', 'Rtu']

>>> ops1 = [['0']]
>>> x1 = len(ops1) - 1
>>> y1 = len(ops1[0]) - 1
>>> assemble_transformation(ops1, x1, y1)
>>> assemble_transformation([['0']], 0, 0)
[]

>>> ops2 = [['0', 'I1', 'I2', 'I3'],
... ['D1', 'C1', 'I2', 'I3'],
... ['D2', 'D2', 'R23', 'R23']]
>>> x2 = len(ops2) - 1
>>> y2 = len(ops2[0]) - 1
>>> assemble_transformation(ops2, x2, y2)
>>> assemble_transformation(ops2, 2, 3)
['C1', 'I2', 'R23']
"""

if i == 0 and j == 0:
return []
elif ops[i][j][0] in {"C", "R"}:
Expand Down
Loading