Reconstruction.traceback: def of bend-edit-distance@0.2.2.0 Import: import bend-edit-distance@0.2.2.0/src/Reconstruction.bend as Reconstruction Lines 79-100 of bend-edit-distance@0.2.2.0/src/Reconstruction.bend: https://jend.leeeet.dev/read.txt?path=bend-edit-distance@0.2.2.0/src/Reconstruction.bend&start_line=79&end_line=100 import Base import bend-edit-distance@0.2.2.0/EdlibTypes.bend as E # Rows and their operations are reversed so left moves consume the current # row directly. Entering the row above skips only its unused right suffix. # Including boundary rows/columns handles all-insertion/deletion paths. def traceback(fuel: Nat, current: List<&2, TraceCell>, previous: List<&2, List<&2, TraceCell>>, +width: Nat, +column: Nat, operations: List<&2, E.Operation>) -> List<&2, E.Operation>: match fuel current previous: case 0n _ _: operations case 1n+p _ Nil{}: List.append(&2, E.Operation, List.replicate(E.Operation, column, E.Delete{}), operations) case 1n+p Nil{} _: operations case 1n+p TraceCell{_, E.Insert{}} <> _ row <> rest: traceback(p, List.drop(&2, TraceCell, row, Nat.sub(width, column)), rest, width, column, E.Insert{} <> operations) case 1n+p TraceCell{_, E.Delete{}} <> tail +rows: traceback(p, tail, rows, width, Nat.sub(column, 1n), E.Delete{} <> operations) case 1n+p TraceCell{_, operation} <> _ row <> rest: +next_column = Nat.sub(column, 1n) traceback(p, List.drop(&2, TraceCell, row, Nat.sub(width, next_column)), rest, width, next_column, operation <> operations) Uses (8): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.drop https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.replicate https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.sub https://jend.leeeet.dev/definition.txt?path=bend-edit-distance@0.2.2.0/EdlibTypes.bend&name=Operation https://jend.leeeet.dev/definition.txt?path=bend-edit-distance@0.2.2.0/src/Reconstruction.bend&name=TraceCell