Created
August 15, 2022 14:32
-
-
Save bwasti/25951fbda7a61e74ac48613e7295fbbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import fs from "node:fs" | |
import readline from "node:readline" | |
const t0 = performance.now() | |
const stream = fs.createReadStream("input.txt") | |
const rl = readline.createInterface({ | |
input: stream, | |
crlfDelay: Infinity | |
}) | |
let out = [] | |
for await (const line of rl) { | |
const [a, b, c] = line.split(',').map(Number) | |
const n = 4 * a + b * b + (c / 3) | |
if (out.length && out[out.length - 1] > n) { | |
out.push(n - out[out.length - 1]) | |
} | |
out.push(n) | |
} | |
const d = (performance.now() - t0) / 1e3 | |
console.log("computed", out.length, "in", d, "seconds") | |
console.log(out.length / d, "lines/sec") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment