-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 1 KB
/
index.js
File metadata and controls
49 lines (41 loc) · 1 KB
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
const fs = require('fs')
const charset = 'utf-8'
const eol = '\n'
const tab = ' '
const inputs = [
'inputs/a_example.in',
'inputs/b_small.in',
'inputs/c_medium.in',
'inputs/d_quite_big.in',
'inputs/e_also_big.in'
]
function chunkToLines(input) {
const lines = input.split(eol)
lines.pop()
return lines
}
function chunkToNumbers(line) {
return line.split(tab).map(Number)
}
function parse(file) {
const input = fs.readFileSync(file, charset)
const lines = chunkToLines(input)
const [maxCapacity, populationCount] = chunkToNumbers(lines.shift())
const weights = chunkToNumbers(lines.shift())
return {
maxCapacity, populationCount, weights
}
}
function solve({ maxCapacity = 0, populationCount = 0, weights = [] }) {
console.log(`solving with maxCapacity=${
maxCapacity
} and populationCount=${
populationCount
}`)
}
function run() {
for (const input of inputs) {
console.log(solve(parse(input)))
}
}
run()