-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventofcode-day5.1.js
79 lines (69 loc) · 2.51 KB
/
adventofcode-day5.1.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
68
69
70
71
72
73
74
75
76
77
78
79
const fs = require('fs');
var expect = require('chai').expect;
var inputArray = fs.readFileSync('adventofcode-day5-input.txt').toString().split(",");
function printArray(array) {
for (i = 0; i < array.length; i++) {
console.log(`Index: ${i} - Value: ${array[i]}`);
}
}
function processor(array) {
index = 0
while (index < array.length) {
console.log(`index: `, index, `switch: `, array[index])
switch (array[index]) {
case 1:
console.log(`add: `, array[array[index + 1]], array[array[index + 2]], array[index + 3], `val:`, (array[array[index + 1]] + array[array[index + 2]]));
array[array[index + 3]] = array[array[index + 1]] + array[array[index + 2]];
index = index + 4
// console.log(`add: `, array);
console.log(array);
break;
case 2:
console.log(`mul: `, array[array[index + 1]], array[array[index + 2]], array[index + 3], `val: `, (array[array[index + 1]] * array[array[index + 2]]));
array[array[index + 3]] = array[array[index + 1]] * array[array[index + 2]];
index = index + 4
// console.log(`multiply: `, array);
console.log(array);
break;
case 99:
index = array.length
break;
default:
index = index+1;
}
}
}
// processor(inputArray);
printArray(inputArray);
// describe("Process Operation", function() {
// it("basic program 1", function() {
// var testarray = [1, 0, 0, 0, 99];
// var expectedarray = [2,0,0,0,99];
// processor(testarray);
// expect(expectedarray).to.eql(testarray);
// });
// it("basic program 2", function() {
// var testarray = [2, 3, 0, 3, 99];
// var expectedarray = [2,3,0,6,99];
// processor(testarray);
// expect(expectedarray).to.eql(testarray);
// });
// it("basic program 3", function() {
// var testarray = [2, 4, 4, 5, 99, 0];
// var expectedarray = [2,4,4,5,99,9801];
// processor(testarray);
// expect(expectedarray).to.eql(testarray);
// });
// it("basic program 4", function() {
// var testarray = [1, 1, 1, 4, 99, 5, 6, 0, 99];
// var expectedarray = [30,1,1,4,2,5,6,0,99];
// processor(testarray);
// expect(expectedarray).to.eql(testarray);
// });
// it("basic program 5", function() {
// var testarray = [1,9,10,3,2,3,11,0,99,30,40,50];
// var expectedarray = [3500,9,10,70,2,3,11,0,99,30,40,50];
// processor(testarray);
// expect(expectedarray).to.eql(testarray);
// });
// });