Recursive backtracking

 

Given an array of ints, is it possible to choose a group of some of the ints, beginning at the start index, such that the group sums to the given target? However, with the additional constraint that all multiples of 3 must be chosen. (No loops needed.)

  • groupSum3(0, [5, 6, 2], 8) → true (since 6 + 2 = 8)

  • groupSum3(0, [5, 6, 2], 9) → false (since 5 + 6 = 11, or 6 + 2 = 8 or 6 are all different from 9)

  • groupSum3(0, [3, 6, 2], 7) → false (since 3 + 6 = 9, 3 + 6 + 2 = 11 are both different from 7)

Start from this file.