-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyramidModel.cs
More file actions
57 lines (46 loc) · 1.23 KB
/
PyramidModel.cs
File metadata and controls
57 lines (46 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Text;
namespace PyramidSolver
{
public class PyramidModel
{
private readonly int[,] _data;
public PyramidModel(PyramidModel pyramid)
{
_data = (int[,])pyramid._data.Clone();
Rows = pyramid.Rows;
}
public PyramidModel(int[,] data)
{
_data = data;
Rows = data.GetLength(0);
}
public PyramidModel(int rows)
{
_data = new int[rows, rows];
Rows = rows;
}
public int this[int row, int col]
{
get => _data[row, col];
set => _data[row, col] = value;
}
public int Rows { get; }
/// <summary>
/// Pretty print me
/// </summary>
public override string ToString()
{
var sb = new StringBuilder();
for (var row = 0; row < Rows; row++)
{
sb.Append(new string(' ', 8 * row / 2));
for (var col = 0; col < Rows - row; col++)
{
sb.AppendFormat("[{0:00000}] ", _data[row, col]);
}
sb.AppendLine();
}
return sb.ToString();
}
}
}