Skip to content

Commit

Permalink
chore(examples): create examples/solutions-readline (#13)
Browse files Browse the repository at this point in the history
* chore: update `package.json`

* wip: create `1000.js`

* wip: create `templates/index.js`

* wip: create `src/1001.js`

* wip: create `src/29751.js`
  • Loading branch information
lumirlumir authored Dec 8, 2024
1 parent 3ab8cc0 commit 7505059
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/solutions-readline/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
24 changes: 24 additions & 0 deletions examples/solutions-readline/src/1000.js
Original file line number Diff line number Diff line change
@@ -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);
});
24 changes: 24 additions & 0 deletions examples/solutions-readline/src/1001.js
Original file line number Diff line number Diff line change
@@ -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);
});
26 changes: 26 additions & 0 deletions examples/solutions-readline/src/29751.js
Original file line number Diff line number Diff line change
@@ -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);
});
20 changes: 20 additions & 0 deletions examples/solutions-readline/templates/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7505059

Please sign in to comment.