Exemple #1
0
        public void Solve(IPlotter plotter)
        {
            // Given a magnitude N
            // Place N queens in a NxN chess board
            // in such a way that no queens attack each other

            const int size  = 8;
            var       board = _strategy.Solve(size);

            plotter.Plot(" ");
            for (var file = 1; file <= board.Size; file++)
            {
                plotter.Plot(" ");
                plotter.Plot(file.ToString());
            }
            plotter.PlotLine("");
            for (var rank = 1; rank <= board.Size; rank++)
            {
                plotter.Plot(rank.ToString());
                for (var file = 1; file <= board.Size; file++)
                {
                    plotter.Plot(" ");
                    plotter.Plot(board[rank, file].HasQueen ? "Q" : "-");
                }
                plotter.PlotLine("");
            }
        }
 public static void PlotValues <T>(this IPlotter plotter, string name, ReadOnlySpan <T> values)
 {
     plotter.PlotLine($"{name}:");
     for (var i = 0; i < values.Length; i++)
     {
         plotter.PlotValue($"  {i}", values[i]);
     }
 }
        public void Solve(IPlotter plotter)
        {
            // Given an array of numbers that represent the values of each coin
            // Given an amount
            // Find the minimum number of coins that are needed to make that amount

            ReadOnlySpan <int> coins = stackalloc int[] { 1, 5, 10, 25, 50 };
            const int          value = 74;

            var solution = _strategy.Solve(coins, value);

            plotter.PlotValue(nameof(value), value);
            for (var i = 0; i < coins.Length; i++)
            {
                plotter.PlotLine($"{solution[i]} coin(s) of {coins[i]}");
            }
        }
    }
 public static void PlotValue <T>(this IPlotter plotter, string name, T value)
 {
     plotter.PlotLine($"{name}: {value}");
 }