using System.Collections.Generic;
namespace SoftwareDeveloperQuestinary
public static int lastSelectedIndex = 0;
static void Main(string[] args)
string fileName = "triangle.txt";
string text = File.ReadAllText(fileName);
string[] lines = text.Split(Environment.NewLine);
List<int> line1 = lines[0].Trim(' ').Split(' ').Select(Int32.Parse).ToList();
List<int> line2 = lines[1].Trim(' ').Split(' ').Select(Int32.Parse).ToList();
List<int> line3 = lines[2].Trim(' ').Split(' ').Select(Int32.Parse).ToList();
List<int> line4 = lines[3].Trim(' ').Split(' ').Select(Int32.Parse).ToList();
isPrimeAndMax(line1,lastSelectedIndex);
isPrimeAndMax(line2,lastSelectedIndex);
isPrimeAndMax(line3,lastSelectedIndex);
isPrimeAndMax(line4,lastSelectedIndex);
public static List<int> isPrime(List<int> listForCheck)
List<int> notPrimeList = new List<int>();
for (int i = 0; i < listForCheck.Count; i++)
while (j != listForCheck[i])
if (listForCheck[i] % j == 0)
notPrimeList.Add(listForCheck[i]);
public static void isPrimeAndMax(List<int> listForCheck, int indexOfPreviousSelected)
if (listForCheck.Count == 1 )
Console.WriteLine($"*{listForCheck[0]} ");
if (listForCheck.Count != 2)
for (int i = 0; i <= indexOfPreviousSelected; i++)
Console.Write($"{listForCheck[i]} ");
List<int> orderedList = listForCheck.OrderByDescending(x => x).ToList();
List<int> maxAndNotPrime = isPrime(orderedList);
for (int i = indexOfPreviousSelected; i < indexOfPreviousSelected +2; i++)
while (j != maxAndNotPrime.Count)
if (listForCheck[i] == maxAndNotPrime[j])
if (listForCheck[i].Equals(listForCheck.Last()))
Console.WriteLine($"*{listForCheck[i]} ");
Console.Write($"*{listForCheck[i]} ");
if (listForCheck.Count > 2)
for (int i = indexOfPreviousSelected + 2; i <= listForCheck.Count; i++)
if (i == listForCheck.Count -1)
Console.WriteLine(listForCheck[i]);
Console.Write($"{listForCheck[i]} ");
Console.WriteLine(listForCheck[1]);