-
Notifications
You must be signed in to change notification settings - Fork 2
/
halloween.js
42 lines (40 loc) · 886 Bytes
/
halloween.js
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
42
function pick(bags, scale) {
// scale.weigh([bags[0]], [bags[1]]); returns -1, 0 or 1
var firstCheck = scale.weigh([bags[0], bags[1], bags[2]], [bags[3], bags[4], bags[5]]);
if (firstCheck === 0){
var secondCheck = scale.weigh([bags[6]], [bags[7]])
if (secondCheck === 0){
return bags[8];
}
else if (secondCheck < 0){
return bags[6];
}
else {
return bags[7];
}
}
else if (firstCheck < 0){
var secondCheck = scale.weigh([bags[0]], [bags[1]]);
if (secondCheck === 0){
return bags[2];
}
else if (secondCheck < 0){
return bags[0];
}
else {
return bags[1];
}
}
else{
var secondCheck = scale.weigh([bags[3]], [bags[4]]);
if (secondCheck === 0){
return bags[5];
}
else if (secondCheck < 0){
return bags[3];
}
else {
return bags[4];
}
}
}