language: Ocaml (ocamlopt 3.10.2)
date: 153 days 6 hours ago
link:
visibility: public
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
81
82
83
84
85
86
87
88
89
90
91
92
let emit_digit () =
  let n = Random.int 10 in
  let c = Char.chr ((Char.code '0') + n) in
  Format.printf "%c" c
  
let emit_digit_sequence max =
  let n = Random.int max in
  for i = 0 to n do emit_digit () done
 
let emit_lit () =
  emit_digit_sequence 18;
  let emit_dot = Random.int 100 < 50 in
  if emit_dot
  then begin
      Format.printf ".";
      emit_digit_sequence 18;
    end;
  if (not emit_dot) || Random.int 100 < 50
  then begin
      Format.printf "e";
      if Random.int 2 = 0 then Format.printf "-";
      emit_digit_sequence 2
    end
 
let emit_binary emit_term op =
  emit_term ();
  Format.printf "%c" op;
  emit_term ()
 
let emit_nary emit_term op =
  let n = Random.int 5 in
  emit_term ();
  for i = 0 to n do
    Format.printf "%c" op;
    emit_term ()
  done
 
let rec emit_expr emit_leaf h =
  if h = 0 || Random.int 100 < 20
  then emit_leaf ()
  else begin
      let r = Random.int 100 in
      Format.printf "(";
      let emit_sub_expr () = emit_expr emit_leaf (h - 1) in
      if r < 25
      then emit_nary emit_sub_expr '+'
      else if r < 50
      then emit_binary emit_sub_expr '-'
      else if r < 75
      then emit_nary emit_sub_expr '*'
      else emit_binary emit_sub_expr '/';
      Format.printf ")";
    end
 
let emit_constant_expr () = emit_expr emit_lit (Random.int 5)
 
let emit_var i =
  Format.printf "x%d" i
 
let emit_random_var n = emit_var (Random.int n)
 
let _ = 
  Random.self_init ();
  let n_var = 2 + Random.int 5 in
  let emit_lit_or_var () =
    if Random.int 100 < 30
    then emit_lit ()
    else 
      emit_random_var n_var
  in
  Format.printf "#include <stdio.h>\n";
  for i = 0 to n_var - 1 do
    Format.printf "double x%d = " i;
    emit_constant_expr ();
    Format.printf ";\n";
  done;
  Format.printf "\nint main(){\n";
  let emit_expr () = 
    emit_expr emit_lit_or_var (Random.int 4) 
  in
  let emit_assign () =
    Format.printf "  ";
    emit_random_var n_var;
    Format.printf " = ";
    emit_expr();
    Format.printf ";\n";
  in
  for i = 1 to 3 do
    emit_assign ()
  done;
  Format.printf "  printf(\"%%a\\n\", x0);\n}@.";
 
  • upload with new input
  • result: Success     time: 0.02s    memory: 2780 kB     returned value: 0

    #include <stdio.h>
    double x0 = 825634640508239e23;
    double x1 = 6636.31217950705102708e2;
    double x2 = ((80214130149305515e-58*90706647e8*200379768798010e-3*7.01036277)+08255310.86202e6+363592443e8);
    double x3 = ((41450e-4-47714.0552)/467792219620223596e8);
    
    int main(){
      x2 = (((x1-1819e-59)+(828914897.731630196045-x2))*((x3/961860608725560453.840769)/(x3/x3)));
      x0 = (x1-250862064485.51222150371e-7);
      x3 = x3;
      printf("%a\n", x0);
    }