require 'yaml'
def foo(prob)
if prob < 0.25
return "*"
elsif prob < 0.5
return "+"
elsif prob < 0.75
return "/"
else
return "-"
end
end
def bar(prob)
if prob < 0.25
return "("
else
return ""
end
end
def tas(prob)
if prob < 0.25
return ")"
else
return ""
end
end
solutions_hash = Hash.new
for i in 1..100000
formula = ""
bracket_counter = 0
e = ""
b = ""
for i in 1..9
formula = formula + i.to_f.to_s
if bracket_counter > 0
e = tas(rand())
end
bracket_counter -= 1 if ")" == e
formula = formula + e
formula = formula + foo(rand()) unless 9 == i
b = bar(rand()) unless 9 == i
bracket_counter += 1 if "(" == b
formula = formula + b
e = ""
b = ""
end
for i in 1..9
if bracket_counter > 0
formula = formula + ")"
bracket_counter -= 1
end
end
begin
a = eval(formula)
if 0 == (a - a.to_i)
if a > 1899 and a < 2101
solutions_hash[a] = formula
File.open("num/"+a.to_s, 'w') {|f| f.write(formula)}
if a > 1909 and a < 1913
puts "HEEEEEYYYYYYYYYY"
puts formula
puts a
puts "HEEEEYYYYY"
end
end
else
end
rescue
end
end
puts solutions_hash.to_yaml