Last active
April 5, 2020 09:06
-
-
Save 0xorial/6f3b93b1c3820f5023297fcf9fc83c9a to your computer and use it in GitHub Desktop.
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
const { spawn, fork } = require("child_process"); | |
const readline = require("readline"); | |
async function* c(x) { | |
for await (const line of x) { | |
yield line; | |
} | |
} | |
async function readLine(g) { | |
const l = await g.next(); | |
if (l.done) { | |
throw new Error("read past end of file"); | |
} | |
return l.value; | |
} | |
const runner = spawn( | |
"C:\\Users\\user\\Anaconda3\\envs\\untitled\\python.exe", | |
["d-runner.py", "1"], | |
{ | |
stdio: "pipe", | |
} | |
); | |
const runnerReader = readline.createInterface({ | |
input: runner.stdout, | |
output: runner.stdin, | |
}); | |
const runnerGenerator = c(runnerReader); | |
const sln = fork("D.js", undefined, { | |
stdio: "pipe", | |
}); | |
const slnReader = readline.createInterface({ | |
input: sln.stdout, | |
output: sln.stdin, | |
}); | |
const slnGenerator = c(slnReader); | |
async function run() { | |
while (true) { | |
const runnerLine = await readLine(runnerGenerator); | |
console.log('runner says: ' + runnerLine); | |
sln.stdin.write(runnerLine + '\n'); | |
const slnLine = await readLine(slnGenerator); | |
console.log('solution says: ' + slnLine); | |
runner.stdin.write(slnLine + '\n'); | |
} | |
} | |
run(); |
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
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
async function* c(x){ | |
for await (const line of rl) { | |
yield line; | |
} | |
} | |
const g = c(rl); | |
async function readLine(){ | |
const l = await g.next(); | |
if (l.done) { | |
throw new Error('read past end of file'); | |
} | |
return l.value; | |
} | |
async function readInt() { | |
return parseInt(await readLine(), 10); | |
} | |
async function readIntArray() { | |
const line = await readLine(); | |
return line.split(' ').map(x => parseInt(x, 10)); | |
} | |
async function run() { | |
const T = await readInt(); | |
for (let i = 0; i < T; i++) { | |
// here be dragons | |
console.log(`Case #${i + 1}: ${sum} ${rowCount} ${colCount}`); | |
} | |
rl.close(); | |
} | |
run(); | |
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
const { fork } = require('child_process'); | |
const fs = require('fs'); | |
const forked = fork('B.js', undefined, { | |
stdio: 'pipe' | |
}); | |
const file = fs.readFileSync('in.txt'); | |
forked.stdin.write(file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment