Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [10:49] Ivan Gocevski | PROLAN
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CrackTheCode2
- {
- public class Coordinate
- {
- public int x;
- public int y;
- public Coordinate(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public string ShowCoordinates()
- {
- return x + ":" + y;
- }
- }
- public class List : List<Coordinate>
- {
- }
- class Program
- {
- static void Main(string[] args)
- {
- string input = System.IO.File.ReadAllText(@"crack-the-code-2_input.txt");
- //string input = "4:4,4:2,2:4,2:2,4:6,2:6";
- List<string> list = new List<string>(input.Split(','));
- List<Coordinate> coordinatesList = new List();
- int count = 0;
- //list = list.Distinct().ToList();
- list.ForEach(item => coordinatesList.Add(new Coordinate(
- x: int.Parse(item.Substring(0, item.IndexOf(':'))),
- y: int.Parse(item.Substring(item.IndexOf(':') + 1)))));
- coordinatesList = coordinatesList.OrderBy(item => item.x).ThenBy(item => item.y).ToList();
- List<string> added = new List<string>();
- for (int A = 0; A < coordinatesList.Count; A++)
- {
- for (int B = A + 1; B < coordinatesList.Count; B++)
- {
- if (IsPerpendicularABx(coordinatesList[A], coordinatesList[B]))
- {
- for (int C = B + 1; C < coordinatesList.Count; C++)
- {
- if (IsPerpendicularACy(coordinatesList[A], coordinatesList[C]))
- {
- for (int D = C + 1; D < coordinatesList.Count; D++)
- {
- if (IsRectangleABCD(coordinatesList[B], coordinatesList[C], coordinatesList[D]))
- {
- count++;
- added.Add(coordinatesList[A].ShowCoordinates() + " + " +
- coordinatesList[B].ShowCoordinates() + " + " +
- coordinatesList[C].ShowCoordinates() + " + " +
- coordinatesList[D].ShowCoordinates());
- }
- }
- }
- }
- }
- }
- }
- Console.WriteLine(count);
- }
- private static bool IsPerpendicularABx(Coordinate A, Coordinate B)
- {
- if (A.x == B.x)
- {
- return true;
- }
- return false;
- }
- private static bool IsPerpendicularACy(Coordinate A, Coordinate C)
- {
- if (A.y == C.y)
- {
- return true;
- }
- return false;
- }
- private static bool IsRectangleABCD(Coordinate B, Coordinate C, Coordinate D)
- {
- if (B.y == D.y && C.x == D.x)
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement