fork download
  1. let rec opCycle (xs : int[]) i su =
  2. if i >= xs.Length then false else
  3. let x = xs.[i]
  4. su := !su - 2 * x
  5. xs.[i] <- -x
  6. if x > 0 then true else opCycle xs (i + 1) su
  7.  
  8. do
  9. let m, origin = 209, [| 1; 24; 2; 2; 8; 44; 3; 42; 4; 8; 9; 2; 2; 7; 9; 4; 3; 5; 2; 4; 9; 5; 3; 2; 3; 2; 1; 1 |]
  10. //let m, origin = 99, [| 1; 8; 4; 3; 2; 4; 8; 9; 2; 2; 7; 9; 4; 3; 5; 2; 4; 9; 5; 3; 2; 3; 2; 1; 1 |]
  11. //let m, origin = 5, [| 1; 4; -2; 2 |]
  12. let xs = Array.copy origin
  13. let su = Array.sum origin |> ref
  14.  
  15. let rec run su =
  16. if !su = m then
  17. printf "%i" xs.[0]
  18. Array.iter2 (fun x o -> printf " %s %i" (if x = o then "+" else "-") o) xs.[1..] origin.[1..]
  19. printfn " = %i" m
  20. if opCycle xs 1 su then run su
  21. run su
Success #stdin #stdout 2.46s 11912KB
stdin
Standard input is empty
stdout
1 + 24 + 2 + 2 + 8 + 44 + 3 + 42 + 4 + 8 + 9 + 2 + 2 + 7 + 9 + 4 + 3 + 5 + 2 + 4 + 9 + 5 + 3 + 2 + 3 + 2 - 1 + 1 = 209
1 + 24 + 2 + 2 + 8 + 44 + 3 + 42 + 4 + 8 + 9 + 2 + 2 + 7 + 9 + 4 + 3 + 5 + 2 + 4 + 9 + 5 + 3 + 2 + 3 + 2 + 1 - 1 = 209