loading...

re: Daily Challenge #14 - Square into Squares VIEW POST

FULL DISCUSSION
 

I think this works for JavaScript:

function squaresTotaling(max, goal) {
  if (max ** 2 === goal) return [max];
  if (goal <= 0 || max <= 0) return null;
  const subProblem = squaresTotaling(max - 1, goal - max ** 2);
  if (subProblem) return [...subProblem, max];
  return squaresTotaling(max - 1, goal);
}

function decompose(val) {
  return squaresTotaling(val - 1, val ** 2);
}
code of conduct - report abuse