Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
      #do nothing
    end
  rescue
    #inf error
  end
end

puts solutions_hash.to_yaml