New Terminal Output:

root@f3f8d6319494:/app# python3 -c "
> import struct
>
> with open('/app/frames.tza', 'rb') as f:
>     f.read(4)
>     w, h = struct.unpack('<HH', f.read(4))
>     n_frames, max_bytes = struct.unpack('<II', f.read(8))
>
>     frames = []
>     for i in range(n_frames):
>         frames.append(f.read(w*h))
>
> # Analyze a changed line (frame 3->4, row 2)
> prev_row = frames[3][2*w:3*w]
> curr_row = frames[4][2*w:3*w]
> changes = sum(1 for j in range(w) if prev_row[j] != curr_row[j])
> print(f'Row 2 changes: {changes} out of {w}')
>
> # Cost of EL + rewrite line
> # ESC[2K = 4 bytes, then write w chars
> cost_erase_rewrite = 4 + w
> print(f'Cost EL+rewrite: {cost_erase_rewrite}')
>
> # Cost of cursor positioning + changes
> # ESC[r;cH = ~7 bytes per run
> # Find runs in this row
> runs = 0
> in_run = False
> for c in range(w):
>     if prev_row[c] != curr_row[c]:
>         if not in_run:
>             in_run = True
>             runs += 1
>     else:
>         in_run = False
> cost_partial = runs * 7 + changes
> print(f'Cost partial ({runs} runs): {cost_partial}')
>
> # Find all changed rows for frame 3->4
> changed_rows = []
> for r in range(h):
>     if frames[3][r*w:(r+1)*w] != frames[4][r*w:(r+1)*w]:
>         changed_rows.append(r)
> print(f'Changed rows in frame 3->4: {changed_rows}')
> "
Row 2 changes: 24 out of 80
Cost EL+rewrite: 84
Cost partial (7 runs): 73
Changed rows in frame 3->4: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
root@f3f8d6319494:/app#
