diff --git a/examples/solutions-readline/package.json b/examples/solutions-readline/package.json new file mode 100644 index 0000000..dec56e1 --- /dev/null +++ b/examples/solutions-readline/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "name": "examples-solutions-readline", + "version": "0.0.0", + "scripts": { + "start:1000": "node src/1000", + "start:1001": "node src/1001", + "start:29751": "node src/29751" + } +} diff --git a/examples/solutions-readline/src/1000.js b/examples/solutions-readline/src/1000.js new file mode 100644 index 0000000..b8800ff --- /dev/null +++ b/examples/solutions-readline/src/1000.js @@ -0,0 +1,24 @@ +const { createInterface } = require('node:readline'); +const { stdin: input, stdout: output } = require('node:process'); +const { EOL } = require('node:os'); +const { log } = require('node:console'); + +const rl = createInterface({ input, output }); + +let inputFile = ''; + +// eslint-disable-next-line no-shadow +function solution(inputFile) { + const [a, b] = inputFile + .trim() + .split(' ') + .map(val => Number(val)); + + log(a + b); +} + +rl.on('line', line => { + inputFile += `${line}${EOL}`; +}).on('close', () => { + solution(inputFile); +}); diff --git a/examples/solutions-readline/src/1001.js b/examples/solutions-readline/src/1001.js new file mode 100644 index 0000000..c3f043f --- /dev/null +++ b/examples/solutions-readline/src/1001.js @@ -0,0 +1,24 @@ +const { createInterface } = require('node:readline'); +const { stdin: input, stdout: output } = require('node:process'); +const { EOL } = require('node:os'); +const { log } = require('node:console'); + +const rl = createInterface({ input, output }); + +let inputFile = ''; + +// eslint-disable-next-line no-shadow +function solution(inputFile) { + const [a, b] = inputFile + .trim() + .split(' ') + .map(val => Number(val)); + + log(a - b); +} + +rl.on('line', line => { + inputFile += `${line}${EOL}`; +}).on('close', () => { + solution(inputFile); +}); diff --git a/examples/solutions-readline/src/29751.js b/examples/solutions-readline/src/29751.js new file mode 100644 index 0000000..5be71fe --- /dev/null +++ b/examples/solutions-readline/src/29751.js @@ -0,0 +1,26 @@ +const { createInterface } = require('node:readline'); +const { stdin: input, stdout: output } = require('node:process'); +const { EOL } = require('node:os'); +const { log } = require('node:console'); + +const rl = createInterface({ input, output }); + +let inputFile = ''; + +// eslint-disable-next-line no-shadow +function solution(inputFile) { + const [W, H] = inputFile + .trim() + .split(' ') + .map(val => Number(val)); + + const width = (W * H) / 2; + + log(width.toFixed(1)); +} + +rl.on('line', line => { + inputFile += `${line}${EOL}`; +}).on('close', () => { + solution(inputFile); +}); diff --git a/examples/solutions-readline/templates/index.js b/examples/solutions-readline/templates/index.js new file mode 100644 index 0000000..ea32b3d --- /dev/null +++ b/examples/solutions-readline/templates/index.js @@ -0,0 +1,20 @@ +/* eslint-disable */ +const { createInterface } = require('node:readline'); +const { stdin: input, stdout: output } = require('node:process'); +const { EOL } = require('node:os'); +const { log } = require('node:console'); + +const rl = createInterface({ input, output }); + +let inputFile = ''; + +// eslint-disable-next-line no-shadow +function solution(inputFile) { + // Solution +} + +rl.on('line', line => { + inputFile += `${line}${EOL}`; +}).on('close', () => { + solution(inputFile); +}); diff --git a/package-lock.json b/package-lock.json index 664d20d..71a0bd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,10 @@ "name": "examples-readline", "version": "0.0.0" }, + "examples/solutions-readline": { + "name": "examples-solutions-readline", + "version": "0.0.0" + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -6588,6 +6592,10 @@ "resolved": "examples/readline", "link": true }, + "node_modules/examples-solutions-readline": { + "resolved": "examples/solutions-readline", + "link": true + }, "node_modules/execa": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/execa/-/execa-5.0.0.tgz",