[ann] nim-ocaml

I read a paper maybe not this one, but it seems it talks about the same thing
https://arxiv.org/html/2506.04657v1.
At the beginning I thought it’s about the new programming language, but then chatgpt explained me that in fact it’s a small game with stones. We put a given number of stones in the middle, and each player can take 1, 2 or 3 stones from the stack. There are two variants of the game, the one that only has one stone in front of him at the end wins or not.

So I tryed to make a nim-ocaml to play against its Random.state, here below:

let () =
  Random.self_init () ;
  let n = 13 + (Random.int 23) in
  let _n = ref n in
  let run = ref true in
  while !run do
    Printf.printf "%d\n" !_n;
    if !_n <= 1 then run := false ;
    let line = read_line () in
    begin
      try
        let d = int_of_string line in
        _n := !_n - d ;
      with _ ->
        Printf.printf "please input an integer number\n%!";
    end;
    let b = Random.int 2 + Random.int 3 in
    Printf.printf "b played: %d\n" b;
    _n := !_n - b ;
  done;
  Printf.printf "done!\n" ;
$ \ocaml nim.ml 

Or later:

$ wget http://decapode314.free.fr/ocaml2/nim/nim.ml
$ \ocaml nim.ml
23
3
b played: 3
17
7
b played: 0
10
3
b played: 2
5
2
b played: 2
1
0
b played: 0
done!

Another version to play against your collegue at the pause:

$ wget http://decapode314.free.fr/ocaml2/nim/.gil/nim.ml.0