DyNaMiXx7

Untitled

Oct 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Stopwatch stopWatch = new Stopwatch();
  9.         stopWatch.Start();
  10.         int numberOfCombination = int.Parse(Console.ReadLine());
  11.         int counter = 0;
  12.  
  13.         if (numberOfCombination >= 1 && numberOfCombination <= 13_983_816)
  14.         {
  15.             for (int firstNumber = 1; firstNumber <= 44; firstNumber++)
  16.             {
  17.                 for (int secondNumber = firstNumber + 1; secondNumber <= 45; secondNumber++)
  18.                 {
  19.                     for (int thirdNumber = secondNumber + 1; thirdNumber <= 46; thirdNumber++)
  20.                     {
  21.                         for (int fourthNumber = thirdNumber + 1; fourthNumber <= 47; fourthNumber++)
  22.                         {
  23.                             for (int fifthNumber = fourthNumber + 1; fifthNumber <= 48; fifthNumber++)
  24.                             {
  25.                                 for (int sixthNumber = fifthNumber + 1; sixthNumber <= 49; sixthNumber++)
  26.                                 {
  27.                                     string combination = firstNumber.ToString() + "-" + secondNumber.ToString() + "-" + thirdNumber.ToString() + "-" + fourthNumber.ToString() + "-" + fifthNumber.ToString() + "-" + sixthNumber.ToString();
  28.                                     counter++;
  29.                                     if (numberOfCombination == counter)
  30.                                     {
  31.                                         Console.WriteLine($"Lottery combination: {combination}");
  32.                                         Console.WriteLine("Your chance to win is 1/13 983 816, so good luck! :)");
  33.                                         stopWatch.Stop();
  34.                                         TimeSpan ts = stopWatch.Elapsed;
  35.                                         string elapsedTime = String.Format("{0:00} seconds.{1:00} milliseconds", ts.Seconds, ts.Milliseconds / 10);
  36.                                         Console.WriteLine($"Execution time: {elapsedTime}");
  37.                                         return;
  38.                                     }
  39.                                 }
  40.                             }
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.         else
  47.         {
  48.             stopWatch.Stop();
  49.             TimeSpan ts = stopWatch.Elapsed;
  50.             string elapsedTime = String.Format("{0:00} seconds.{1:00} milliseconds", ts.Seconds, ts.Milliseconds / 10);
  51.             Console.WriteLine("Input a valid number between 1-13_983_816 for the combination!");
  52.             Console.WriteLine($"Execution time: {elapsedTime}");
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment