fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int randto(int n) {
  6. int r, maxr = (RAND_MAX / n) * n;
  7. do r = rand(); while (r >= maxr);
  8. return r % n;
  9. }
  10.  
  11. int main(void) {
  12. srand((unsigned)time(0));
  13. int len = 0;
  14. int count[1000] = {0};
  15. for (int i = 0; i < 1000000; i++) {
  16. int dealer = randto(13);
  17. int player = randto(13);
  18. if (player == dealer) {
  19. continue;
  20. }
  21. if (player > 6) {
  22. if (player > dealer) {
  23. len++;
  24. } else {
  25. count[len]++;
  26. len = 0;
  27. }
  28. } else {
  29. if (player < 6) {
  30. if (player < dealer) {
  31. len++;
  32. } else {
  33. count[len]++;
  34. len = 0;
  35. }
  36. } else {
  37. }
  38. }
  39. }
  40. int countlow = 0;
  41. int counthigh = 0;
  42. for (int i = 0; i < 25; i++) countlow += count[i];
  43. for (int i = 25; i < 1000; i++) counthigh += count[i];
  44. printf("losses: %d; wins: %d. Percentage %.2f\n", countlow, counthigh, (counthigh * 100.0)/countlow);
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.04s 5476KB
stdin
Standard input is empty
stdout
losses: 176942; wins: 502. Percentage 0.28