Unique Array Combinations The goal is to write a function or program which takes a set of integer arrays and returns a set of all possible arrays which meet the following criteria:


A valid array must contain at least one number from each of the input arrays.
A valid array cannot contain more than one number from a single input array.
A valid array cannot contain duplicate values.


Additional rules:


Order of the output does not matter.
Input/Output can be in any format you wish.
If no valid arrays exist, the result should be an empty array or blank string.


Examples:

input:
[[1,2],
 [2,1,0],
 [0,3,1]]

output:
[[2,3],
 [1]]




input:
[[1,3,4,7],
 [1,2,5,6],
 [3,4,8],
 [8,9]]

output:
[[6,7,8],
 [5,7,8],
 [2,7,8],
 [4,6,9],
 [4,5,9],
 [2,4,9],
 [3,6,9],
 [3,5,9],
 [2,3,9],
 [1,8]]




input:
[[1,2,3],
 [2,3,4],
 [1,4]]

output:
[]
GolfScript, 36 characters
:I[[]]\{{{|$}+1$/}%|}/{I{1$&amp;,(},!*},

Input/output is standard GolfScript arrays, see in this example.
:I              # save input to variable I

# part 1: generate all possible sets with zero or one numbers from each array
# (zero or one is one char shorter than exactly one which would work also)
[[]]\           # push the set with an empty set
{               # iterate over all input sets
  {             #   iterate over the numbers in the current set
    {|$}+1$/    #     add this number to any set in the result
  }%
  |             #   join with the result set
}/

# part 2: filter for valid sets (i.e. exactly one number from each array)
{               # start of filter block
  I{            #   filter the input array of sets
    1$&amp;         #     calculate overlap of the current set with the input set
    ,(          #     remove if length is equal to one
  },
  !             #   is the list empty? (i.e. all input matched the filter criterion)
  *             #   get rid of the second item on the stack
},              # end of filter block