Ejemplo n.º 1
0
        /// <summary>
        /// The main method that is called outside this class that will solve the puzzle
        /// and return the answer
        /// </summary>
        /// <returns>The answer to the puzzle</returns>
        public int solvePuzzle()
        {
            // load the data from the PuzzleData.txt
            string puzzleData = this.LoadPuzzleDataIntoMemory();

            // create an instance of bagParser which will parse the puzzleData text
            Bags.BagParser bagParser = new Bags.BagParser();
            // parze the puzzle data text
            System.Collections.Hashtable bags = bagParser.parseBagText(puzzleData);
            // find the "shiny gold" bag
            Bags.Bag aBag = (Bags.Bag)bags["shiny gold"];

            // count how many unique parent bags the "shiny gold" bag has
            this.findParentBags(aBag);
            // return the unique number of parent bags the "shiny gold" bag has
            return(this._uniqueParentBags.Count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main method that is called outside this class that will solve the puzzle
        /// and return the answer
        /// </summary>
        /// <returns>The answer to the puzzle</returns>
        public int solvePuzzle()
        {
            // load the data from the PuzzleData.txt
            string puzzleData = this.LoadPuzzleDataIntoMemory();

            // create an instance of bagParser which will parse the puzzleData text
            Bags.BagParser bagParser = new Bags.BagParser();
            // parze the puzzle data text
            System.Collections.Hashtable bags = bagParser.parseBagText(puzzleData);
            // find the "shiny gold" bag
            Bags.Bag aBag = (Bags.Bag)bags["shiny gold"];

            int NoParentBags = 1;
            // count the number of child bags within aBag
            int answer = this.FindAllChildBags_Test(aBag, NoParentBags);

            return(answer);
        }