Esempio n. 1
0
 private static string BrickRowToString(BrickRow row)
 {
     StringBuilder sb = new StringBuilder();
     for (int idx = 1; idx <= row.RowCracks.Length - 1; idx++)
     {
         sb.Append(row.RowCracks[idx] ? "|" : ".");
     }
     return sb.ToString();
 }
Esempio n. 2
0
        private static void BuildValidRows()
        {
            validBrickRowDefs = new List<string>();
            validBrickRows = new List<BrickRow>();

            int maxBricksWide = wallWidth / 2;

            for (int layout = 0; layout <= (int)Math.Pow(2, maxBricksWide); layout++)
            {
                string brickRowDef = "";
                bool[] brickRowCracks = new bool[wallWidth + 1];
                string layoutString = MiscFunctions.ToBinary(layout, maxBricksWide);
                char[] bricks = layoutString.ToCharArray();
                int widthBricks = 0;
                foreach (char brick in bricks)
                {
                    widthBricks += (brick == '0' ? 2 : 3);
                    if (widthBricks > wallWidth)
                        break;
                    brickRowCracks[widthBricks] = true; // line here!!
                    brickRowDef += brick;
                    if (widthBricks == wallWidth)
                    {
                        if (!validBrickRowDefs.Contains(brickRowDef))
                        {
                            validBrickRowDefs.Add(brickRowDef);
                            BrickRow newRow = new BrickRow(brickRowDef, brickRowCracks);
                            validBrickRows.Add(newRow);
                        }
                        break;
                    }
                }
            }
            Console.WriteLine("Number validRows: {0}", validBrickRows.Count);
        }
Esempio n. 3
0
 private static bool IsValidStack(BrickRow upper, BrickRow lower)
 {
     if (upper.BrickRowDefinition==lower.BrickRowDefinition)
         return false;
     for (int idx = 2; idx < (wallWidth-1); idx++)
     {
         if (upper.RowCracks[idx] && lower.RowCracks[idx])
             return false;
     }
     return true;
 }
Esempio n. 4
0
 private static void DoStacks(int numRowsToAdd, BrickRow topRow)
 {
     for (int idx = 0; idx < topRow.PossibleValidRows.Count; idx++)
     {
         if (numRowsToAdd > 1)
         {
             DoStacks(numRowsToAdd - 1, topRow.PossibleValidRows[idx]);
         }
         else
         {
             numSolutions++;
         }
     }
 }