コード例 #1
0
ファイル: Program.cs プロジェクト: andnied/public
        static void Main(string[] args)
        {
            int    inches   = 0;
            string tryAgain = string.Empty;

            do
            {
                Console.WriteLine("Please provide the number of inches.");
                var read = Console.ReadLine();

                if (int.TryParse(read, out inches))
                {
                    if (inches < 1)
                    {
                        Console.WriteLine("The number of inches should be greater than 0.");
                    }
                    else
                    {
                        var tree = new MovementTree(inches);
                        tree.FillNodes();
                        var result = tree.CountPaths();

                        Console.WriteLine(string.Format("There are {0} possibilities.", result));
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect argument. Should be a number.");
                }

                Console.WriteLine("Want to try again? (y/n)");
                tryAgain = Console.ReadLine();
            } while (tryAgain == "y");
        }
コード例 #2
0
        public void FillNodes()
        {
            if ((_number - 1) >= 0)
            {
                Left = new MovementTree(_number - 1);
                Left.FillNodes();
            }

            if ((_number - 2) >= 0)
            {
                Right = new MovementTree(_number - 2);
                Right.FillNodes();
            }
        }