Skip to content

Commit fd6c724

Browse files
committed
feat(Program): accept day as arg through dotnet run
1 parent 44928ae commit fd6c724

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

AdventOfCode.Solutions/SolutionBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ string LoadInput(bool debug = false)
133133
}
134134

135135
public override string ToString() =>
136-
$"--- Day {Day}: {Title} --- {(Debug ? "!! Debug mode active, using DebugInput !!" : "")}\n"
136+
$"\n--- Day {Day}: {Title} --- {(Debug ? "!! Debug mode active, using DebugInput !!" : "")}\n"
137137
+ $"{ResultToString(1, Part1)}\n"
138-
+ $"{ResultToString(2, Part2)}\n";
138+
+ $"{ResultToString(2, Part2)}";
139139

140140
string ResultToString(int part, SolutionResult result) =>
141141
$" - Part{part} => " + (string.IsNullOrEmpty(result.Answer)

AdventOfCode.Solutions/SolutionCollector.cs

-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
using AdventOfCode.Services;
2-
31
namespace AdventOfCode.Solutions;
42

53
public static class SolutionCollector
64
{
7-
public static IEnumerable<SolutionBase> FetchSolutions() => FetchSolutions(ConfigurationService.GetYear(), ConfigurationService.GetDays());
8-
9-
public static IEnumerable<SolutionBase> FetchSolutions(int year) => FetchSolutions(year, ConfigurationService.GetDays());
10-
115
public static IEnumerable<SolutionBase> FetchSolutions(int year, IEnumerable<int> days)
126
{
137
if (days.Sum() == 0) days = Enumerable.Range(1, 25).ToArray();

Program.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
using AdventOfCode.Solutions;
1+
using AdventOfCode.Services;
2+
using AdventOfCode.Solutions;
23

3-
Console.WriteLine();
4-
foreach (var solution in SolutionCollector.FetchSolutions())
4+
var year = ConfigurationService.GetYear();
5+
var days = ConfigurationService.GetDays();
6+
7+
if (args.Length > 0 && int.TryParse(args.First(), out int day)) days = new[] { day };
8+
9+
foreach (var solution in SolutionCollector.FetchSolutions(year, days))
510
{
611
Console.WriteLine(solution.ToString());
712
}

0 commit comments

Comments
 (0)