/**
 * One helper the scorer does not need but the board does.
 *
 * `evidence()` in `./score` takes the best alternate's F1 and discards which
 * alternate it was. The reveal on the board wants to mark each cited id as
 * planted or not, and "planted" is only well-defined against the alternate the
 * grader actually scored — so this recovers it, with the same tie-break the
 * scorer uses (first alternate wins a tie). Pure, no `?raw`, testable.
 */

import { f1Exact } from './score';

export function bestAlternate(cites: readonly string[], planted: readonly string[][]): string[] {
  let best: string[] = planted[0] ?? [];
  let bestNum = 0;
  let bestDen = 1;
  for (const alt of planted) {
    const [num, den] = f1Exact(cites, alt);
    if (num * bestDen > bestNum * den) {
      bestNum = num;
      bestDen = den;
      best = alt;
    }
  }
  return best;
}
