Example #1
0
        static void Main(string[] args)
        {
            var pyramid = PyramidNode.Load(Properties.Resources.PyramidP18);

            Console.WriteLine(pyramid.GetBestSum());

            Console.ReadLine();
        }
Example #2
0
 public PyramidNode(int number, int index, int level)
 {
     this.number = number;
     this.index  = index;
     this.level  = level;
     this.left   = null;
     this.right  = null;
 }
Example #3
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled       = true,
                LightEstimationEnabled = true,
                PlaneDetection         = ARPlaneDetection.Horizontal,
                WorldAlignment         = ARWorldAlignment.Gravity
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            CubeNode cubeNode = new CubeNode(size, UIColor.Red);

            cubeNode.Position = new SCNVector3(0, 0, zPosition);

            SphereNode sphereNode = new SphereNode(size, UIColor.Yellow);

            sphereNode.Position = new SCNVector3(0.3f, 0, zPosition);

            TorusNode torusNode = new TorusNode(size / 2, size / 4, UIColor.Blue);

            torusNode.Position = new SCNVector3(0.6f, 0, zPosition);

            TubeNode tubeNode = new TubeNode(size / 2, size / 2, size * 2, UIColor.Orange);

            tubeNode.Position = new SCNVector3(0.9f, 0, zPosition);

            ConeNode coneNode = new ConeNode(0.0001f, size / 2, size * 2, UIColor.Green);

            coneNode.Position = new SCNVector3(0, -0.3f, zPosition);

            CylinderNode cylinderNode = new CylinderNode(size, size * 2, UIColor.Cyan);

            cylinderNode.Position = new SCNVector3(0.3f, -0.3f, zPosition);

            PyramidNode pyramidNode = new PyramidNode(size * 2, size * 2, size * 2, UIColor.Brown);

            pyramidNode.Position = new SCNVector3(0.6f, -0.3f, zPosition);

            PlaneNode planeNode = new PlaneNode(size, size, UIColor.Purple);

            planeNode.Position = new SCNVector3(0.9f, -0.3f, zPosition);

            TextNode textNode = new TextNode("Hello from ARKit", 0.01f, UIColor.Orange);

            textNode.Position = new SCNVector3(0, -0.85f, zPosition);

            sceneView.Scene.RootNode.AddChildNode(cubeNode);
            sceneView.Scene.RootNode.AddChildNode(sphereNode);
            sceneView.Scene.RootNode.AddChildNode(torusNode);
            sceneView.Scene.RootNode.AddChildNode(tubeNode);
            sceneView.Scene.RootNode.AddChildNode(coneNode);
            sceneView.Scene.RootNode.AddChildNode(cylinderNode);
            sceneView.Scene.RootNode.AddChildNode(pyramidNode);
            sceneView.Scene.RootNode.AddChildNode(planeNode);
            sceneView.Scene.RootNode.AddChildNode(textNode);
        }
        /// <summary>
        /// Walk the Path and Calculate Sum
        /// </summary>
        /// <param name="pyramid"></param>
        /// <returns></returns>
        public ResultModel WalkAndCalculate(Pyramid pyramid)
        {
            ResultModel resultModel = new ResultModel();

            if (pyramid == null)
            {
                throw new ArgumentNullException("Root Doesn't Exist");
            }

            //First node is the Parent
            PyramidNode parent = pyramid.nodes.FirstOrDefault();

            //Include the Parent in the Sum
            int sum = parent.number;

            //Set level to next
            int level = 0;

            ++level;

            //Add root to the Path
            resultModel.path.Add(parent.number);

            //Traverse Pyramid Levels
            while (level <= pyramid.level)
            {
                //Get the next node
                PyramidNode pathNode = pyramid.nodes.Where(n => n.level == level)
                                       .Where(n => n.IsOdd() != parent.IsOdd())
                                       .Where(n => parent.left.index == n.index || parent.right.index == n.index)
                                       .OrderByDescending(n => n.number)
                                       .FirstOrDefault();

                //If there is no node Return
                if (null == pathNode)
                {
                    resultModel.path.Clear();
                    return(resultModel);
                }
                else
                {
                    //Update the Sum
                    sum += pathNode.number;
                    //Node is the new Parent
                    parent = pathNode;
                    //Include the node in the Path
                    resultModel.path.Add(pathNode.number);
                    //Ready for next level
                    level++;
                }
            }

            //Include calculated Sum and Return
            resultModel.maxSum = sum;
            return(resultModel);
        }
Example #5
0
 /// <summary>
 /// Set left and right Nodes for a Parent
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 public void SetLeftRight(PyramidNode left, PyramidNode right)
 {
     this.left  = left;
     this.right = right;
 }