Assembles the transformations based on the ops table. >>> ops = [['0', 'Ic', 'Iu', 'It'], ... ['Dc', 'Cc', 'Iu', 'It'], ... ['Da', 'Da', 'Rau', 'Rat'], ... ['Dt', 'Dt', 'Rtu', 'Ct']] >>> x = len(ops) - 1 >>> y = len(ops[0]) - 1 >>> assemble_tran
(ops: list[list[str]], i: int, j: int)
| 74 | |
| 75 | |
| 76 | def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]: |
| 77 | """ |
| 78 | Assembles the transformations based on the ops table. |
| 79 | |
| 80 | >>> ops = [['0', 'Ic', 'Iu', 'It'], |
| 81 | ... ['Dc', 'Cc', 'Iu', 'It'], |
| 82 | ... ['Da', 'Da', 'Rau', 'Rat'], |
| 83 | ... ['Dt', 'Dt', 'Rtu', 'Ct']] |
| 84 | >>> x = len(ops) - 1 |
| 85 | >>> y = len(ops[0]) - 1 |
| 86 | >>> assemble_transformation(ops, x, y) |
| 87 | ['Cc', 'Rau', 'Ct'] |
| 88 | |
| 89 | >>> ops1 = [['0']] |
| 90 | >>> x1 = len(ops1) - 1 |
| 91 | >>> y1 = len(ops1[0]) - 1 |
| 92 | >>> assemble_transformation(ops1, x1, y1) |
| 93 | [] |
| 94 | |
| 95 | >>> ops2 = [['0', 'I1', 'I2', 'I3'], |
| 96 | ... ['D1', 'C1', 'I2', 'I3'], |
| 97 | ... ['D2', 'D2', 'R23', 'R23']] |
| 98 | >>> x2 = len(ops2) - 1 |
| 99 | >>> y2 = len(ops2[0]) - 1 |
| 100 | >>> assemble_transformation(ops2, x2, y2) |
| 101 | ['C1', 'I2', 'R23'] |
| 102 | """ |
| 103 | if i == 0 and j == 0: |
| 104 | return [] |
| 105 | elif ops[i][j][0] in {"C", "R"}: |
| 106 | seq = assemble_transformation(ops, i - 1, j - 1) |
| 107 | seq.append(ops[i][j]) |
| 108 | return seq |
| 109 | elif ops[i][j][0] == "D": |
| 110 | seq = assemble_transformation(ops, i - 1, j) |
| 111 | seq.append(ops[i][j]) |
| 112 | return seq |
| 113 | else: |
| 114 | seq = assemble_transformation(ops, i, j - 1) |
| 115 | seq.append(ops[i][j]) |
| 116 | return seq |
| 117 | |
| 118 | |
| 119 | if __name__ == "__main__": |
no test coverage detected