all done
This commit is contained in:
parent
d5fbba3277
commit
47510ec0ff
8
day17/part1.js
Normal file
8
day17/part1.js
Normal file
@ -0,0 +1,8 @@
|
||||
var input = 344;
|
||||
var arr = [0];
|
||||
var pos = 0;
|
||||
for(var i = 1; i <= 2017; i++){
|
||||
pos = (pos+input)%arr.length + 1;
|
||||
arr.splice(pos, 0, i);
|
||||
}
|
||||
console.log(arr[pos+1]);
|
10
day17/part2.js
Normal file
10
day17/part2.js
Normal file
@ -0,0 +1,10 @@
|
||||
var input = 344;
|
||||
var len = 1;
|
||||
var pos = 0;
|
||||
for(var i = 1; i <= 50000000; i++){
|
||||
pos = (pos+input)%len + 1;
|
||||
len++;
|
||||
if(pos == 1){
|
||||
console.log(i);
|
||||
}
|
||||
}
|
41
day18/input.txt
Normal file
41
day18/input.txt
Normal file
@ -0,0 +1,41 @@
|
||||
set i 31
|
||||
set a 1
|
||||
mul p 17
|
||||
jgz p p
|
||||
mul a 2
|
||||
add i -1
|
||||
jgz i -2
|
||||
add a -1
|
||||
set i 127
|
||||
set p 622
|
||||
mul p 8505
|
||||
mod p a
|
||||
mul p 129749
|
||||
add p 12345
|
||||
mod p a
|
||||
set b p
|
||||
mod b 10000
|
||||
snd b
|
||||
add i -1
|
||||
jgz i -9
|
||||
jgz a 3
|
||||
rcv b
|
||||
jgz b -1
|
||||
set f 0
|
||||
set i 126
|
||||
rcv a
|
||||
rcv b
|
||||
set p a
|
||||
mul p -1
|
||||
add p b
|
||||
jgz p 4
|
||||
snd a
|
||||
set a b
|
||||
jgz 1 3
|
||||
snd b
|
||||
set f 1
|
||||
add i -1
|
||||
jgz i -11
|
||||
snd a
|
||||
jgz f -16
|
||||
jgz a -19
|
39
day18/part1.js
Normal file
39
day18/part1.js
Normal file
@ -0,0 +1,39 @@
|
||||
var pc = 0;
|
||||
var registers = {};
|
||||
var lastsnd = 0;
|
||||
var instructions = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a));
|
||||
while((pc >= 0) && (pc < instructions.length)){
|
||||
val = a => ((isNaN(parseInt(a))) ? (registers[a]) : (parseInt(a)));
|
||||
var instruction = instructions[pc];
|
||||
var parts = instruction.split(" ");
|
||||
switch(parts[0]){
|
||||
case "snd":
|
||||
lastsnd = val(parts[1]);
|
||||
break;
|
||||
case "set":
|
||||
registers[parts[1]] = val(parts[2]);
|
||||
break;
|
||||
case "add":
|
||||
registers[parts[1]] += val(parts[2]);
|
||||
break;
|
||||
case "mul":
|
||||
registers[parts[1]] *= val(parts[2]);
|
||||
break;
|
||||
case "mod":
|
||||
registers[parts[1]] = registers[parts[1]] % val(parts[2]);
|
||||
break;
|
||||
case "rcv":
|
||||
if(val(parts[1]) != 0){
|
||||
console.log(lastsnd);
|
||||
pc = instructions.length;
|
||||
}
|
||||
break;
|
||||
case "jgz":
|
||||
if(val(parts[1]) > 0){
|
||||
pc += (val(parts[2]) - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pc++;
|
||||
}
|
||||
|
54
day18/part2.js
Normal file
54
day18/part2.js
Normal file
@ -0,0 +1,54 @@
|
||||
var pc = [0,0];
|
||||
var registers = [{p: 0}, {p: 1}];
|
||||
var lastsnd = [0,0];
|
||||
var queue = [[],[]];
|
||||
var instructions = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a));
|
||||
var deadlock = 0;
|
||||
var numSends = [0, 0];
|
||||
while(deadlock < 2){
|
||||
deadlock = 0;
|
||||
for(var p = 0; p <= 1; p++){
|
||||
if((pc[p] >= 0) && (pc[p] < instructions.length)){
|
||||
val = a => ((isNaN(parseInt(a))) ? (registers[p][a]) : (parseInt(a)));
|
||||
var instruction = instructions[pc[p]];
|
||||
var parts = instruction.split(" ");
|
||||
switch(parts[0]){
|
||||
case "snd":
|
||||
numSends[p]++;
|
||||
queue[1-p].push(val(parts[1]));
|
||||
break;
|
||||
case "set":
|
||||
registers[p][parts[1]] = val(parts[2]);
|
||||
break;
|
||||
case "add":
|
||||
registers[p][parts[1]] += val(parts[2]);
|
||||
break;
|
||||
case "mul":
|
||||
registers[p][parts[1]] *= val(parts[2]);
|
||||
break;
|
||||
case "mod":
|
||||
registers[p][parts[1]] = registers[p][parts[1]] % val(parts[2]);
|
||||
break;
|
||||
case "rcv":
|
||||
if(queue[p].length >= 1){
|
||||
registers[p][parts[1]] = queue[p].splice(0,1)[0];
|
||||
}
|
||||
else{
|
||||
pc[p]--;
|
||||
deadlock++;
|
||||
}
|
||||
break;
|
||||
case "jgz":
|
||||
if(val(parts[1]) > 0){
|
||||
pc[p] += (val(parts[2]) - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pc[p]++;
|
||||
}
|
||||
else{
|
||||
deadlock++;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(numSends[1]);
|
201
day19/input.txt
Normal file
201
day19/input.txt
Normal file
@ -0,0 +1,201 @@
|
||||
|
|
||||
+---------------------------------------------------------------------------+ +---------------------+ +---+ +-------------------------------------+
|
||||
| | | | | | | | |
|
||||
+---------------+ +---------------+ +-------|-------------------------------------+ | | | | +-----------+ +-----+
|
||||
| | | | | | | | | | | | | | | | |
|
||||
+---+ | | +-------+ | | +-----------------------------|-------------------------------------------|-----------+ | | | | | | +-----------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
+-----------+ | +-|-----------|-----------+ | +---+ | | | +-----------------------|-|---------------|-------|-----------|-----------------------+ |
|
||||
| | | | | | | | | | | | | | | | | M | | | | | | | | |
|
||||
| | | +-|-----------|---------------------|-----+ | | | | | +---------+ +-+ +---------------|-----------|---------------+ | +-+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | +-------------------------|---------------|---------------|-------|-------+ | | +-----+ +-----+ | | | | | | | +---+ +-+ | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---|-+ | +---+ | +---------------------------------------|-------------|---------------------------|-----|-|---|-------|---------------------|-|-|---------+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---+ | | | | | | | | +-------|-------|-------|---|-|-----|---------------|-----------|-------------|-|-----------|---|-|-|-|---+ | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | +-----------------------------|---------------------|---|-|-------------------|-|-----------|---|-|-|-|-------|-|---+
|
||||
| | | | C | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|---|-----|-|-----------|-------|-----------------------------|-------------+ | | | | | | +-------------|-|---|-|-|---|---+ | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|---|-----|-------------|-------|-----------------------------|---------------|-------------------|-------|-----|---------|---|-+ | | | | | | | | | +-|---|---|-----|-+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| +---+ | | | | | | | | +-+ | +---------------------|---+ | | | | | | | +-|-----|-|-------------|-----------+ | | | | | | | | +---+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | P |
|
||||
| | | | | | | | | | | | | +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | +---|-+ | +---|-|-----|-----------|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | +---|---------+ | | +---|-|-|---|---------|-----------|-+ +-+ | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | +-------+ | | | | | | | | | | +-------+ | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---|---|---|---------|-----+ +-----|-|-----|-------------------|-----|-------------|-|-------|-----------|-|-----|-------------------|-------|---------|---|-----------|-----------+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | +---+ | | | | | | | | | | | | | | | | | | | | | | | +-|-+ Y +-|-|-----+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | +-+ | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | +-|-------|-----|-|-----|-------------------|-------------|---------------|---------------------|-----|-|---------|-|---|-|-|-------|---|-------+ | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | +-----|---------|-------------|---------------|---|---|-|-|-----|-+ | | +-------|-+ +---|---|-------+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | +-------------------|-------|-------------|---+ | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | +-|-------------------|---|-----+ | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | +-----|-----|---------|-------|---|-|-------------------|---------------------------------------------|-|-----|---+ | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|-+ | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | +-----|---|-|-|-----|-----|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | +-------|-|-----|-----|-+ | | +---+ | +---------|-------|---------|-|---|-----|-|-|-+ | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | +---|-|---------------|-|---|-|-----|-------------|-+ | | | +-----------|-------------|---------+ | | | | | +-----+ | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|---------------------------|---|-------|---+ +-------|---+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | +-----|---------------|-|-----------|-|-----|-----|-|---|---|-----------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | Q | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----+ | | | | | | | | | +-+ | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +-----------|---|---------|-|-----------------------+ | | | | | | | | | | | | | | | | +---------------------|-|-|-----------|----------E------+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | +---------|-|---|-----------|-|-|---+ | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | +---|-------|---|-+ | | +-|-------------|-|-----------|-----|---|-----+ | | +-+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | +-----------------|-|---|-----|-----------|---|-|---------------|-----|-------------------|-|-|-----|---------------+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | +---|-|---|-------|---|-----|---|-----------|---------------|-----|-------|---|-----|-----------------+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | +-------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | +---------------|-+ | | +-|-|-------------------|-----------|-----|-|-|-|---------------|-|-----------|-----|-|-|---------------------|-------------|-|-|-|-----|-|-+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | +-|---+ | | | | | | | | | | | | | | | +-|---|-----+ | +---|---|-|---+ | | | +-------|-|-------|---|-|---|-------|-----+ | +-------|-----+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-+ | | | | | | | | | | +-----------|-|-|---|---|-------|---|---|---------------|-|-|---------+ | | +-|---|---------|-|-----------|-------|-------|-----|-----|-----|---+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|-|-+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | H | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | +-|---|-----+ | | | | | | | | | | | | | | | | +-|-------|---|-|-----------|-----------|-|---+ | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-|-------|-|-----|---|-----|-------------------|-------|-+ | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|-----+ | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | +---|-|---|-|---|-----------|---|-----|-|---------|---|-------------|-|-----|-----|-------|-------|-------|---|---|-|-|-|-----------------------------------|-------------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | +-|-------|---+ | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | +-------|---|-------|---------------|-|---------|-----|---|-----------|---|-|-|-|-----------------------------|-------|-|---------+ | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | +-+ | | | | | +---|-----|-----------------|-|-------+ | | | | | | | +-|-------+ | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---|---|-------|-|---|-----------------+ | | | | +---+ | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | +-------|-|-|-|-------|---------|-|-------------|-|---|-|-----|-|-------------------|-------|-|-------|-------------+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | +-----+ | | | | | | | | | | | | +---------|-----+ | +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | +-|-----------|---|-|---|-------+ +-------|-----------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | +---|-|---------|-|---------------+ | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | +---|---------|---|---------------|---|---|-----|---------|-------|---------------------|---|-------|-|-|-----+ | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | +-|-+ | | | | | | | | | | | | | | | | | | | | | | | | +-|---------|-------------------|-----------|---|-----|-------|-----|---------|-+ | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-----+ | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|---|-|---|-|-----|---|-|---|-|-+ +---|-+ | | | | | | | +-------|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---+ | | | | | | | | | | | | | | | | | | | | | | | | | +---|-----|-------|-|-----------------|-|-|-|-|---|-|---|-|-|-|-------------------|-------|---|-----+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +-----|---+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|---------|-------|-|-|-------|-----|-|-|-|---------|-----|-----+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | +-|-+ | +-------------|---|---|---------|-------------|-|---------|-------|---|-|-|-------|-|-|---------|-------|-|---|-----------|-----+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | +-----|-----|---------|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | +-------|-----------|-------|-|-------|-----+ | | | | | +---|-|-|---|-|-|-+ | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | S | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | +---|-------|---------------------------------|---------|-----------------|---|-|---|-|---+ | | | +---------|-----|---------+ | | | | +-|-+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
+-----|-|---|-|---|-----------|-----|-|---|-----|---------|---+ | | | | | +-------|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | +---|-----|---------|-----|---|-|-|-|-----|-------|-------|---|-----|-------+ +-|-|-------|-|---------------------|-|-|-------------------|-|-+ | | +-|---+ | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
+-------------|-|-|-|-----|---------|-----|-|-----|-|---------------------|---|-----|---------|-|-|-|-------|---------+ | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|-----|-|---|-|-----|---------------|---|---|---|---|-------|-------|-------|-----+ | | | | | | | | | | | | | +---|-+ | | | | | | | | | | | | | +-+ | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---|---|-|-----------|---|-------|-------|---+ | | | | +-----------------------|---|-------|---+ +---------------|-----+ | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +---+ | +-|---|-+ +-----|-----|-+ +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +-|-----------|-|---|---+ | +-------|-+ | | | | | | | | | +---|-+ | | | | | | +-|-|-----|-----+ | | | | +---+ | +-+ | +-+ | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| +-----|-|V------|-|---|-|---------|-|-------|-----|-----------------|-------------------------|---------|-----|---------------------------+ | | | | +-|-+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|-|-----|-|-|-|---------------------|-|-------|---------------|---|-------|-------------|---------|-|-----------+ | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-----+ | | | | | | +---|-----------|-|---------------|-------|---|-|-----------------------|---|-----------------|-----|-------|-|---|-|---|---+ | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---------|-|---|-|-|-----------------|-|-------------------|-------|---|-------------------|---------|---------------------|-|-----|-------|---|-|---|-------------------|-|-----|---|-|-----+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| +-|-----|-----+ +---|---|-----------------|---+ | | | | | | | | | | | | | +-----------+ | | | | | | | | | | +-|---|-----|-----+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
+-|-|-----|---------|-|-+ | +-----|-|-+ | | | | | | | | | | | | | +-----------|---+ | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
+---------|---------|-|-----------------|-+ | | | +---|-------|---|---|---|---------------+ | | | | | +-|-------+ | | | | | | | | +---------------------|-+ | +-----+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +---|---------+ +-+ | | | | | +---------|---------------+ | +-|---------------|-------|-----|---------------|-|-----|-------|-------|---------------------|-|---+ | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | +---+ | | +---|-----------|---|-----------|-----------|-|---------|-|-----------|-----------|-|---|-|-------------------------|-----|-------------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | +-------|-|-+ | | | | | | | | | | | | | +-----------|-----+ | +---+ | | | | | | | +---------------------+ +-------|-------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | +-----|-----|-+ | | +-|-----------|---|-----------------|---+ | | | +-----+ | +-------|-----------+ | | | | | +-------------|-------------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | +---------|---|---|---|-------|-|-|-----------|-|-|---------|-------------------+ | +---|-------------+ +-------------|-----+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | | | | +-----------|-----|-----------+ | | +-----|-|-|-------------------------|-----------+ +-|-|-|-------------+ |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---------------------|-----|-------|-|---------|-----|-----------|-|-----|---|-+ +-------+ | +-|-|-+ | | | +---------------------------------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +-|-|---------|---|-------|---------|---|-|---------------|-------|---------|---------|-|-|-|---------|---------------------|-------|---------+ | | +-+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | +-------|-----|-----------|---|---|---+ | | | | | | +-+ +---------|---------------+ | | | | | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | +---+ | | | | | | | | | | | | | +---------|-|-|-------|---------+ | | +---------|-----+ +-+ | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | +---------|-+ | | | | | +-----+ | +-----|-------+ +-+ +---------------+ | | | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | | | | | +---------|-------|---------|---|---|-----|-----------|---------------------------------------------|-------+ +-------------------------------------|---------------+
|
||||
| | | | | | | | | | | | | | | | | | | | | | | |
|
||||
| | | +---------+ | +-------------|-----------|---------|---|-------------|-------------------------------------------------+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | | | |
|
||||
| | | | +---------+ +---------|---+ +---|---------+ +-+ +---------------------------------------------+ | | | | |
|
||||
| | | | | | | | | | | | | | | | | |
|
||||
+-+ +-------------------------|-----------+ +-+ +---|---+ | +---------------------------------------------------------------+ +-----+ | +-------------+
|
||||
| | | | | |
|
||||
+-----+ +-------+ +--------------------------------------------B----------------------------------------------------------------------+
|
||||
|
35
day19/part1.js
Normal file
35
day19/part1.js
Normal file
@ -0,0 +1,35 @@
|
||||
var grid = require("fs").readFileSync("input.txt").toString().split("\n").map((a)=>(a.split("")));
|
||||
var x = 163;
|
||||
var y = 0;
|
||||
var dirs = [[0, 1], [1, 0], [-1, 0], [0, -1]];
|
||||
var dir = 0;
|
||||
var visited = [];
|
||||
var end = false;
|
||||
var letters = [];
|
||||
while(!end){
|
||||
if(grid[y][x].match("[A-Z]")){
|
||||
letters.push(grid[y][x]);
|
||||
}
|
||||
visited.push((y*201) + x);
|
||||
if(grid[y][x] == "+"){
|
||||
var changed = false;
|
||||
var i = 0;
|
||||
while(!changed){
|
||||
if(visited.indexOf(((y + dirs[i][1]) * 201) + (x + dirs[i][0])) == -1){
|
||||
//not visited before
|
||||
if(grid[y+dirs[i][1]][x+dirs[i][0]] != " "){
|
||||
//not empty
|
||||
changed = true;
|
||||
dir = i;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
x += dirs[dir][0];
|
||||
y += dirs[dir][1];
|
||||
if(grid[y][x] == " "){
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
console.log(letters.join(""));
|
37
day19/part2.js
Normal file
37
day19/part2.js
Normal file
@ -0,0 +1,37 @@
|
||||
var grid = require("fs").readFileSync("input.txt").toString().split("\n").map((a)=>(a.split("")));
|
||||
var x = 163;
|
||||
var y = 0;
|
||||
var dirs = [[0, 1], [1, 0], [-1, 0], [0, -1]];
|
||||
var dir = 0;
|
||||
var visited = [];
|
||||
var end = false;
|
||||
var letters = [];
|
||||
var moves = 0;
|
||||
while(!end){
|
||||
if(grid[y][x].match("[A-Z]")){
|
||||
letters.push(grid[y][x]);
|
||||
}
|
||||
visited.push((y*201) + x);
|
||||
if(grid[y][x] == "+"){
|
||||
var changed = false;
|
||||
var i = 0;
|
||||
while(!changed){
|
||||
if(visited.indexOf(((y + dirs[i][1]) * 201) + (x + dirs[i][0])) == -1){
|
||||
//not visited before
|
||||
if(grid[y+dirs[i][1]][x+dirs[i][0]] != " "){
|
||||
//not empty
|
||||
changed = true;
|
||||
dir = i;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
x += dirs[dir][0];
|
||||
y += dirs[dir][1];
|
||||
if(grid[y][x] == " "){
|
||||
end = true;
|
||||
}
|
||||
moves++;
|
||||
}
|
||||
console.log(moves);
|
1000
day20/input.txt
Normal file
1000
day20/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
day20/part1.js
Normal file
15
day20/part1.js
Normal file
@ -0,0 +1,15 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var inputjson = "[{" + input.replace(/([a-z])=</g, "\"$1\": [").replace(/>/g, "]").replace(/\n/g, "},\n{").slice(0,-3) + "]";
|
||||
var objects = JSON.parse(inputjson);
|
||||
for(var i = 0; i < 1000; i++){
|
||||
objects = objects.map(o=>{
|
||||
o.v = o.v.map((v,x)=>(v + o.a[x]));
|
||||
o.p = o.p.map((p,x)=>(p + o.v[x]));
|
||||
return o;
|
||||
});
|
||||
}
|
||||
var locations = objects.map(o=>(o.p));
|
||||
var distances = locations.map((a)=>(a.map((b)=>(Math.abs(b))).reduce((b,c)=>(b+c))));
|
||||
var maxdist = Math.min.apply(null, distances);
|
||||
console.log(maxdist);
|
||||
console.log(distances.indexOf(maxdist));
|
14
day20/part2.js
Normal file
14
day20/part2.js
Normal file
@ -0,0 +1,14 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var inputjson = "[{" + input.replace(/([a-z])=</g, "\"$1\": [").replace(/>/g, "]").replace(/\n/g, "},\n{").slice(0,-3) + "]";
|
||||
var objects = JSON.parse(inputjson);
|
||||
for(var i = 0; i < 10000; i++){
|
||||
objects = objects.map(o=>{
|
||||
o.v = o.v.map((v,x)=>(v + o.a[x]));
|
||||
o.p = o.p.map((p,x)=>(p + o.v[x]));
|
||||
return o;
|
||||
});
|
||||
var locations = objects.map(o=>(o.p));
|
||||
var locationsStr = locations.map((a)=>(a.join(",")));
|
||||
objects = objects.filter((a)=>(locationsStr.filter((b)=>(b==a.p.join(","))).length == 1));
|
||||
console.log(objects.length);
|
||||
}
|
108
day21/input.txt
Normal file
108
day21/input.txt
Normal file
@ -0,0 +1,108 @@
|
||||
../.. => ..#/#../.#.
|
||||
#./.. => #../#../...
|
||||
##/.. => ###/#.#/#..
|
||||
.#/#. => ###/##./.#.
|
||||
##/#. => .../.#./..#
|
||||
##/## => ##./#.#/###
|
||||
.../.../... => ##../.#../#.#./....
|
||||
#../.../... => ..../##.#/...#/##.#
|
||||
.#./.../... => ###./####/#.../#..#
|
||||
##./.../... => ###./.##./...#/..##
|
||||
#.#/.../... => .###/.##./#.../#.##
|
||||
###/.../... => ##.#/#..#/#.#./#.##
|
||||
.#./#../... => #.#./.###/#.../#.##
|
||||
##./#../... => #.../####/#.##/....
|
||||
..#/#../... => #.##/..#./...#/...#
|
||||
#.#/#../... => #.##/####/.#.#/#.#.
|
||||
.##/#../... => #.../##../##.#/.##.
|
||||
###/#../... => ..../#.#./.###/#...
|
||||
.../.#./... => .#.#/#..#/##../#.##
|
||||
#../.#./... => ###./.###/.#.#/..#.
|
||||
.#./.#./... => ..##/.##./..##/.#.#
|
||||
##./.#./... => ..#./##../###./...#
|
||||
#.#/.#./... => ..##/.##./.###/###.
|
||||
###/.#./... => ..#./.###/###./#.##
|
||||
.#./##./... => ###./..../.#../#...
|
||||
##./##./... => .#.#/##../##.#/...#
|
||||
..#/##./... => ##.#/.##./.###/..##
|
||||
#.#/##./... => .###/..#./#.##/####
|
||||
.##/##./... => ##.#/..#./..##/###.
|
||||
###/##./... => ..../.#.#/.#../#...
|
||||
.../#.#/... => ###./.#.#/.#../#.##
|
||||
#../#.#/... => ####/#..#/..../....
|
||||
.#./#.#/... => #.../..##/#.##/#.#.
|
||||
##./#.#/... => #.#./###./##../#.#.
|
||||
#.#/#.#/... => ...#/.##./.##./.#..
|
||||
###/#.#/... => ..../.##./####/#.#.
|
||||
.../###/... => .###/.#../.###/#.##
|
||||
#../###/... => ..##/..##/.##./##..
|
||||
.#./###/... => .#.#/..#./..##/##.#
|
||||
##./###/... => ...#/#.##/#.#./##.#
|
||||
#.#/###/... => #.##/.##./...#/###.
|
||||
###/###/... => ##../...#/..##/####
|
||||
..#/.../#.. => #.##/#.../.#../#.#.
|
||||
#.#/.../#.. => .##./.##./.#.#/.##.
|
||||
.##/.../#.. => .#.#/#.##/...#/##.#
|
||||
###/.../#.. => ##../..#./...#/##..
|
||||
.##/#../#.. => ##../..##/#..#/#..#
|
||||
###/#../#.. => ##../..#./#.#./....
|
||||
..#/.#./#.. => .##./##.#/##../####
|
||||
#.#/.#./#.. => ####/...#/.#.#/..#.
|
||||
.##/.#./#.. => .#.#/..#./##.#/.#..
|
||||
###/.#./#.. => #.../#.##/..../##.#
|
||||
.##/##./#.. => #.#./#.#./#.##/#.#.
|
||||
###/##./#.. => ...#/###./.##./.#.#
|
||||
#../..#/#.. => ####/####/..../.##.
|
||||
.#./..#/#.. => #.##/...#/..#./####
|
||||
##./..#/#.. => ..#./#.../..##/####
|
||||
#.#/..#/#.. => #.../#.##/#.##/..##
|
||||
.##/..#/#.. => ####/..../##../####
|
||||
###/..#/#.. => ..../##.#/.##./####
|
||||
#../#.#/#.. => ...#/..##/###./#..#
|
||||
.#./#.#/#.. => #..#/..#./.###/##.#
|
||||
##./#.#/#.. => ###./####/#.##/..#.
|
||||
..#/#.#/#.. => ##../##.#/..##/.##.
|
||||
#.#/#.#/#.. => .#.#/.##./#.../##.#
|
||||
.##/#.#/#.. => .#.#/#..#/.##./..#.
|
||||
###/#.#/#.. => ...#/.#../.##./##.#
|
||||
#../.##/#.. => ###./##../#.#./####
|
||||
.#./.##/#.. => .#../##../#.#./.#.#
|
||||
##./.##/#.. => ##.#/.#../.#.#/####
|
||||
#.#/.##/#.. => ####/.#.#/..../....
|
||||
.##/.##/#.. => ####/##../#..#/####
|
||||
###/.##/#.. => .###/##.#/.#../#.##
|
||||
#../###/#.. => #..#/###./####/.#.#
|
||||
.#./###/#.. => ..##/##../##.#/.#.#
|
||||
##./###/#.. => #..#/.#../####/...#
|
||||
..#/###/#.. => ##../##.#/...#/#..#
|
||||
#.#/###/#.. => ..#./.##./#..#/....
|
||||
.##/###/#.. => #..#/#.../..../.#..
|
||||
###/###/#.. => ..#./#.##/.##./#...
|
||||
.#./#.#/.#. => .#.#/.##./##.#/.##.
|
||||
##./#.#/.#. => #..#/.###/.#.#/.##.
|
||||
#.#/#.#/.#. => #.../##../#.../.###
|
||||
###/#.#/.#. => ###./.###/###./....
|
||||
.#./###/.#. => .#../####/...#/##..
|
||||
##./###/.#. => ####/###./..../....
|
||||
#.#/###/.#. => ...#/.###/..../####
|
||||
###/###/.#. => ..../#.../..#./.###
|
||||
#.#/..#/##. => #.#./#.../####/#.##
|
||||
###/..#/##. => .#.#/#..#/.###/#...
|
||||
.##/#.#/##. => ..##/..#./..../##..
|
||||
###/#.#/##. => #.#./##.#/####/#..#
|
||||
#.#/.##/##. => ..../.#../#.#./##.#
|
||||
###/.##/##. => ..../..../.#../##.#
|
||||
.##/###/##. => #.#./.###/#.#./#.##
|
||||
###/###/##. => ##.#/##.#/.###/..#.
|
||||
#.#/.../#.# => #..#/.#../#.../...#
|
||||
###/.../#.# => ##../.#../##.#/..#.
|
||||
###/#../#.# => ..##/#.#./####/.#..
|
||||
#.#/.#./#.# => ...#/...#/#..#/#.#.
|
||||
###/.#./#.# => ..../####/.##./.#.#
|
||||
###/##./#.# => #..#/.#.#/..##/####
|
||||
#.#/#.#/#.# => #.#./..#./...#/.#..
|
||||
###/#.#/#.# => ...#/##.#/.###/.#..
|
||||
#.#/###/#.# => .#.#/###./.#../.##.
|
||||
###/###/#.# => ...#/.###/.#.#/###.
|
||||
###/#.#/### => #.##/.#.#/...#/.#..
|
||||
###/###/### => ..##/.#../#.#./.#..
|
66
day21/part1.js
Normal file
66
day21/part1.js
Normal file
@ -0,0 +1,66 @@
|
||||
var maps = {};
|
||||
for(var map of require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a))){
|
||||
map = map.split(" => ");
|
||||
maps[map[0]] = map[1];
|
||||
}
|
||||
|
||||
for(var i = 0; i < 1; i++){
|
||||
for(var input of Object.keys(maps)){
|
||||
var lines = input.split("/");
|
||||
rotated = input.split("/").map((line,y)=>(line.split("").map((a, x)=>(lines[lines.length-1-x][y])).join(""))).join("/");
|
||||
maps[rotated] = maps[input];
|
||||
}
|
||||
}
|
||||
|
||||
for(var input of Object.keys(maps)){
|
||||
maps[input.split("/").reverse().join("/")] = maps[input];
|
||||
}
|
||||
|
||||
for(var input of Object.keys(maps)){
|
||||
maps[input.split("/").map(line=>(line.split("").reverse().join(""))).join("/")] = maps[input];
|
||||
}
|
||||
|
||||
function runRound(textInput){
|
||||
var oldGrid = textInput.split("/").map((a)=>(a.split("")));
|
||||
var sideLen = oldGrid[0].length;
|
||||
if(sideLen%2 == 0){
|
||||
var sideSquares = sideLen/2;
|
||||
var squareLen = 2;
|
||||
var newSquareLen = 3;
|
||||
}
|
||||
else if(sideLen%3 == 0){
|
||||
var sideSquares = sideLen/3;
|
||||
var squareLen = 3;
|
||||
var newSquareLen = 4;
|
||||
}
|
||||
|
||||
var newGrid = [];
|
||||
for(var i = 0; i < (sideSquares * newSquareLen); i++){
|
||||
newGrid[i] = [];
|
||||
}
|
||||
|
||||
for(var x = 0; x < sideSquares; x++){
|
||||
for(var y = 0; y < sideSquares; y++){
|
||||
var section = [];
|
||||
for(var i = 0; i < squareLen; i++){
|
||||
section.push(oldGrid[(y*squareLen) + i].slice(x*squareLen, (x+1)*squareLen));
|
||||
}
|
||||
var sectionText = section.map((a)=>(a.join(""))).join("/");
|
||||
var newSectionText = maps[sectionText];
|
||||
var newSection = newSectionText.split("/").map(a=>(a.split("")));
|
||||
for(var x1 = 0; x1 < newSquareLen; x1++){
|
||||
for(var y1= 0; y1 < newSquareLen; y1++){
|
||||
newGrid[(y*newSquareLen) + y1][(x*newSquareLen) + x1] = newSection[y1][x1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return newGrid.map(a=>(a.join(""))).join("/")
|
||||
}
|
||||
|
||||
var currentGrid = ".#./..#/###";
|
||||
var iters = 5;
|
||||
for(var i = 0; i < iters; i++){
|
||||
currentGrid = runRound(currentGrid);
|
||||
}
|
||||
console.log(currentGrid.split("").filter(a=>(a=="#")).length);
|
66
day21/part2.js
Normal file
66
day21/part2.js
Normal file
@ -0,0 +1,66 @@
|
||||
var maps = {};
|
||||
for(var map of require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a))){
|
||||
map = map.split(" => ");
|
||||
maps[map[0]] = map[1];
|
||||
}
|
||||
|
||||
for(var i = 0; i < 1; i++){
|
||||
for(var input of Object.keys(maps)){
|
||||
var lines = input.split("/");
|
||||
rotated = input.split("/").map((line,y)=>(line.split("").map((a, x)=>(lines[lines.length-1-x][y])).join(""))).join("/");
|
||||
maps[rotated] = maps[input];
|
||||
}
|
||||
}
|
||||
|
||||
for(var input of Object.keys(maps)){
|
||||
maps[input.split("/").reverse().join("/")] = maps[input];
|
||||
}
|
||||
|
||||
for(var input of Object.keys(maps)){
|
||||
maps[input.split("/").map(line=>(line.split("").reverse().join(""))).join("/")] = maps[input];
|
||||
}
|
||||
|
||||
function runRound(textInput){
|
||||
var oldGrid = textInput.split("/").map((a)=>(a.split("")));
|
||||
var sideLen = oldGrid[0].length;
|
||||
if(sideLen%2 == 0){
|
||||
var sideSquares = sideLen/2;
|
||||
var squareLen = 2;
|
||||
var newSquareLen = 3;
|
||||
}
|
||||
else if(sideLen%3 == 0){
|
||||
var sideSquares = sideLen/3;
|
||||
var squareLen = 3;
|
||||
var newSquareLen = 4;
|
||||
}
|
||||
|
||||
var newGrid = [];
|
||||
for(var i = 0; i < (sideSquares * newSquareLen); i++){
|
||||
newGrid[i] = [];
|
||||
}
|
||||
|
||||
for(var x = 0; x < sideSquares; x++){
|
||||
for(var y = 0; y < sideSquares; y++){
|
||||
var section = [];
|
||||
for(var i = 0; i < squareLen; i++){
|
||||
section.push(oldGrid[(y*squareLen) + i].slice(x*squareLen, (x+1)*squareLen));
|
||||
}
|
||||
var sectionText = section.map((a)=>(a.join(""))).join("/");
|
||||
var newSectionText = maps[sectionText];
|
||||
var newSection = newSectionText.split("/").map(a=>(a.split("")));
|
||||
for(var x1 = 0; x1 < newSquareLen; x1++){
|
||||
for(var y1= 0; y1 < newSquareLen; y1++){
|
||||
newGrid[(y*newSquareLen) + y1][(x*newSquareLen) + x1] = newSection[y1][x1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return newGrid.map(a=>(a.join(""))).join("/")
|
||||
}
|
||||
|
||||
var currentGrid = ".#./..#/###";
|
||||
var iters = 18;
|
||||
for(var i = 0; i < iters; i++){
|
||||
currentGrid = runRound(currentGrid);
|
||||
}
|
||||
console.log(currentGrid.split("").filter(a=>(a=="#")).length);
|
25
day22/input.txt
Normal file
25
day22/input.txt
Normal file
@ -0,0 +1,25 @@
|
||||
..#..##...##.######.##...
|
||||
..#...#####..#.#####..#..
|
||||
...##.#..##.#.##....#...#
|
||||
#.#.#.#..###...#....##..#
|
||||
..#..#####.....##..#.#..#
|
||||
.##.#####.#.....###.#..#.
|
||||
##..####...#.##.#...##...
|
||||
###.#.#####...##.#.##..#.
|
||||
#.##..##.#....#.#..#.##..
|
||||
###.######......####..#.#
|
||||
###.....#.##.##.######..#
|
||||
...####.###.#....#..##.##
|
||||
#..####.#.....#....###.#.
|
||||
#..##..#.####.#.##..#.#..
|
||||
#..#.#.##...#...#####.##.
|
||||
#.###..#.##.#..##.#######
|
||||
...###..#..####.####.#.#.
|
||||
.#..###..###.#....#######
|
||||
.####..##.#####.#.#..#.#.
|
||||
#.#....##.....##.##.....#
|
||||
....####.....#..#.##..##.
|
||||
######..##..#.###...###..
|
||||
..##...##.....#..###.###.
|
||||
##.#.#..##.#.#.##....##.#
|
||||
.#.###..##..#....#...##.#
|
31
day22/part1.js
Normal file
31
day22/part1.js
Normal file
@ -0,0 +1,31 @@
|
||||
var grid = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a)).reverse().map(a=>(a.split("")));
|
||||
var dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
|
||||
var dir = 0;
|
||||
var x = Math.floor(grid.length/2);
|
||||
var y = Math.floor(grid.length/2);
|
||||
var numInfected = 0;
|
||||
|
||||
for(var i = 0; i < 10000; i++){
|
||||
var clean = true;
|
||||
if(grid[y]){
|
||||
if(grid[y][x] == "#"){
|
||||
clean = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
grid[y] = [];
|
||||
}
|
||||
if(clean){
|
||||
grid[y][x] = "#";
|
||||
numInfected++;
|
||||
dir--;
|
||||
}
|
||||
else{
|
||||
grid[y][x] = ".";
|
||||
dir++;
|
||||
}
|
||||
dir = (dir+4)%4;
|
||||
x += dirs[dir][0];
|
||||
y += dirs[dir][1];
|
||||
}
|
||||
console.log(numInfected);
|
32
day22/part2.js
Normal file
32
day22/part2.js
Normal file
@ -0,0 +1,32 @@
|
||||
var grid = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>(a)).reverse().map(a=>(a.split("")));
|
||||
var dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
|
||||
var dir = 0;
|
||||
var x = Math.floor(grid.length/2);
|
||||
var y = Math.floor(grid.length/2);
|
||||
var numInfected = 0;
|
||||
|
||||
for(var i = 0; i < 10000000; i++){
|
||||
var clean = true;
|
||||
if(grid[y]){
|
||||
if(!grid[y][x]){
|
||||
grid[y][x] = ".";
|
||||
}
|
||||
}
|
||||
else{
|
||||
grid[y] = [];
|
||||
grid[y][x] = ".";
|
||||
}
|
||||
|
||||
var states = [".", "W", "#", "F"];
|
||||
var dirChanges = [-1, 0, 1, 2];
|
||||
dir += dirChanges[states.indexOf(grid[y][x])];
|
||||
grid[y][x] = states[(states.indexOf(grid[y][x])+1) % 4];
|
||||
if(grid[y][x] == "#"){
|
||||
numInfected++;
|
||||
}
|
||||
|
||||
dir = (dir+4)%4;
|
||||
x += dirs[dir][0];
|
||||
y += dirs[dir][1];
|
||||
}
|
||||
console.log(numInfected);
|
32
day23/input.txt
Normal file
32
day23/input.txt
Normal file
@ -0,0 +1,32 @@
|
||||
set b 540
|
||||
set c b
|
||||
jnz a 2
|
||||
jnz 1 5
|
||||
mul b 100
|
||||
sub b -100000
|
||||
set c b
|
||||
sub c -17000
|
||||
set f 1
|
||||
set d 2
|
||||
set e 2
|
||||
set g d
|
||||
mul g e
|
||||
sub g b
|
||||
jnz g 2
|
||||
set f 0
|
||||
sub e -1
|
||||
set g e
|
||||
sub g b
|
||||
jnz g -8
|
||||
sub d -1
|
||||
set g d
|
||||
sub g b
|
||||
jnz g -13
|
||||
jnz f 2
|
||||
sub h -1
|
||||
set g b
|
||||
sub g c
|
||||
jnz g 2
|
||||
jnz 1 3
|
||||
sub b -17
|
||||
jnz 1 -23
|
30
day23/part1.js
Normal file
30
day23/part1.js
Normal file
@ -0,0 +1,30 @@
|
||||
var pc = 0;
|
||||
var registers = {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0};
|
||||
var instructions = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a));
|
||||
var numMul = 0;
|
||||
while((pc >= 0) && (pc < instructions.length)){
|
||||
val = a => ((isNaN(parseInt(a))) ? (registers[a]) : (parseInt(a)));
|
||||
var instruction = instructions[pc];
|
||||
var parts = instruction.split(" ");
|
||||
var pcstart = pc;
|
||||
switch(parts[0]){
|
||||
case "set":
|
||||
registers[parts[1]] = val(parts[2]);
|
||||
break;
|
||||
case "sub":
|
||||
registers[parts[1]] -= val(parts[2]);
|
||||
break;
|
||||
case "mul":
|
||||
numMul++;
|
||||
registers[parts[1]] *= val(parts[2]);
|
||||
break;
|
||||
case "jnz":
|
||||
if(val(parts[1]) != 0){
|
||||
pc += (val(parts[2]) - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pc++;
|
||||
}
|
||||
console.log(numMul);
|
||||
console.log(registers);
|
13
day23/part2.js
Normal file
13
day23/part2.js
Normal file
@ -0,0 +1,13 @@
|
||||
var num = 106700;
|
||||
var end = 123700;
|
||||
var numNotPrime = 0;
|
||||
while(num <= end){
|
||||
for(var i = 2; i <= Math.sqrt(num); i++){
|
||||
if(num%i == 0){
|
||||
i = num;
|
||||
numNotPrime++;
|
||||
}
|
||||
}
|
||||
num += 17;
|
||||
}
|
||||
console.log(numNotPrime);
|
56
day24/input.txt
Normal file
56
day24/input.txt
Normal 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
25
day24/part1.js
Normal 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
28
day24/part2.js
Normal 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);
|
36
day25/part1.js
Normal file
36
day25/part1.js
Normal file
@ -0,0 +1,36 @@
|
||||
var state = "A";
|
||||
var tape = {};
|
||||
var pointer = 0;
|
||||
var actions = {
|
||||
A: [
|
||||
[1, 1, "B"], [0, -1, "B"]
|
||||
],
|
||||
B: [
|
||||
[0, 1, "C"], [1, -1, "B"]
|
||||
],
|
||||
C: [
|
||||
[1, 1, "D"], [0, -1, "A"]
|
||||
],
|
||||
D: [
|
||||
[1, -1, "E"], [1, -1, "F"]
|
||||
],
|
||||
E: [
|
||||
[1, -1, "A"], [0, -1, "D"]
|
||||
],
|
||||
F: [
|
||||
[1, 1, "A"], [1, -1, "E"]
|
||||
],
|
||||
}
|
||||
aactions = {
|
||||
A: [[1,1,"B"],[0,-1,"B"]],
|
||||
B: [[1,-1,"A"],[1,1,"A"]],
|
||||
}
|
||||
for(var i = 0; i < 12629077; i++){
|
||||
var action = actions[state][tape[pointer] ? 1 : 0];
|
||||
//console.log(state, pointer, tape);
|
||||
tape[pointer] = action[0];
|
||||
pointer += action[1];
|
||||
state = action[2];
|
||||
}
|
||||
console.log(tape);
|
||||
console.log(Object.keys(tape).map(a=>(tape[a])).reduce((a,b)=>(a+b)));
|
Loading…
x
Reference in New Issue
Block a user