def match word
	return [ "a", "ab" ] if word =~ /^ab/
	return [ "de" ] if word =~ /^de/
	return [ word[0,1] ] if word =~ /^[a-d]/
	nil
end

def parts word
	return nil if word.length == 0
	matches = match( word )
	return nil if matches.nil?
	arry = []
	for match in matches
		sub = [ match ]
		sub << parts( word[match.length..-1] ) unless word == match
		arry << sub 
	end
	arry
end

=begin
def string x
	return x.to_s unless x.is_a? Array
	rv = "[ "
	x.each { |i| rv << string(i) ; rv << ", " }
	rv << " ]"
	rv
end
=end

def flatten array
	return nil if array.nil?
	return array unless array.is_a? Array
	return flatten(array[0]) if array.length == 1
	tmp = []
	array.each { |x|
		tmp << flatten(x)
	}
	if !tmp[0].is_a? Array and tmp[1].is_a? Array
		if !tmp[1][0].is_a? Array
			rv = [tmp[0]]
			rv += tmp[1]
			return rv 
		end
	end
	tmp
end

# Removes all combinations that would include nils
def compress array
	rv = []
	string = []

	for item in array
		if item.is_a? Array
			subitems = compress item if item.is_a? Array
			subitems.each { |substring| 
				rv << string+substring unless substring.nil?
			} unless subitems.nil?
		else
			return nil if item.nil?
			string << item.to_s
		end
	end
	rv.unshift string if string.length > 0 and rv.length == 0
	rv
end
