-
Notifications
You must be signed in to change notification settings - Fork 17
/
input.js
61 lines (59 loc) · 1.25 KB
/
input.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
const path = require('path');
const fs = require('fs');
const input = fs
.readFileSync(path.join(__dirname, 'input.txt'), 'utf8')
.toString()
.trim()
.split('\n')
.map((line) => {
// mask = 010X11X110X1101011101000001XX1000100
// mem[25292] = 672982926
if (line.includes('mask')) {
let [, value] = /mask = (.+)$/.exec(line);
return {
type: 'mask',
value,
};
} else {
let [, address, value] = /mem\[(\d+)\] = (\d+)/.exec(line);
address = parseInt(address, 10);
value = parseInt(value, 10);
return {
type: 'write',
address,
value,
};
}
});
const sampleInput = `mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1`
.toString()
.trim()
.split('\n')
.map((line) => {
// mask = 010X11X110X1101011101000001XX1000100
// mem[25292] = 672982926
if (line.includes('mask')) {
let [, value] = /mask = (.+)$/.exec(line);
value = value.split('');
return {
type: 'mask',
value,
};
} else {
let [, address, value] = /mem\[(\d+)\] = (\d+)/.exec(line);
address = parseInt(address, 10);
value = parseInt(value, 10);
return {
type: 'write',
address,
value,
};
}
});
module.exports = {
input,
sampleInput,
};