Sha256: 4482b72376a0385a0c6cd17bb1f7ed1975fd6d9dcb2d3cbb3271ab092dce9b8e
Contents?: true
Size: 1.36 KB
Versions: 263
Compression:
Stored size: 1.36 KB
Contents
using System; using System.Collections.Generic; public class Minesweeper { public static string Annotate(string input) { var results = new List<string>(); var board = input.Split("\n".ToCharArray()); for (int i = 0; i < board.Length; i++) { var result = string.Empty; for (int j = 0; j < board[0].Length; j++) { if (board[i][j] == '*') { result += '*'; } else { var numMines = GetCountForSquare(board, i, j); result += numMines == 0 ? " " : numMines.ToString(); } } results.Add(result); } return string.Join("\n", results); } private static int GetCountForSquare(string[] board, int x, int y) { var result = 0; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { try { if (board[x + i][y + j] == '*') { result++; } } catch (IndexOutOfRangeException) { } } } return result; } }
Version data entries
263 entries across 263 versions & 1 rubygems