function* RowReduce(m, n, zero) {
let i;
let j;
let ip;
let sm = {
init: function() {
i = 1;
j = 1;
ip = 1;
return 'search';
},
search: function() {
if (zero(i, j)) {
i = i + 1;
if (i > m) {
i = ip;
j = j + 1;
}
if (j > n) return 'stop';
return 'search';
} else {
return 'pivot';
}
},
pivot: function() {
return 'scale';
},
scale: function() {
return 'swap';
},
swap: function() {
i = 1;
return 'eliminate';
},
eliminate: function() {
i = i + 1;
if (i > m) {
j = j + 1;
if (j > n) return 'stop';
ip = ip + 1;
i = ip;
if (i > m) return 'stop';
return 'search';
} else return 'eliminate';
}
};
let st = 'init';
do {
st = sm[st]();
yield { action: st, i, j, ip };
} while (st !== 'stop');
}