chore: day 10 WIP
This commit is contained in:
@@ -17,15 +17,20 @@ export default async function Factory() {
|
|||||||
|
|
||||||
export function count_min_button_presses(manuals: MachineManual[]): number {
|
export function count_min_button_presses(manuals: MachineManual[]): number {
|
||||||
let total_sum = 0;
|
let total_sum = 0;
|
||||||
manuals.forEach((manual) => {
|
manuals.forEach((manual, i) => {
|
||||||
const wiring_list = manual.button_wirings;
|
const wiring_list = manual.button_wirings;
|
||||||
|
|
||||||
let min_presses = Infinity;
|
let min_presses = Infinity;
|
||||||
wiring_list.forEach((wiring, wiring_i) => {
|
wiring_list.forEach((wiring, wiring_i) => {
|
||||||
let current_indicator = manual.indicators.map((i) => i); // Clone the indicator
|
let pairing_indicator = manual.indicators.map((_) => Indicator.OFF);
|
||||||
current_indicator = apply_wiring_to_indicators(wiring, current_indicator);
|
|
||||||
|
|
||||||
if (current_indicator.join("") === manual.indicators.join("")) {
|
// Apply the current wiring
|
||||||
|
pairing_indicator = apply_wiring_to_indicators(
|
||||||
|
wiring,
|
||||||
|
pairing_indicator,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pairing_indicator.join("") === manual.indicators.join("")) {
|
||||||
min_presses = 1;
|
min_presses = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -35,15 +40,71 @@ export function count_min_button_presses(manuals: MachineManual[]): number {
|
|||||||
inner_i < wiring_list.length;
|
inner_i < wiring_list.length;
|
||||||
inner_i++
|
inner_i++
|
||||||
) {
|
) {
|
||||||
current_indicator = apply_wiring_to_indicators(
|
pairing_indicator = manual.indicators.map((_) => Indicator.OFF);
|
||||||
wiring_list[wiring_i],
|
// Apply the current wiring
|
||||||
current_indicator,
|
pairing_indicator = apply_wiring_to_indicators(
|
||||||
|
wiring,
|
||||||
|
pairing_indicator,
|
||||||
);
|
);
|
||||||
|
// Apply the next wiring
|
||||||
|
pairing_indicator = apply_wiring_to_indicators(
|
||||||
|
wiring_list[inner_i],
|
||||||
|
pairing_indicator,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pairing_indicator.join("") === manual.indicators.join("")) {
|
||||||
|
min_presses = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If - not a simple press/pairing found
|
||||||
|
// then - check all combinations
|
||||||
|
//
|
||||||
|
// For size, starts at 1
|
||||||
|
// for index spacing?
|
||||||
|
// OR binary
|
||||||
|
if (min_presses === Infinity) {
|
||||||
|
let cumulative_presses = 0;
|
||||||
|
// DOES NOT MAKE ALL COMBINATIONS, only secuentials
|
||||||
|
wiring_list.forEach((wiring, wiring_i) => {
|
||||||
|
let cumulative_indicator = manual.indicators.map((_) => Indicator.OFF);
|
||||||
|
|
||||||
|
// Apply the current wiring
|
||||||
|
cumulative_indicator = apply_wiring_to_indicators(
|
||||||
|
wiring,
|
||||||
|
cumulative_indicator,
|
||||||
|
);
|
||||||
|
cumulative_presses += 1;
|
||||||
|
|
||||||
|
for (
|
||||||
|
let inner_i = wiring_i + 1;
|
||||||
|
inner_i < wiring_list.length;
|
||||||
|
inner_i++
|
||||||
|
) {
|
||||||
|
cumulative_presses += 1;
|
||||||
|
// Apply the next wiring
|
||||||
|
cumulative_indicator = apply_wiring_to_indicators(
|
||||||
|
wiring_list[inner_i],
|
||||||
|
cumulative_indicator,
|
||||||
|
);
|
||||||
|
if (cumulative_indicator.join("") === manual.indicators.join("")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cumulative_presses < min_presses) {
|
||||||
|
min_presses = cumulative_presses;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(">> Total and min", { total_sum, min_presses });
|
||||||
total_sum += min_presses;
|
total_sum += min_presses;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return total_sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
function apply_wiring_to_indicators(
|
function apply_wiring_to_indicators(
|
||||||
|
|||||||
Reference in New Issue
Block a user