My solutions for different programming problems, from different platforms:
- add code runner for vscode.
- top 100 in Kattis.
- 1 star in Leetcode.
- 10 ProjectEuler problems from Hackerrank with editorials.
- Finish advent of code 2018.
- Finish advent of code 2019.
- Finish Algorithms and Data Structures Micro Masters.
JavaScript solutions are run in node v8.11.4
.
Generally, reading is done from process.stdin (standard input), using the readline interface. Inputs are read at once, sometimes parsed on the go.
// importing and instantiating the readline interface
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
// Reading multiple lines, each line include space-split integers
rl.on("line", line => {
input.push(...line.split(" ").map(x => parseInt(x)));
});
Then solution is run once the input stream is closed.
// when there's no more data to process, we run the solution
rl.on("close", () => {
console.log(solution(input))
});
Run a given solution locally using the command below, solution will run on interactive mode, where you can provide inputs on the go, then hit ctrl + C
to close the input stream.
node ./kattis/solution.js
I'm using standard input/output stdin/stdout
to read/write for my c++ implementations.
To run any solution, you can use the command below. Then provide data on your own.
You can use your preferred c++ compiler, I'm using g++
g++ pathToSolution/solution.cpp -o solution.out && ./solution.out