day13 part 1
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
844a52bbec
commit
dea4e1014f
|
@ -20,6 +20,7 @@ namespace aoc2020.test
|
|||
[DataRow(typeof(Day10), "1980", "4628074479616")]
|
||||
[DataRow(typeof(Day11), "2303", "2057")]
|
||||
[DataRow(typeof(Day12), "1710", "62045")]
|
||||
[DataRow(typeof(Day13), "171", "")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
// create day instance
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace aoc2020
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 13: <see href="https://adventofcode.com/2020/day/13">Shuttle Search</see>
|
||||
/// </summary>
|
||||
public sealed class Day13 : Day
|
||||
{
|
||||
private readonly long _earliest;
|
||||
private readonly string[] _fullSchedule;
|
||||
private readonly long[] _buses;
|
||||
|
||||
public Day13() : base(13)
|
||||
{
|
||||
_earliest = long.Parse(Input.First());
|
||||
_fullSchedule = Input.Last().Split(',');
|
||||
_buses = _fullSchedule.Where(c => c != "x").Select(long.Parse).ToArray();
|
||||
}
|
||||
|
||||
public override string Part1()
|
||||
{
|
||||
for (var i = _earliest; ; i++)
|
||||
{
|
||||
if (_buses.Any(b => i % b == 0))
|
||||
{
|
||||
var bus = _buses.First(b => i % b == 0);
|
||||
return $"{bus * (i - _earliest)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
1000417
|
||||
23,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,37,x,x,x,x,x,479,x,x,x,x,x,x,x,x,x,x,x,x,13,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,373,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19
|
Loading…
Reference in New Issue