jsadvent/solutions/2017/1.js

23 lines
454 B
JavaScript
Raw Normal View History

2020-12-10 08:33:00 +00:00
const { Glib } = require('../../lib');
const VALUE = {
'(': 1,
')': -1,
};
module.exports = {
'1': (input) =>
Glib.fromIterable(input)
2020-12-13 06:52:00 +00:00
.filter((char, index) => char === input[(index + 1n) % input.lengthN])
2020-12-10 08:33:00 +00:00
.toInts()
.sum(),
'2': (input) =>
Glib.fromIterable(input)
.filter(
(char, index) =>
2020-12-13 06:52:00 +00:00
char === input[(index + input.lengthN / 2n) % input.lengthN],
2020-12-10 08:33:00 +00:00
)
.toInts()
.sum(),
};