Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created November 26, 2025 18:11
Show Gist options
  • Select an option

  • Save goofballLogic/07d3a6886e50cb2759e28689e509ecd4 to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/07d3a6886e50cb2759e28689e509ecd4 to your computer and use it in GitHub Desktop.
const taskListEndsAt = ts =>
Math.max(...ts.map(t => t[2]));
const maybeAdd = (ts, candidate) =>
(taskListEndsAt(ts) <= candidate[1])
? [ts, [...ts, candidate]]
: [ts]
;
const combinations = ts =>
ts.reduce(
(combinations, t) =>
[
...combinations.flatMap(c => maybeAdd(c, t)),
[t]
],
[]
);
const choose = ts =>
combinations(ts).reduce(
(found, cs) => (cs.length > found.length) ? cs : found,
[]
);
const summarise = chosen =>
({
count: chosen.length,
chosen: chosen.map(x => x[0])
});
const maxMealPrepTasks = ts =>
summarise(choose(ts));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment