Skip to content

Instantly share code, notes, and snippets.

@Crenshinibon
Created May 2, 2013 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crenshinibon/5501748 to your computer and use it in GitHub Desktop.
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
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