prog.csp 744 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. define N 20
  2. PROCESSUS ==
  3. [
  4. i = 0 ->
  5. x : integer:= random(0,N); print (i + "? " + x + "\n");
  6. processus[1]!couple(i,x)
  7. []
  8. i /= 0 & i /= N ->
  9. x, j, k, val : integer;
  10. x := random(0,N); print (i + "? " + x + "\n");
  11. k := i;
  12. *[
  13. processus[i-1]?couple(j,val) ->
  14. [
  15. x < val -> processus[i+1]!couple(k,x); x:=val; k:=j
  16. []
  17. x >= val -> processus[i+1]!couple(j,val)
  18. ]
  19. ];
  20. processus[i+1]!couple(k,x)
  21. []
  22. i = N ->
  23. valeur, j : integer;
  24. *[
  25. processus[N-1]?couple(j,valeur) -> print (j + ": " + valeur + "\n")
  26. ]
  27. ]
  28. MAIN ==
  29. [
  30. processus[i:0..N] :: PROCESSUS
  31. ]