Commit 899c1511 authored by Philipp Rummelsberger's avatar Philipp Rummelsberger
Browse files

.

parent b49d7f3e
const importer = require('../utils/import');
function reduceData(element, rows, lowerHalf, upperHalf, start, end) {
const el = element.substr(start, end);
el.split('').forEach(letter => {
if (rows.length === 2) {
if (letter === lowerHalf) {
rows = rows[0];
} else if (letter === upperHalf) {
rows = rows[1];
}
return
}
if (!Array.isArray(rows)) {
return
}
if (letter === lowerHalf) {
rows = rows.splice(0, (rows.length / 2));
} else if (letter === upperHalf) {
rows = rows.splice((rows.length / 2), rows.length - 1);
}
});
return rows;
}
function inputArray(size) {
return new Array(size).fill(1).map((_, index) => index);
}
function groupBy(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
async function exec() {
const result = await importer.importInputAsArray('../day_05/input.txt')
.then(result => result.split("\n").filter(res => !!res).map(res => res.trim()))
.then(result => {
return result.map(res => {
const row = reduceData(res, inputArray(128), 'F', 'B', 0, 7);
const column = reduceData(res, inputArray(8), 'L', 'R', 7, 9);
const id = row * 8 + column;
return {
row: row,
column: column,
id: id,
}
});
})
.then(result => result.sort((a, b) => a.id - b.id))
.then(result => groupBy(result, 'row'))
.then(result => {
return Object.keys(result).map(key => {
if (result[key].length !== 8 && key !== '2' && key !== '103') {
return result[key]
}
return null
}).filter(res => !!res)
})
// .then(result => result.sort((a, b) => b.row - a.row))
console.log('TADA ', result);
}
exec()
FBFBBFBRRL
BBFFBFFRLR
FBBFFBBLLL
FBFBFBFRRR
FBBBFFFLLL
FFBFBBFLLR
BFBBBFBLRR
BFBBBFFRLL
FBFFBFFLLL
BFBFBFFRLR
FBFBFFBLLL
FBFFBBFLLR
FBFBBBBLRR
BFFBBBFLLL
BFBBFBBLLL
FBFFFFBLRL
BFBFFFFLRR
BFBBFFBRRL
FBFFFFBLLL
FBBBBFFRLR
BFBBBFBLRL
BBFFBFBRRL
FBBFFFBRRL
FFBFBBFRRL
FFFFBBFLLR
FBFFFBBR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