svephoto

The song of the wheels [C#]

Aug 10th, 2021 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TheSongOfTheWheels
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int controlValue = int.Parse(Console.ReadLine());
  10.  
  11.             int combinationsCount = 0;
  12.            
  13.             int i = 0;
  14.             int j = 0;
  15.             int k = 0;
  16.             int l = 0;
  17.             int sum = 0;
  18.            
  19.             bool theFourth = false;
  20.             bool row = false;
  21.  
  22.             for (int first = 1; first <= 9; first++)
  23.             {
  24.                 for (int second = 1; second <= 9; second++)
  25.                 {
  26.                     for (int third = 1; third <= 9; third++)
  27.                     {
  28.                         for (int fourth = 1; fourth <= 9; fourth++)
  29.                         {
  30.                             sum = (first * second) + (third * fourth);
  31.  
  32.                             if (first < second && third > fourth && sum == controlValue)
  33.                             {
  34.                                 row = true;
  35.                                 combinationsCount++;
  36.  
  37.                                 Console.Write($"{first}{second}{third}{fourth} ");
  38.  
  39.                                 if (combinationsCount == 4)
  40.                                 {
  41.                                     theFourth = true;
  42.                                     i = first;
  43.                                     j = second;
  44.                                     k = third;
  45.                                     l = fourth;
  46.                                 }
  47.                             }
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.                
  53.             if (row)
  54.             {
  55.                Console.WriteLine();                    
  56.             }
  57.                  
  58.             if (theFourth)
  59.             {
  60.                Console.WriteLine($"Password: {i}{j}{k}{l}");
  61.             }
  62.             else
  63.             {
  64.                Console.WriteLine("No!");
  65.             }
  66.         }
  67.     }
  68. }
  69.  
Add Comment
Please, Sign In to add comment