Skip to content

Instantly share code, notes, and snippets.

@alucky0707
Created May 3, 2013 06:53
Show Gist options
  • Select an option

  • Save alucky0707/5507593 to your computer and use it in GitHub Desktop.

Select an option

Save alucky0707/5507593 to your computer and use it in GitHub Desktop.
AOJ 104
function main() {
var
i, j, w, h, t, l,
line, cache, map, isLoop,
len = input.length;
for(i = 0; i < len; i++) {
line = input[i].split(' ');
h = parseInt(line[0], 10);
w = parseInt(line[1], 10);
if(w === 0 && h === 0) break;
map = [];
cache = {};
for(j = 0; j < h; j++) map[j] = input[++i];
t = 0;
l = 0;
isLoop = false;
while(map[t].charAt(l) !== '.') {
cache[[t, l]] = true;
switch(map[t].charAt(l)) {
case '>':
l += 1;
break;
case '<':
l -= 1;
break;
case 'v':
t += 1;
break;
case '^':
t -= 1;
break;
}
if(cache[[t, l]]) {
isLoop = true;
break;
}
}
console.log(isLoop ? 'LOOP' : [l, t].join(' '));
}
}
var
input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
input += chunk;
});
process.stdin.on('end', function() {
input = input.split('\n');
main();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment