This commit is contained in:
2017-12-25 23:22:40 +00:00
parent d5fbba3277
commit 47510ec0ff
24 changed files with 2002 additions and 0 deletions

56
day24/input.txt Normal file
View File

@ -0,0 +1,56 @@
31/13
34/4
49/49
23/37
47/45
32/4
12/35
37/30
41/48
0/47
32/30
12/5
37/31
7/41
10/28
35/4
28/35
20/29
32/20
31/43
48/14
10/11
27/6
9/24
8/28
45/48
8/1
16/19
45/45
0/4
29/33
2/5
33/9
11/7
32/10
44/1
40/32
2/45
16/16
1/18
38/36
34/24
39/44
32/37
26/46
25/33
9/10
0/29
38/8
33/33
49/19
18/20
49/39
18/39
26/13
19/32

25
day24/part1.js Normal file
View File

@ -0,0 +1,25 @@
var components = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a)).map(a=>(a.split("/").map(b=>(parseInt(b)))));
var finalBridges = [];
function getLongerChains(state){
var additions = components.filter(a=>(state.components.indexOf(a) == -1)).filter(a=>(a[0] == state.end || a[1] == state.end));
if(additions.length == 0){
finalBridges.push(state.components)
}
else{
additions.forEach(a=>{
var newState = {
components: state.components.slice(),
end: a.filter((b,i)=>(i!=a.indexOf(state.end)))[0]
}
newState.components.push(a);
//console.log(newState);
getLongerChains(newState);
});
}
}
getLongerChains({
components: [],
end: 0
});
var bridgeLengths = finalBridges.map(bridge=>(bridge.map(a=>(a[0] + a[1])).reduce((a,b)=>(a+b))));
console.log(bridgeLengths.reduce((g, b)=>((b>g || g==null) ? b : g),null));

28
day24/part2.js Normal file
View File

@ -0,0 +1,28 @@
var components = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a)).map(a=>(a.split("/").map(b=>(parseInt(b)))));
var finalBridges = [];
function getLongerChains(state){
var additions = components.filter(a=>(state.components.indexOf(a) == -1)).filter(a=>(a[0] == state.end || a[1] == state.end));
if(additions.length == 0){
finalBridges.push(state.components)
}
else{
additions.forEach(a=>{
var newState = {
components: state.components.slice(),
end: a.filter((b,i)=>(i!=a.indexOf(state.end)))[0]
}
newState.components.push(a);
getLongerChains(newState);
});
}
}
getLongerChains({
components: [],
end: 0
});
var bridgeLengths = finalBridges.map(bridge=>(bridge.length));
var maxLength = bridgeLengths.reduce((g, b)=>((b>g || g==null) ? b : g),null);
var maxLengthBridges = finalBridges.filter(bridge=>(bridge.length == maxLength));
var bridgeStrengths = maxLengthBridges.map(bridge=>(bridge.map(a=>(a[0] + a[1])).reduce((a,b)=>(a+b))));
var maxStrength = bridgeStrengths.reduce((g, b)=>((b>g || g==null) ? b : g),null);
console.log(maxStrength);