Skip to content

Instantly share code, notes, and snippets.

@CarlosX
Created June 17, 2016 08:03
Show Gist options
  • Save CarlosX/0771febf090e1ca949bf3da20f54a302 to your computer and use it in GitHub Desktop.
Save CarlosX/0771febf090e1ca949bf3da20f54a302 to your computer and use it in GitHub Desktop.
Ejemplo Cajero
var arc = [[10, 10, 10, 10, 10],
[20, 20, 20, 20, 20],
[50, 50, 50, 50, 50],
[100, 100, 100, 100, 100],
[200, 200, 200, 200, 200]];
function verf(arr, x) {
for(var y = 0; y < 5; y++)
if(arr[x][y] !== 0)
return y;
return -1;
}
var req = 560;
for(var i = 4; i > -1; i--) {
for(var y = 0; y < 5;) {
var c = verf(arc, i);
if(c > -1) {
var cf = arc[i][c];
if(cf == req) {
arc[i][c] = 0;
req -= cf;
break;
} else if(req > cf) {
req = req - cf;
arc[i][c] = 0;
} else if(req < cf) {
break;
}
} else {
y++;
}
}
}
if(req > 0)
console.log("fallo " + req);
console.log(arc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment