using System.Collections.Generic;
private const string testInput = @"1
private const string input = @"215
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";
static void Main(string[] args)
List<string> pyramidList = InputToList(testInput);
int lineCount = FindLineCount(pyramidList);
int[,] pyramidArray = ListToArray(pyramidList, lineCount);
List<int> way = PathFinder(pyramidArray, lineCount);
foreach (var item in way)
Console.WriteLine("Sum: "+ sum);
private static List<string> InputToList(string input)
string[] inputArray = input.Split("\n");
List<string> allNumberLine = new List<string>();
foreach (var item in inputArray)
if (item != "\n" || item != " ")
allNumberLine.Add(item.Trim(' '));
List<string> allNumber = new List<string>();
foreach (var line in allNumberLine)
foreach (var number in line.Split(" "))
private static int FindLineCount(List<string> pyramidList)
for (int i = 0; i < pyramidList.Count; i++)
if (numberCount == pyramidList.Count)
private static int[,] ListToArray(List<string> pyramidList, int lineCount)
int[,] pyramidArray = new int[lineCount, lineCount];
for (int x = 0; x < lineCount; x++)
for (int y = 0; y <= x; y++)
pyramidArray[x, y] = int.Parse(pyramidList[numberCounter]);
public static bool IsPrime(int number)
if (number <= 1) return false;
if (number == 2) return true;
if (number % 2 == 0) return false;
var boundary = (int)Math.Floor(Math.Sqrt(number));
for (int i = 3; i <= boundary; i += 2)
public static List<int> PathFinder(int[,] pyramidArray, int lineCount)
List<int> way = new List<int>();
way.Add(pyramidArray[currentX, currentY]);
for (int x = 0; x <= lineCount; x++)
bool updateCurrentIndex = true;
if (currentX + 1 >= lineCount)
if (!IsPrime(pyramidArray[currentX + 1, currentY]) && IsPrime(pyramidArray[currentX + 1, currentY + 1]))
nextNumber = pyramidArray[currentX + 1, currentY];
updateCurrentIndex = true;
else if (!IsPrime(pyramidArray[currentX + 1, currentY + 1]) && IsPrime(pyramidArray[currentX + 1, currentY]))
nextNumber = pyramidArray[currentX + 1, currentY + 1];
updateCurrentIndex = false;
else if (!IsPrime(pyramidArray[currentX + 1, currentY]) && !IsPrime(pyramidArray[currentX + 1, currentY + 1]))
if (pyramidArray[currentX + 1, currentY] > pyramidArray[currentX + 1, currentY + 1])
nextNumber = pyramidArray[currentX + 1, currentY];
updateCurrentIndex = true;
nextNumber = pyramidArray[currentX + 1, currentY + 1];
updateCurrentIndex = false;