Skip to content

Instantly share code, notes, and snippets.

@tyage
Created December 19, 2010 08:07
Show Gist options
  • Save tyage/747195 to your computer and use it in GitHub Desktop.
Save tyage/747195 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
sys = require('sys');
var result = function (file) {
fs.readFile(file, "utf-8", function (err, data) {
err && sys.print(err)
r = '';
n = +data.split('\r\n')[0];
max = +data.split('\r\n')[1];
data.split('\r\n').forEach(function (val, i) {
if (i < 2 || i > max+1) {
return false;
}
var xy = val.split(' '),
x = +xy[0],
y = +xy[1],
color = check(x, y, n);
r += color+'\n';
})
fs.writeFile(file, r);
});
}
function check (x, y, n) {
if (y > n/2) y = n-y+1;
if (x > n/2) x = n-x+1;
return (x >= y+1 && x <= n-y) ? (y%3 || 3) : (x%3 || 3);
}
result('2011-yo-t3-in1.txt')
result('2011-yo-t3-in2.txt')
result('2011-yo-t3-in3.txt')
result('2011-yo-t3-in4.txt')
result('2011-yo-t3-in5.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment