day 13 part 2
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dea4e1014f
commit
e6ffe8050a
|
@ -20,7 +20,7 @@ namespace aoc2020.test
|
|||
[DataRow(typeof(Day10), "1980", "4628074479616")]
|
||||
[DataRow(typeof(Day11), "2303", "2057")]
|
||||
[DataRow(typeof(Day12), "1710", "62045")]
|
||||
[DataRow(typeof(Day13), "171", "")]
|
||||
[DataRow(typeof(Day13), "171", "539746751134958")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
// create day instance
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace aoc2020
|
|||
var s = Stopwatch.StartNew();
|
||||
var part1 = Part1();
|
||||
s.Stop();
|
||||
Console.Write($"Part1: {part1,-14} ");
|
||||
Console.Write($"Part1: {part1,-15} ");
|
||||
Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");
|
||||
|
||||
s.Reset();
|
||||
|
@ -37,7 +37,7 @@ namespace aoc2020
|
|||
s.Start();
|
||||
var part2 = Part2();
|
||||
s.Stop();
|
||||
Console.Write($"Part2: {part2,-14} ");
|
||||
Console.Write($"Part2: {part2,-15} ");
|
||||
Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");
|
||||
|
||||
Console.WriteLine();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace aoc2020
|
||||
|
@ -9,9 +7,9 @@ namespace aoc2020
|
|||
/// </summary>
|
||||
public sealed class Day13 : Day
|
||||
{
|
||||
private readonly long[] _buses;
|
||||
private readonly long _earliest;
|
||||
private readonly string[] _fullSchedule;
|
||||
private readonly long[] _buses;
|
||||
|
||||
public Day13() : base(13)
|
||||
{
|
||||
|
@ -22,19 +20,35 @@ namespace aoc2020
|
|||
|
||||
public override string Part1()
|
||||
{
|
||||
for (var i = _earliest; ; i++)
|
||||
{
|
||||
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 "";
|
||||
var i = 0;
|
||||
long result = 1, multiplier = 1;
|
||||
|
||||
foreach (var id in _fullSchedule)
|
||||
{
|
||||
if (id != "x")
|
||||
{
|
||||
var increment = long.Parse(id);
|
||||
while (((result += multiplier) + i) % increment != 0)
|
||||
{
|
||||
}
|
||||
|
||||
multiplier *= increment;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return $"{result}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue