示例#1
0
文件: Day_08.cs 项目: LEPT0N/toybox
 public void remove_all(c_display_segment other)
 {
     for (int i = 0; i < m_possibilities.Length; i++)
     {
         if (other.m_possibilities[i])
         {
             m_possibilities[i] = false;
         }
     }
 }
示例#2
0
文件: Day_08.cs 项目: LEPT0N/toybox
            public c_display(string[] inputs)
            {
                // Convert the input strings to c_displayed_numbers and bucket by input length

                List <c_displayed_number>[] inputs_by_length = new List <c_displayed_number> [10];

                foreach (string input in inputs)
                {
                    if (inputs_by_length[input.Length] == null)
                    {
                        inputs_by_length[input.Length] = new List <c_displayed_number>();
                    }

                    c_displayed_number displayed_number = new c_displayed_number(input);
                    inputs_by_length[input.Length].Add(displayed_number);
                }

                // Build our c_display_segments and remove possibilities from them one at a time.
                c_display_segment top_left     = new c_display_segment();
                c_display_segment top_right    = new c_display_segment();
                c_display_segment bottom_left  = new c_display_segment();
                c_display_segment bottom_right = new c_display_segment();
                c_display_segment top          = new c_display_segment();
                c_display_segment middle       = new c_display_segment();
                c_display_segment bottom       = new c_display_segment();

                // 1
                {
                    // There is only one c_display_number with 2 lights on
                    c_displayed_number displayed_number = inputs_by_length[2][0];

                    top.remove_all(displayed_number);
                    middle.remove_all(displayed_number);
                    bottom.remove_all(displayed_number);
                    top_left.remove_all(displayed_number);
                    bottom_left.remove_all(displayed_number);

                    top_right.remove_all_except(displayed_number);
                    bottom_right.remove_all_except(displayed_number);
                }

                // 7
                {
                    // There is only one c_display_number with 3 lights on
                    c_displayed_number displayed_number = inputs_by_length[3][0];

                    middle.remove_all(displayed_number);
                    bottom.remove_all(displayed_number);
                    top_left.remove_all(displayed_number);
                    bottom_left.remove_all(displayed_number);

                    top.remove_all_except(displayed_number);
                    top_right.remove_all_except(displayed_number);
                    bottom_right.remove_all_except(displayed_number);
                }

                // 4
                {
                    // There is only one c_display_number with 4 lights on
                    c_displayed_number displayed_number = inputs_by_length[4][0];

                    top.remove_all(displayed_number);
                    bottom.remove_all(displayed_number);
                    bottom_left.remove_all(displayed_number);

                    middle.remove_all_except(displayed_number);
                    top_left.remove_all_except(displayed_number);
                    top_right.remove_all_except(displayed_number);
                    bottom_right.remove_all_except(displayed_number);
                }

                // 2 or 3 or 5
                {
                    List <c_displayed_number> displayed_numbers = inputs_by_length[5];

                    // bottom and bottom_left now only have (the same) two possibilities.
                    // bottom_left shows up once in [2, 3, 5], while bottom shows up in all of them.
                    bottom_left.remove_all_except_matches_count(displayed_numbers, 1);
                    bottom.remove_all(bottom_left);

                    // top_left and middle now only have (the same) two possibilities.
                    // top_left shows up once in [2, 3, 5], while middle shows up in all of them.
                    top_left.remove_all_except_matches_count(displayed_numbers, 1);
                    middle.remove_all(top_left);
                }

                // 6 or 9 or 0
                {
                    List <c_displayed_number> displayed_numbers = inputs_by_length[6];

                    // top_right and bottom_right now only have (the same) two possibilities.
                    // top_right shows up twice in [6, 9, 0], while bottom_right shows up in all of them.
                    top_right.remove_all_except_matches_count(displayed_numbers, 2);
                    bottom_right.remove_all(top_right);
                }

                // each of the c_display_segment's now only have one possibility remaining.
                char top_left_wire     = top_left.get_first_possibility();
                char top_right_wire    = top_right.get_first_possibility();
                char bottom_left_wire  = bottom_left.get_first_possibility();
                char bottom_right_wire = bottom_right.get_first_possibility();
                char top_wire          = top.get_first_possibility();
                char middle_wire       = middle.get_first_possibility();
                char bottom_wire       = bottom.get_first_possibility();

                // We now know exactly what wires are in each number, so save them for later.

                char[][] wires = new char[][]
                {
                    // 0
                    new char[]
                    {
                        top_left_wire,
                        top_right_wire,
                        bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        // middle_wire,
                        bottom_wire,
                    },

                    // 1
                    new char[]
                    {
                        // top_left_wire,
                        top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        // top_wire,
                        // middle_wire,
                        // bottom_wire,
                    },

                    // 2
                    new char[]
                    {
                        // top_left_wire,
                        top_right_wire,
                        bottom_left_wire,
                        // bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },

                    // 3
                    new char[]
                    {
                        // top_left_wire,
                        top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },

                    // 4
                    new char[]
                    {
                        top_left_wire,
                        top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        // top_wire,
                        middle_wire,
                        // bottom_wire,
                    },

                    // 5
                    new char[]
                    {
                        top_left_wire,
                        // top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },

                    // 6
                    new char[]
                    {
                        top_left_wire,
                        // top_right_wire,
                        bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },

                    // 7
                    new char[]
                    {
                        // top_left_wire,
                        top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        // middle_wire,
                        // bottom_wire,
                    },

                    // 8
                    new char[]
                    {
                        top_left_wire,
                        top_right_wire,
                        bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },

                    // 9
                    new char[]
                    {
                        top_left_wire,
                        top_right_wire,
                        // bottom_left_wire,
                        bottom_right_wire,
                        top_wire,
                        middle_wire,
                        bottom_wire,
                    },
                };

                for (int i = 0; i < 10; i++)
                {
                    m_displayed_numbers[i] = new c_displayed_number(wires[i]);
                }
            }