-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.cs
48 lines (46 loc) · 1.4 KB
/
Factory.cs
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
using System;
namespace Sudoku_Solver
{
static class Factory
{
public static Sudoku CreateSudoku()
{
Console.WriteLine("Reading sudoku from user input");
int[] init = new int[81];
for (int i = 0; i <= 72; i += 9)
{
Console.Write("Line {0}: ", i / 9 + 1);
string input = Console.ReadLine();
char[] line = input.ToCharArray();
try
{
if (input.Length == 9)
{
for (int j = 0; j < line.Length; j++)
{
init[i + j] = int.Parse(line[j].ToString());
}
}
else
{
throw new IndexOutOfRangeException("Input does not contain 9 characters");
}
}
catch (Exception e)
{
if (e is IndexOutOfRangeException || e is FormatException)
{
Console.WriteLine(e.Message);
i -= 9;
}
else
{
throw;
}
}
}
Console.WriteLine("");
return new Sudoku(init);
}
}
}