longest = 0
best_comb = nil
ops = %w(+ - * /).map { |o| eval("lambda {|m,n| m.to_f %s n.to_f }" % o) }
for comb in (1..9).to_a.combination(4)
gap_check = Array.new(100, false)
for (a,b,c,d) in comb.permutation
for (o1, o2, o3) in ops.repeated_permutation(3)
p_ords = []
begin p_ords << o3.call(o2.call(o1.call(a, b), c), d) rescue ZeroDivisionError end
begin p_ords << o3.call(o1.call(a, b), o2.call(c, d)) rescue ZeroDivisionError end
begin p_ords << o3.call(o2.call(a, o1.call(b, c)), d) rescue ZeroDivisionError end
begin p_ords << o3.call(a, o2.call(o1.call(b, c), d)) rescue ZeroDivisionError end
begin p_ords << o3.call(a, o2.call(b, o1.call(c, d))) rescue ZeroDivisionError end
for result in p_ords
index = (result % 1 == 0 and result > 0) ? result - 1 : 0
gap_check[index] = true
end
end
end
length = 0
for i in gap_check
break if not i
length += 1
end
if length > longest
longest = length
best_comb = comb
end
end
puts best_comb.join("")