Skip to content

Commit 9008409

Browse files
committed
refactor(FormatHelper): added old formatting option and changed function names; removed ASolution.ToString()
1 parent 2f6cd20 commit 9008409

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

AdventOfCode/Infrastructure/Helpers/FormatHelper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ namespace AdventOfCode.Infrastructure.Helpers
66
{
77
static class FormatHelper
88
{
9-
public static string FormatDay(ASolution solution) => solution.ToString();
9+
public static string SimpleFormat(ASolution solution)
10+
=> $"--- {FormatTitle(solution.Day, solution.Title)} --- \n"
11+
+ (solution.Debug ? FormatDebug(solution.DebugInput) + "\n" : "")
12+
+ $"Part 1: {solution.Part1.Answer}\n"
13+
+ $"Part 2: {solution.Part2.Answer}\n";
14+
15+
public static string FunctionFormat(ASolution solution)
16+
=> $"{FormatTitle(solution.Day, solution.Title)}\n"
17+
+ (solution.Debug ? FormatDebug(solution.DebugInput) + "\n" : "")
18+
+ $"{FormatPart(1, solution.Part1)}\n"
19+
+ $"{FormatPart(2, solution.Part2)}\n";
1020

1121
public static string FormatTitle(int day, string title) => $"Day {day}: {title}";
1222

AdventOfCode/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using AdventOfCode.Infrastructure;
33
using AdventOfCode.Infrastructure.Helpers;
4-
using AdventOfCode.Infrastructure.Models;
54
using AdventOfCode.Solutions;
65

76
namespace AdventOfCode
@@ -15,7 +14,7 @@ static void Main(string[] args)
1514
foreach (ASolution solution in Solutions)
1615
{
1716
Console.WriteLine();
18-
Console.WriteLine(FormatHelper.FormatDay(solution));
17+
Console.WriteLine(FormatHelper.FunctionFormat(solution));
1918
}
2019
}
2120
}

AdventOfCode/Solutions/ASolution.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ private protected ASolution(int day, int year, string title, bool useDebugInput
3030
Debug = useDebugInput;
3131
_input = new Lazy<string>(() => InputHelper.LoadInput(Day, Year));
3232
_debugInput = new Lazy<string>(() => InputHelper.LoadDebugInput(Day, Year));
33-
_part1 = new Lazy<SolutionResult>(() => Solver(SolvePartOne));
34-
_part2 = new Lazy<SolutionResult>(() => Solver(SolvePartTwo));
33+
_part1 = new Lazy<SolutionResult>(() => SolveSafely(SolvePartOne));
34+
_part2 = new Lazy<SolutionResult>(() => SolveSafely(SolvePartTwo));
3535
}
3636

3737
public IEnumerable<SolutionResult> Solve(int part = 0)
@@ -47,13 +47,7 @@ public IEnumerable<SolutionResult> Solve(int part = 0)
4747
}
4848
}
4949

50-
public override string ToString()
51-
=> $"{FormatHelper.FormatTitle(Day, Title)}\n"
52-
+ (Debug ? FormatHelper.FormatDebug(DebugInput) + "\n" : "")
53-
+ $"{FormatHelper.FormatPart(1, Part1)}\n"
54-
+ $"{FormatHelper.FormatPart(2, Part2)}\n";
55-
56-
SolutionResult Solver(Func<string> SolverFunction)
50+
SolutionResult SolveSafely(Func<string> SolverFunction)
5751
{
5852
if (Debug)
5953
{

0 commit comments

Comments
 (0)