-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (70 loc) · 2.33 KB
/
Program.cs
File metadata and controls
78 lines (70 loc) · 2.33 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AoC2020.Application;
namespace AoC2020
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 4)
{
Console.WriteLine("Arguments: --event <int> --file <string> --second?");
return;
}
var argsEvent = GetArgsValue(args, "-e", "--event");
var argsFile = GetArgsValue(args, "--file");
var linesEnumerable = GetLines(argsFile);
var second = GetArgsExist(args, "--second");
IEventApp app;
switch (argsEvent)
{
case "1": {
app = new One(linesEnumerable, 2020);
break;
}
case "2": {
app = new Two(linesEnumerable);
break;
}
case "3": {
app = new Three(linesEnumerable);
break;
}
case "4": {
app = new Four(linesEnumerable);
break;
}
case "5": {
app = new Five(linesEnumerable);
break;
}
case "6": {
app = new Six(linesEnumerable);
break;
}
default:
Console.WriteLine("No registered runner for event: " +argsEvent);
return;
}
app.Run(second);
return;
}
private static string GetArgsValue(string[] args, params string[] flags) {
var value = "";
var index = Array.FindIndex(args, a => flags.Contains(a));
if(index != -1) {
value = args[index+1];
}
return value;
}
private static bool GetArgsExist(string[] args, params string[] flags) {
return Array.FindIndex(args, a => flags.Contains(a)) != -1;
}
private static IEnumerable<string> GetLines(string fileSource) {
return File.ReadLines(fileSource);
}
}
}