def paths(arrs)
      arrs.inject([[]]) do |paths, arr|
        arr.map {|e| paths.map {|path| path + [e]}}.flatten(1)
      end
    end
def paths(arrs)
      arrs.inject([[]]) do |paths, arr|
        arr.map {|e| paths.map {|path| path + [e]}}.flatten(1)
      end
    end
Return an array of all possible paths through the given arrays.

 @param arrs [Array<Array>]
 @return [Array<Arrays>]

 @example
   paths([[1, 2], [3, 4], [5]]) #=>
     # [[1, 3, 5],
     #  [2, 3, 5],
     #  [1, 4, 5],
     #  [2, 4, 5]]