-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21.js
50 lines (42 loc) · 747 Bytes
/
21.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
const R = require('ramda')
const I = require('iter-tools')
const intcode = require('./intcode')
// d && !(a && b && c)
const WALK_SCRIPT = `OR A J
AND B J
AND C J
NOT J J
AND D J
WALK
`
// d && !(a && b && c) && (e || h)
const RUN_SCRIPT = `OR A J
AND B J
AND C J
NOT J J
AND D J
OR E T
OR H T
AND T J
RUN
`
const runScript = R.curry((script, input) =>
R.pipe(
intcode.parseRAM,
intcode.spawn,
intcode.iteratorExecutor(
script
.split('')
.map((x) => x.charCodeAt(0))
.values(),
),
I.toArray,
)(input),
)
const getHullDamage = R.curryN(2, R.pipe(runScript, R.last))
const part1 = getHullDamage(WALK_SCRIPT)
const part2 = getHullDamage(RUN_SCRIPT)
module.exports = {
part1,
part2,
}