Skip to content

Commit

Permalink
feat(Program): accept day as arg through dotnet run
Browse files Browse the repository at this point in the history
  • Loading branch information
sindrekjr committed Dec 30, 2021
1 parent 44928ae commit fd6c724
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions AdventOfCode.Solutions/SolutionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ string LoadInput(bool debug = false)
}

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

string ResultToString(int part, SolutionResult result) =>
$" - Part{part} => " + (string.IsNullOrEmpty(result.Answer)
Expand Down
6 changes: 0 additions & 6 deletions AdventOfCode.Solutions/SolutionCollector.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using AdventOfCode.Services;

namespace AdventOfCode.Solutions;

public static class SolutionCollector
{
public static IEnumerable<SolutionBase> FetchSolutions() => FetchSolutions(ConfigurationService.GetYear(), ConfigurationService.GetDays());

public static IEnumerable<SolutionBase> FetchSolutions(int year) => FetchSolutions(year, ConfigurationService.GetDays());

public static IEnumerable<SolutionBase> FetchSolutions(int year, IEnumerable<int> days)
{
if (days.Sum() == 0) days = Enumerable.Range(1, 25).ToArray();
Expand Down
11 changes: 8 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using AdventOfCode.Solutions;
using AdventOfCode.Services;
using AdventOfCode.Solutions;

Console.WriteLine();
foreach (var solution in SolutionCollector.FetchSolutions())
var year = ConfigurationService.GetYear();
var days = ConfigurationService.GetDays();

if (args.Length > 0 && int.TryParse(args.First(), out int day)) days = new[] { day };

foreach (var solution in SolutionCollector.FetchSolutions(year, days))
{
Console.WriteLine(solution.ToString());
}

0 comments on commit fd6c724

Please sign in to comment.