using System; using System.Collections.Generic; using System.Linq; namespace OOP { class Program { static void Main(string[] args) { int[] dizi =//quest4 { 215, 193, 124, 117, 237, 442, 218, 935, 347, 235, 320, 804, 522, 417, 345, 229, 601, 723, 835, 133, 124, 248, 202, 277, 433, 207, 263, 257, 359, 464, 504, 528, 516, 716, 871, 182, 461, 441, 426, 656, 863, 560, 380, 171, 923, 381, 348, 573, 533, 447, 632, 387, 176, 975, 449, 223, 711, 445, 645, 245, 543, 931, 532, 937, 541, 444, 330, 131, 333, 928, 377, 733, 017, 778, 839, 168, 197, 197, 131, 171, 522, 137, 217, 224, 291, 413, 528, 520, 227, 229, 928, 223, 626, 034, 683, 839, 053, 627, 310, 713, 999, 629, 817, 410, 121, 924, 622, 911, 233, 325, 139, 721, 218, 253, 223, 107, 233, 230, 124, 233 };//array of quest 4. int[] dizi2 = new[] { 1, 2, 3 };//The desired array can be added. int katman = KatmanSay(dizi); List nodes = new List(); TabloOlustur(nodes, katman, dizi); SubCrossRelations(nodes); Traveller(nodes); } public static void SubCrossRelations(List nodes) { foreach (Node node in nodes) { if (node.SearchNode(node.x, node.y, nodes) == null) { return; } if (node.SearchNode(node.x + 1, node.y, nodes) != null) { node.AltNode = node.SearchNode(node.x + 1, node.y, nodes); } if (node.SearchNode(node.x + 1, node.y + 1, nodes) != null) { node.SagNode = node.SearchNode(node.x + 1, node.y + 1, nodes); } } }//makes sub-cross relations between nodes. public static void TabloOlustur(List nodes, int katman, int[] dizi) { int[] sayac = new[] { 0, 0, 0 };//The 1st number counts the x coordinate, the 2nd number counts the y coordinate, the 3rd number is the data of the node. for (int i = 0; i < katman + 1; i++) { sayac[1] = 0; for (int j = 0; j < i; j++) { sayac[1]++; nodes.Add(new Node(sayac[0], sayac[1], dizi[sayac[2]])); sayac[2]++; } sayac[0]++; } }//Adds and names nodes in the form of a coordinate table, equal to the size of the array. public static int KatmanSay(int[] dizi) { int topla = 0, katman = 0; for (int a = 1; topla < dizi.Length; a++) { topla += a; katman++; } return katman; }//counts the depth of the pyramid. public static void Traveller(List nodes) { Node tempNode = nodes[0]; int toplam = 0; int sayi1 = 0, sayi2 = 0; while (tempNode != null) { sayi1 = 0; sayi2 = 0; toplam += tempNode.data; if (tempNode.AltNode != null) { if (!Asalmi(tempNode.AltNode.data)) { sayi1 = tempNode.AltNode.data; } } if (tempNode.SagNode != null) { if (!Asalmi(tempNode.SagNode.data)) { sayi2 = tempNode.SagNode.data; } } if (sayi1 == 0 && sayi2 == 0) { tempNode.Display(); Console.Write("son : "); tempNode = null; break; } else if (sayi2 < sayi1) { tempNode.Display(); tempNode = tempNode.AltNode; } else { tempNode.Display(); tempNode = tempNode.SagNode; } } Console.WriteLine("toplam : " + toplam); }//traveler moving on the pyramid. public static bool Asalmi(int sayi) { for (int i = 2; i <= sayi / 2; i++) { if (sayi % i == 0) { return false; } } return true; }//prime number controll } public class Node { public Node(int x, int y, int data) { this.x = x; this.y = y; this.data = data; }// Constructor public int x { get; set; } public int y { get; set; } public int data { get; set; } //encapsulation properties public Node AltNode { get; set; } public Node SagNode { get; set; } public Node SearchNode(int x, int y, List list) { int sayac = 0; foreach (Node node in list) { if (x == list[sayac].x && y == list[sayac].y) { return list[sayac]; } sayac++; } return null; }// searching a node with koordinats public void Display() { Console.Write("(" + this.x + " " + this.y + " " + this.data + ")"); }//node print code }//Node Class }