-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.js
23 lines (19 loc) · 675 Bytes
/
validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var vm = require('vm')
process.stdin.on('data', function(data) {
data = data.toString('utf8')
var packet = JSON.parse(data)
, input = packet.input
, solution= packet.solution
var exp = {}
vm.runInNewContext('exp.___x = '+solution, {'input':JSON.parse(input), 'exp':exp}, 'test')
var result = exp.___x
result = JSON.stringify(result, input)
// give this bitch a drain event. bitches love drain events.
if(result !== undefined) {
if(!process.stdout.write(result))
process.stdout.on('drain', process.exit.bind(process))
} else {
process.stderr.write('got undefined from '+data+', y\'all screwed up')
}
})
process.stdin.resume()