add virtual implementation for reading input file
This commit is contained in:
parent
53b7f05dee
commit
419f225bd0
7
Day.cs
7
Day.cs
|
@ -1,16 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace aoc2019
|
||||
{
|
||||
public abstract class Day
|
||||
{
|
||||
public abstract int DayNumber { get; }
|
||||
public virtual IEnumerable<string> Input =>
|
||||
File.ReadLines($"input/day{DayNumber}.in");
|
||||
|
||||
public virtual void AllParts()
|
||||
{
|
||||
Console.WriteLine($"Day {DayNumber}:");
|
||||
Console.WriteLine(Part1());
|
||||
Console.WriteLine(Part2());
|
||||
}
|
||||
|
||||
public abstract string Part1();
|
||||
public abstract string Part2();
|
||||
}
|
||||
|
|
7
Day1.cs
7
Day1.cs
|
@ -8,8 +8,11 @@ namespace aoc2019
|
|||
{
|
||||
public override int DayNumber => 1;
|
||||
|
||||
private readonly IEnumerable<int> masses =
|
||||
File.ReadLines("input/day1.in").Select(int.Parse);
|
||||
private readonly IEnumerable<int> masses;
|
||||
public Day1()
|
||||
{
|
||||
masses = Input.Select(int.Parse);
|
||||
}
|
||||
|
||||
private static int FuelCost(int weight) => weight / 3 - 2;
|
||||
private static int FullCost(int cost)
|
||||
|
|
7
Day2.cs
7
Day2.cs
|
@ -8,8 +8,11 @@ namespace aoc2019
|
|||
{
|
||||
public override int DayNumber => 2;
|
||||
|
||||
private readonly IEnumerable<int> input =
|
||||
File.ReadLines("input/day2.in").First().Split(',').Select(int.Parse);
|
||||
private readonly IEnumerable<int> input;
|
||||
public Day2()
|
||||
{
|
||||
input = Input.First().Split(',').Select(int.Parse);
|
||||
}
|
||||
|
||||
public int RunIntCode(int noun, int verb)
|
||||
{
|
||||
|
|
2
Day3.cs
2
Day3.cs
|
@ -14,7 +14,7 @@ namespace aoc2019
|
|||
|
||||
public Day3()
|
||||
{
|
||||
wires = File.ReadAllLines("input/day3.in").Select(ParseWire).ToList();
|
||||
wires = Input.Select(ParseWire).ToList();
|
||||
intersections = wires[0].Keys.Intersect(wires[1].Keys);
|
||||
}
|
||||
|
||||
|
|
4
Day4.cs
4
Day4.cs
|
@ -12,9 +12,7 @@ namespace aoc2019
|
|||
|
||||
public Day4()
|
||||
{
|
||||
var range = File.ReadLines("input/day4.in")
|
||||
.First().Split('-').Select(int.Parse).ToList();
|
||||
|
||||
var range = Input.First().Split('-').Select(int.Parse).ToList();
|
||||
start = range[0]; end = range[1];
|
||||
}
|
||||
|
||||
|
|
7
Day5.cs
7
Day5.cs
|
@ -8,8 +8,11 @@ namespace aoc2019
|
|||
{
|
||||
public override int DayNumber => 5;
|
||||
|
||||
private readonly IEnumerable<int> tape =
|
||||
File.ReadLines("input/day5.in").First().Split(',').Select(int.Parse);
|
||||
private readonly IEnumerable<int> tape;
|
||||
public Day5()
|
||||
{
|
||||
tape = Input.First().Split(',').Select(int.Parse);
|
||||
}
|
||||
|
||||
private int output;
|
||||
public void RunIntCode(List<int> v, int input)
|
||||
|
|
Loading…
Reference in New Issue