/// <summary> /// Go through the triangle recursively and find all valid paths from top to /// bottom only with subjacents items (down and right bottom childs) when parity /// is the opposite of root item (parent) ie. Parent = odd childs must be even. /// </summary> /// <param name="triangle">Input converted to array</param> /// <param name="sum">acumulative value from top to buttom</param> /// <param name="row">current level of array</param> /// <param name="col">current column of array</param> public void FindValidChilds(int[][] triangle, int sum = 0, int row = 0, int col = 0) { var rootValue = triangle[row][col]; arrayNum[row] = rootValue; ResetArrayFromLevel(row); if (row + 1 >= triangle.Length) { return; } if (ParityHelper.AreNotEqual(rootValue, triangle[row + 1][col])) { FindValidChilds(triangle, rootValue + sum, row + 1, col); } if (ParityHelper.AreNotEqual(rootValue, triangle[row + 1][col + 1])) { FindValidChilds(triangle, rootValue + sum, row + 1, col + 1); } CachePathValidOnArrayOfNumbers(); }
public void Asser_Parity_When_Number_Given_A_Number(int number, Parity expected) { Assert.AreEqual(expected, ParityHelper.GetParity(number)); }