// If blank strings/ints is not enough
export const inputMapper = (inputs: string) => inputs;

export function solution1(inputs: string[]): number {
  const bulked: string[][] = inputs.reduce((acc, curr) => {
    if (curr !== "") {
      acc[0].push(curr);
      return acc;
    } else {
      return [[], ...acc];
    }
  }, [[]] as string[][]);

  const summed: number[] = bulked.map((group) =>
    group.map((s) => parseInt(s, 10)).reduce((acc, curr) => acc + curr, 0)
  );

  return summed.toSorted((a, b) => b - a)[0];
}

export function solution2(inputs: string[]): number {
  const bulked: string[][] = inputs.reduce((acc, curr) => {
    if (curr !== "") {
      acc[0].push(curr);
      return acc;
    } else {
      return [[], ...acc];
    }
  }, [[]] as string[][]);

  const summed: number[] = bulked.map((group) =>
    group.map((s) => parseInt(s, 10)).reduce((acc, curr) => acc + curr, 0)
  ).toSorted((a, b) => b - a);

  return summed.slice(0, 3).reduce((acc, curr) => acc + curr, 0);
}
