Created
May 2, 2013 11:58
-
-
Save Crenshinibon/5501748 to your computer and use it in GitHub Desktop.
Script to generate TSP test data for Olimex's Programming Challenge No. 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs') | |
fileName = process.argv[2] | |
outFile = if process.argv[3] then process.argv[3] else fileName + '.oli' | |
data = fs.readFileSync(fileName, 'utf8') | |
fs.writeFileSync(outFile, 'T55\n') | |
lines = data.split '\n' | |
dataFound = false | |
base = 100 | |
scale = (pos, base) -> | |
Math.round pos / base * 100000, 0 | |
pos | |
lines.forEach (l) -> | |
parts = l.trim().split(' ') | |
if parts[0] is 'DIMENSION' | |
base = parts[2] | |
if l.trim() is 'EOF' | |
dataFound = false | |
if dataFound | |
x = '' + scale(parts[1],base) | |
while x.length < 6 | |
x = "0" + x | |
y = '' + scale(parts[2],base) | |
while y.length < 6 | |
y = "0" + y | |
fs.appendFile outFile, "X" + x + " Y" + y + "\n" | |
if l.trim() is 'NODE_COORD_SECTION' | |
dataFound = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment