Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Quick
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var rand = new Random();
  10.             var successes = 0;
  11.             var failures = 0;
  12.             var highestFailure = 0;
  13.  
  14.             for (int i = 0; i < 10000; i++)
  15.             {
  16.                 int total = 0;
  17.                 int peak = 0;
  18.  
  19.                 do
  20.                 {
  21.                     total += rand.Next(1, 20);
  22.                     if (total > peak)
  23.                     {
  24.                         peak = total;
  25.                     }
  26.                     total -= 4;
  27.  
  28.                     if (total >= 10000000)
  29.                     {
  30.                         successes++;
  31.                         break;
  32.                     }
  33.                 }
  34.                 while (total > 0);
  35.  
  36.                 if (total <= 0)
  37.                 {
  38.                     if (peak > highestFailure)
  39.                     {
  40.                         highestFailure = peak;
  41.                     }
  42.                     failures++;
  43.                 }
  44.             }
  45.  
  46.             Console.WriteLine($"successes:{successes}");
  47.             Console.WriteLine($"failures:{failures}");
  48.             Console.WriteLine($"highest failure:{highestFailure}");
  49.             Console.Read();
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement