Context
To move (and not copy) a value A to another cell (here, next one), we need to add 1 A times to an empty cell and decrease A by 1 each timeInitial state
- Memory: A, 0
 - Cursor: first cell
 - Input: any
 
Process
- While first cell is not null, decrease first and increase second by 1, move back to first cell
 - Loop invariant: sum of both cells is A
 - When first cell equals 0, then second equals A
 
Code
[->+<]
Final state
- Memory: 0, A
 - Cursor: first cell
 - Input: any
 - Output: unchanged
 
Aucun commentaire:
Enregistrer un commentaire