day 9 part 1
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Ben Harris 2020-12-09 00:41:09 -05:00
parent eb58c1b72e
commit 3c0cc14d45
Signed by: ben
GPG Key ID: 4E0AF802FFF7960C
3 changed files with 1023 additions and 2 deletions

View File

@ -1,17 +1,28 @@
using System.Collections.Generic;
using System.Linq;
namespace aoc2020
{
/// <summary>
/// Day 9: <see href="https://adventofcode.com/2020/day/9"></see>
/// Day 9: <see href="https://adventofcode.com/2020/day/9">Encoding Error</see>
/// </summary>
public sealed class Day09 : Day
{
private readonly long[] _list;
public Day09() : base(9)
{
_list = Input.Select(long.Parse).ToArray();
}
public override string Part1()
{
return "";
var i = 25;
while (_list.Skip(i - 25).Take(25).DifferentCombinations(2).Select(c => c.Sum()).Contains(_list[i]))
{
i++;
}
return $"{_list[i]}";
}
public override string Part2()

View File

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace aoc2020
{
@ -12,6 +14,14 @@ namespace aoc2020
: source.Remove(source.LastIndexOf(value, StringComparison.Ordinal));
}
public static IEnumerable<IEnumerable<T>> DifferentCombinations<T>(this IEnumerable<T> elements, int k)
{
var enumerable = elements as T[] ?? elements.ToArray();
return k == 0 ? new[] { Array.Empty<T>() } :
enumerable.SelectMany((e, i) =>
enumerable.Skip(i + 1).DifferentCombinations(k - 1).Select(c => (new[] {e}).Concat(c)));
}
/// <summary>
/// increased accuracy for stopwatch based on frequency.
/// <see

1000
aoc2020/input/day9.in Normal file

File diff suppressed because it is too large Load Diff