Пример #1
0
        public override Task <Number> MultiplyNumbers(NumberPair request, ServerCallContext context)
        {
            var response = new Number()
            {
                Content = request.X * request.Y
            };

            return(Task.FromResult(response));
        }
Пример #2
0
        static async Task <int> MultiplyNumbers(int x, int y)
        {
            var data = new NumberPair()
            {
                X = x, Y = y
            };
            var response = await client.MultiplyNumbersAsync(data);

            return(response.Content);
        }
Пример #3
0
        private bool IsPairValid(NumberPair pair, IArithmeticOp op)
        {
            if (_gameConfig.MinValueInQuestion != 0)
            {
                if (pair.Number1 == 0 || pair.Number2 == 0)
                {
                    return(false);
                }
            }

            return(op.IsValid(pair));
        }
 static NumberPair GetNumberPair(string value)
 {
     if (numberPairXref.ContainsKey(value))
     {
         return(new NumberPair(numberPairXref[value]));
     }
     else
     {
         NumberPair pair = new NumberPair(value);
         numberPairXref.Add(value, new NumberPair(pair));
         return(pair);
     }
 }
Пример #5
0
        public static int TestExplicitLayoutStruct()
        {
            var color = new Color()
            {
                Value = 0xAABBCCDD
            };
            var a    = color.Value + GetColorR(ref color) + GetColorG(color) + color.GetColorB() + color.A;
            var pair = new NumberPair()
            {
                SignedA   = -13,
                UnsignedB = 37
            };
            var b = pair.SignedA - ((int)pair.UnsignedA) + pair.SignedB - ((int)pair.UnsignedB);

            return(((int)a) + b);
        }
Пример #6
0
    private static Dictionary <NumberPair, int> FindPairwiseCosts(Cell[,] maze, List <NumberedLocation> numbered)
    {
        Dictionary <NumberPair, int> best = new();

        // Run BFS starting from each numbered location to find the best path between each pair of numbered
        // locations in the maze. This gives us the building blocks necessary to find the overall best path
        // later on by brute force.
        foreach (NumberedLocation start in numbered)
        {
            HashSet <Cell> visited = new();
            Queue <Cell>   q       = new();
            int            depth   = 0;

            q.Enqueue(start.Cell);
            visited.Add(start.Cell);

            while (q.Count > 0)
            {
                int cellsInCurrentLevel = q.Count;
                while (cellsInCurrentLevel > 0)
                {
                    Cell curr = q.Dequeue();

                    if (depth > 0 && char.IsDigit(curr.Char))
                    {
                        NumberPair pair = new NumberPair(start.Number, curr.Char - '0');
                        best[pair] = depth;
                    }

                    List <Cell> neighbors = FindNeighbors(maze, curr, visited);
                    neighbors.ForEach(n => visited.Add(n));
                    neighbors.ForEach(n => q.Enqueue(n));

                    cellsInCurrentLevel--;
                }
                depth++;
            }
        }

        return(best);
    }