this is the solution to acit question

foo uses recursion , bar uses itertools and combination..