Skip to content

Commit 022083c

Browse files
committed
Merge branch 'release/1.4.0'
2 parents d06575e + 592f7c9 commit 022083c

25 files changed

Lines changed: 13820 additions & 1 deletion
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"test": {
4+
"presets": [
5+
[
6+
"@babel/preset-env"
7+
]
8+
]
9+
},
10+
"build": {
11+
"presets": [
12+
[
13+
"@babel/preset-env",
14+
{
15+
"modules": false,
16+
"targets": {
17+
"node": "11.13.0"
18+
}
19+
}
20+
]
21+
]
22+
}
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
'env': {
3+
'es6': true,
4+
'node': true,
5+
'jest': true,
6+
},
7+
'extends': 'standard',
8+
'globals': {
9+
'Atomics': 'readonly',
10+
'SharedArrayBuffer': 'readonly'
11+
},
12+
'parserOptions': {
13+
'ecmaVersion': 2018,
14+
'sourceType': 'module'
15+
},
16+
'rules': {
17+
}
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Foregone Solution
2+
3+
[Direct link to Google Code Jam site](https://codingcompetitions.withgoogle.com/codejam/round/0000000000051705/0000000000088231)
4+
5+
This solution passes all test set 1 (6 points), test set 2 (10 points) and test set 3 (1 point).
6+
7+
## Prerequisite
8+
9+
nodejs 11.13.0
10+
11+
## Usage
12+
13+
First, install dev dependencies (babel, rollup, jest etc) by running the following:
14+
15+
```
16+
npm install
17+
```
18+
19+
To run tests:
20+
21+
```
22+
npm run test
23+
```
24+
25+
Build the solution into one file output at `build/solution.js`:
26+
27+
```
28+
npm run build
29+
```
30+
31+
`build/solution.js` is the code to be submitted to Google Code Jam site.
32+
33+
To run and test `build/solution.js` manually, run the following and key in the input:
34+
35+
```
36+
npm run start
37+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict';
2+
3+
const parseCase = (line, data) => {
4+
const {
5+
isProcessing,
6+
...result
7+
} = data;
8+
result.N = line;
9+
return result;
10+
};
11+
12+
const parseProblem = (line, problem) => {
13+
if (!problem.T || problem.T === 0) {
14+
const result = { ...problem,
15+
T: parseInt(line),
16+
isProcessing: true
17+
};
18+
return result;
19+
}
20+
21+
const cases = [...problem.cases];
22+
23+
if (cases.length === 0 || !cases[cases.length - 1].isProcessing) {
24+
cases.push({
25+
isProcessing: true
26+
});
27+
}
28+
29+
const currentCase = cases[cases.length - 1];
30+
cases[cases.length - 1] = parseCase(line, currentCase);
31+
const isProcessing = cases.length < problem.T || cases[cases.length - 1].isProcessing;
32+
const result = { ...problem,
33+
cases,
34+
isProcessing
35+
};
36+
return result;
37+
};
38+
39+
const solve = data => {
40+
const {
41+
N
42+
} = data;
43+
const A = [];
44+
const B = [];
45+
N.split('').forEach(c => {
46+
if (c === '4') {
47+
A.push('2');
48+
B.push('2');
49+
} else {
50+
A.push(c);
51+
52+
if (B.length > 0) {
53+
B.push('0');
54+
}
55+
}
56+
});
57+
const result = `${A.join('')} ${B.join('')}`;
58+
return result;
59+
};
60+
61+
const solveCases = cases => {
62+
for (let index = 0; index < cases.length; index++) {
63+
const result = solve(cases[index]);
64+
console.log(`Case #${index + 1}: ${result}`);
65+
}
66+
};
67+
68+
const main = () => {
69+
const readline = require('readline');
70+
71+
let problem = {
72+
T: 0,
73+
cases: [],
74+
isProcessing: true
75+
};
76+
const rl = readline.createInterface({
77+
input: process.stdin,
78+
output: process.stdout
79+
});
80+
rl.on('line', line => {
81+
problem = parseProblem(line, problem);
82+
83+
if (!problem.isProcessing) {
84+
rl.close();
85+
}
86+
}).on('close', () => {
87+
solveCases(problem.cases);
88+
process.exit(0);
89+
});
90+
};
91+
92+
if (!module.parent) {
93+
main();
94+
}

0 commit comments

Comments
 (0)