-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpart-one.js
67 lines (63 loc) · 2.72 KB
/
part-one.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { samples } = require('./input');
const { isEqual } = require('lodash');
const DeviceInstructions = require('./device-instructions');
// Number of sample inputs that behave like three or more opcodes?
let answer = samples
.map(line => {
let { instruction, before, after } = line;
// Trim off opcode from instruction (we don't know what it maps to yet)
instruction = instruction.slice(1);
return [
new DeviceInstructions(before).addr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).addi(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).mulr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).muli(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).banr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).bani(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).borr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).bori(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).setr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).seti(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).gtir(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).gtri(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).gtrr(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).eqir(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).eqri(...instruction).toString() === after.toString()
? 1
: 0,
new DeviceInstructions(before).eqrr(...instruction).toString() === after.toString()
? 1
: 0,
].reduce((a, b) => a + b, 0);
})
.map(possibilites => (possibilites >= 3 ? 1 : 0))
.reduce((a, b) => a + b, 0);
console.log(answer);