Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. [10:49] Ivan Gocevski | PROLAN
  2.    
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7.  
  8. namespace CrackTheCode2
  9. {
  10.     public class Coordinate
  11.     {
  12.         public int x;
  13.         public int y;
  14.  
  15.  
  16.         public Coordinate(int x, int y)
  17.         {
  18.             this.x = x;
  19.             this.y = y;
  20.         }
  21.  
  22.  
  23.         public string ShowCoordinates()
  24.         {
  25.             return x + ":" + y;
  26.         }
  27.     }
  28.  
  29.  
  30.     public class List : List<Coordinate>
  31.     {
  32.     }
  33.     class Program
  34.     {
  35.         static void Main(string[] args)
  36.         {
  37.             string input = System.IO.File.ReadAllText(@"crack-the-code-2_input.txt");
  38.             //string input = "4:4,4:2,2:4,2:2,4:6,2:6";
  39.  
  40.  
  41.             List<string> list = new List<string>(input.Split(','));
  42.             List<Coordinate> coordinatesList = new List();
  43.             int count = 0;
  44.  
  45.  
  46.             //list = list.Distinct().ToList();
  47.             list.ForEach(item => coordinatesList.Add(new Coordinate(
  48.                 x: int.Parse(item.Substring(0, item.IndexOf(':'))),
  49.                 y: int.Parse(item.Substring(item.IndexOf(':') + 1)))));
  50.             coordinatesList = coordinatesList.OrderBy(item => item.x).ThenBy(item => item.y).ToList();
  51.            
  52.             List<string> added = new List<string>();
  53.  
  54.  
  55.             for (int A = 0; A < coordinatesList.Count; A++)
  56.             {
  57.                 for (int B = A + 1; B < coordinatesList.Count; B++)
  58.                 {
  59.                     if (IsPerpendicularABx(coordinatesList[A], coordinatesList[B]))
  60.                     {
  61.                         for (int C = B + 1; C < coordinatesList.Count; C++)
  62.                         {
  63.                             if (IsPerpendicularACy(coordinatesList[A], coordinatesList[C]))
  64.                             {
  65.                                 for (int D = C + 1; D < coordinatesList.Count; D++)
  66.                                 {
  67.                                     if (IsRectangleABCD(coordinatesList[B], coordinatesList[C], coordinatesList[D]))
  68.                                     {
  69.                                         count++;
  70.                                         added.Add(coordinatesList[A].ShowCoordinates() + " + " +
  71.                                             coordinatesList[B].ShowCoordinates() + " + " +
  72.                                             coordinatesList[C].ShowCoordinates() + " + " +
  73.                                             coordinatesList[D].ShowCoordinates());
  74.                                     }
  75.                                 }
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.  
  82.  
  83.             Console.WriteLine(count);
  84.         }
  85.         private static bool IsPerpendicularABx(Coordinate A, Coordinate B)
  86.         {
  87.             if (A.x == B.x)
  88.             {
  89.                 return true;
  90.             }
  91.  
  92.  
  93.             return false;
  94.         }
  95.  
  96.  
  97.         private static bool IsPerpendicularACy(Coordinate A, Coordinate C)
  98.         {
  99.             if (A.y == C.y)
  100.             {
  101.                 return true;
  102.             }
  103.  
  104.  
  105.             return false;
  106.         }
  107.  
  108.  
  109.         private static bool IsRectangleABCD(Coordinate B, Coordinate C, Coordinate D)
  110.         {
  111.             if (B.y == D.y && C.x == D.x)
  112.             {
  113.                 return true;
  114.             }
  115.  
  116.  
  117.             return false;
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement