day 9 part 1
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
eb58c1b72e
commit
3c0cc14d45
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue