-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path2.js
More file actions
41 lines (36 loc) · 1.17 KB
/
2.js
File metadata and controls
41 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @param {number} protonsStart The initial number of protons
* @param {number} neutronsStart The initial number of neutrons
* @param {number} protonsTarget The desired number of protons
* @param {number} neutronsTarget The desired number of neutrons
* @return {string[]}
*/
function solve(protonsStart, neutronsStart, protonsTarget, neutronsTarget) {
// Write your code here
let actions = []
while (protonsStart !== protonsTarget || neutronsStart !== neutronsTarget) {
console.error(protonsStart, neutronsStart)
if (protonsStart < protonsTarget) {
actions.push('PROTON')
protonsStart++
} else if (neutronsStart < neutronsTarget) {
actions.push('NEUTRON')
neutronsStart++
} else {
actions.push('ALPHA')
protonsStart -= 2
neutronsStart -= 2
}
// if (actions.length > 20) break
}
return actions
}
/* Ignore and do not change the code below */
/**
* Try a solution
*/
function trySolution(recipe) {
console.log('' + JSON.stringify(recipe))
}
trySolution(solve(JSON.parse(readline()), JSON.parse(readline()), JSON.parse(readline()), JSON.parse(readline())))
/* Ignore and do not change the code above */