Skip to content

Instantly share code, notes, and snippets.

@tyage
Created December 19, 2010 02:16
Show Gist options
  • Save tyage/747044 to your computer and use it in GitHub Desktop.
Save tyage/747044 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
sys = require('sys');
fs.readFile('1.txt', "utf-8", function (err, data) {
data = data.split('\n');
var nm = data[0].split(' '),
n = +nm[0],
m = +nm[1],
step = 1,
steps = data.slice(1, n+1),
dices = data.slice(n);
for (i in dices) {
step += (+dices[i]);
if (step >= n) {
fs.writeFile('1.txt', i+"");
break
}
step += (+steps[step-1]);
sys.print(i+':'+step+'\n');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment