-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathto-csv.js
37 lines (30 loc) · 867 Bytes
/
to-csv.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
import { input } from './input.js';
let current_func = [];
let program = [];
for (let line of input) {
if (current_func.length && line.startsWith('inp')) {
program.push([...current_func]);
current_func = [];
}
current_func.push(line);
}
program.push([...current_func]);
let max_func = program.reduce((max, func) => Math.max(max, func.length), 0);
let str = '| ' + program.map((_, i) => `Program ${i}`).join(' | ') + ' |';
str += '\n| ' + program.map((_, i) => `-----`).join(' | ') + ' |';
for (let i = 0; i < max_func; i++) {
let row = [];
let cmds_across = new Set();
for (let func of program) {
let cmd = func[i] || '';
row.push(cmd);
cmds_across.add(cmd);
}
if (cmds_across.size === 1) {
row = '| **' + row.join('** | **') + '** |';
} else {
row = '| ' + row.join(' | ') + ' |';
}
str += str ? '\n' + row : row;
}
console.log(str);