update to .net 6
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
- global usings - file-scope namespaces - update drone image tag
This commit is contained in:
parent
f1c329ddaa
commit
811c0f5d74
|
@ -4,7 +4,7 @@ name: run
|
|||
|
||||
steps:
|
||||
- name: run
|
||||
image: mcr.microsoft.com/dotnet/sdk:latest
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
commands:
|
||||
- dotnet test
|
||||
- dotnet run --project aoc2020/aoc2020.csproj
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
MIT License Copyright (c) <year> <copyright holders>
|
||||
MIT License Copyright (c) 2020 Ben Harris
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace aoc2020.test
|
||||
namespace aoc2020.test;
|
||||
|
||||
[TestClass]
|
||||
public class DayTests
|
||||
{
|
||||
[TestClass]
|
||||
public class DayTests
|
||||
{
|
||||
[DataTestMethod]
|
||||
[DataRow(typeof(Day01), "751776", "42275090")]
|
||||
[DataRow(typeof(Day02), "556", "605")]
|
||||
|
@ -37,7 +36,7 @@ namespace aoc2020.test
|
|||
{
|
||||
// create day instance
|
||||
var s = Stopwatch.StartNew();
|
||||
var day = (Day) Activator.CreateInstance(dayType);
|
||||
var day = Activator.CreateInstance(dayType) as Day;
|
||||
s.Stop();
|
||||
Assert.IsNotNull(day, "failed to create day object");
|
||||
Console.WriteLine($"{s.ScaleMilliseconds()}ms elapsed in constructor");
|
||||
|
@ -58,5 +57,4 @@ namespace aoc2020.test
|
|||
Console.WriteLine($"{s.ScaleMilliseconds()}ms elapsed in part2");
|
||||
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
public abstract class Day
|
||||
{
|
||||
public abstract class Day
|
||||
{
|
||||
protected Day(int dayNumber, string puzzleName)
|
||||
{
|
||||
DayNumber = dayNumber;
|
||||
|
@ -44,5 +41,4 @@ namespace aoc2020
|
|||
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 1: <see href="https://adventofcode.com/2020/day/1" />
|
||||
/// </summary>
|
||||
public sealed class Day01 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 1: <see href="https://adventofcode.com/2020/day/1" />
|
||||
/// </summary>
|
||||
public sealed class Day01 : Day
|
||||
{
|
||||
private readonly ImmutableHashSet<int> _entries;
|
||||
|
||||
public Day01() : base(1, "Report Repair")
|
||||
|
@ -31,5 +28,4 @@ namespace aoc2020
|
|||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 2: <see href="https://adventofcode.com/2020/day/1" />
|
||||
/// </summary>
|
||||
public sealed class Day02 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 2: <see href="https://adventofcode.com/2020/day/1" />
|
||||
/// </summary>
|
||||
public sealed class Day02 : Day
|
||||
{
|
||||
private readonly ImmutableList<Password> _passwords;
|
||||
|
||||
public Day02() : base(2, "Password Philosophy")
|
||||
|
@ -52,5 +49,4 @@ namespace aoc2020
|
|||
private char C { get; }
|
||||
private string Value { get; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 3: <see href="https://adventofcode.com/2020/day/3" />
|
||||
/// </summary>
|
||||
public sealed class Day03 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 3: <see href="https://adventofcode.com/2020/day/3" />
|
||||
/// </summary>
|
||||
public sealed class Day03 : Day
|
||||
{
|
||||
private readonly string[] _grid;
|
||||
private readonly int _width;
|
||||
|
||||
|
@ -33,13 +31,12 @@ namespace aoc2020
|
|||
|
||||
public override string Part2()
|
||||
{
|
||||
var xSlopes = new[] {1, 3, 5, 7, 1};
|
||||
var ySlopes = new[] {1, 1, 1, 1, 2};
|
||||
var xSlopes = new[] { 1, 3, 5, 7, 1 };
|
||||
var ySlopes = new[] { 1, 1, 1, 1, 2 };
|
||||
|
||||
return xSlopes.Zip(ySlopes)
|
||||
.Select(s => CountSlope(s.Item1, s.Item2))
|
||||
.Select(s => CountSlope(s.First, s.Second))
|
||||
.Aggregate((acc, i) => acc * i)
|
||||
.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 4: <see href="https://adventofcode.com/2020/day/4" />
|
||||
/// </summary>
|
||||
public sealed class Day04 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 4: <see href="https://adventofcode.com/2020/day/4" />
|
||||
/// </summary>
|
||||
public sealed class Day04 : Day
|
||||
{
|
||||
private readonly List<Passport> _passports;
|
||||
|
||||
public Day04() : base(4, "Passport Processing")
|
||||
|
@ -102,7 +97,7 @@ namespace aoc2020
|
|||
// height
|
||||
if (_hgt.EndsWith("cm"))
|
||||
{
|
||||
var h = _hgt.Substring(0, 3);
|
||||
var h = _hgt[..3];
|
||||
if (int.TryParse(h, out var hgt))
|
||||
{
|
||||
if (hgt < 150 || hgt > 193)
|
||||
|
@ -136,7 +131,7 @@ namespace aoc2020
|
|||
return false;
|
||||
|
||||
// eye color
|
||||
if (!new[] {"amb", "blu", "brn", "gry", "grn", "hzl", "oth"}.Contains(_ecl))
|
||||
if (!new[] { "amb", "blu", "brn", "gry", "grn", "hzl", "oth" }.Contains(_ecl))
|
||||
return false;
|
||||
|
||||
// passport id
|
||||
|
@ -184,5 +179,4 @@ namespace aoc2020
|
|||
return passport;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 5: <see href="https://adventofcode.com/2020/day/5" />
|
||||
/// </summary>
|
||||
public sealed class Day05 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 5: <see href="https://adventofcode.com/2020/day/5" />
|
||||
/// </summary>
|
||||
public sealed class Day05 : Day
|
||||
{
|
||||
private readonly ImmutableHashSet<int> _ids;
|
||||
|
||||
public Day05() : base(5, "Binary Boarding")
|
||||
|
@ -30,5 +26,4 @@ namespace aoc2020
|
|||
// arithmetic sum of full series
|
||||
return $"{(_ids.Count + 1) * (_ids.First() + _ids.Last()) / 2 - _ids.Sum()}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 6: <see href="https://adventofcode.com/2020/day/6" />
|
||||
/// </summary>
|
||||
public sealed class Day06 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 6: <see href="https://adventofcode.com/2020/day/6" />
|
||||
/// </summary>
|
||||
public sealed class Day06 : Day
|
||||
{
|
||||
private readonly int _countPart1;
|
||||
private readonly int _countPart2;
|
||||
|
||||
|
@ -50,5 +47,4 @@ namespace aoc2020
|
|||
{
|
||||
return $"{_countPart2}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 7: <see href="https://adventofcode.com/2020/day/7" />
|
||||
/// </summary>
|
||||
public sealed class Day07 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 7: <see href="https://adventofcode.com/2020/day/7" />
|
||||
/// </summary>
|
||||
public sealed class Day07 : Day
|
||||
{
|
||||
private readonly Dictionary<string, IEnumerable<(int, string)?>> _rules;
|
||||
|
||||
public Day07() : base(7, "Handy Haversacks")
|
||||
|
@ -37,7 +34,7 @@ namespace aoc2020
|
|||
public override string Part1()
|
||||
{
|
||||
// breadth-first search with Queue
|
||||
var start = new Queue<string>(new[] {"shiny gold"});
|
||||
var start = new Queue<string>(new[] { "shiny gold" });
|
||||
var p = new HashSet<string>();
|
||||
string node;
|
||||
while (true)
|
||||
|
@ -57,5 +54,4 @@ namespace aoc2020
|
|||
{
|
||||
return $"{Weight("shiny gold") - 1}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 8: <see href="https://adventofcode.com/2020/day/8" />
|
||||
/// </summary>
|
||||
public sealed class Day08 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 8: <see href="https://adventofcode.com/2020/day/8" />
|
||||
/// </summary>
|
||||
public sealed class Day08 : Day
|
||||
{
|
||||
private readonly (string instruction, int value)[] _instructions;
|
||||
private int _accumulator;
|
||||
private int _currentInstruction;
|
||||
|
@ -73,5 +71,4 @@ namespace aoc2020
|
|||
|
||||
return $"{_accumulator}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 9: <see href="https://adventofcode.com/2020/day/9" />
|
||||
/// </summary>
|
||||
public sealed class Day09 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 9: <see href="https://adventofcode.com/2020/day/9" />
|
||||
/// </summary>
|
||||
public sealed class Day09 : Day
|
||||
{
|
||||
private readonly long[] _list;
|
||||
private long _part1;
|
||||
|
||||
|
@ -48,5 +46,4 @@ namespace aoc2020
|
|||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 10: <see href="https://adventofcode.com/2020/day/10" />
|
||||
/// </summary>
|
||||
public sealed class Day10 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 10: <see href="https://adventofcode.com/2020/day/10" />
|
||||
/// </summary>
|
||||
public sealed class Day10 : Day
|
||||
{
|
||||
private readonly int[] _adapters;
|
||||
private readonly long[] _memo;
|
||||
|
||||
|
@ -15,7 +12,7 @@ namespace aoc2020
|
|||
{
|
||||
var parsed = Input.Select(int.Parse).ToArray();
|
||||
// add socket and device to the list
|
||||
_adapters = parsed.Concat(new[] {0, parsed.Max() + 3}).OrderBy(i => i).ToArray();
|
||||
_adapters = parsed.Concat(new[] { 0, parsed.Max() + 3 }).OrderBy(i => i).ToArray();
|
||||
_memo = new long[_adapters.Length];
|
||||
}
|
||||
|
||||
|
@ -55,5 +52,4 @@ namespace aoc2020
|
|||
{
|
||||
return $"{Connections(0)}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 11: <see href="https://adventofcode.com/2020/day/11" />
|
||||
/// </summary>
|
||||
public sealed class Day11 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 11: <see href="https://adventofcode.com/2020/day/11" />
|
||||
/// </summary>
|
||||
public sealed class Day11 : Day
|
||||
{
|
||||
public Day11() : base(11, "Seating System")
|
||||
{
|
||||
}
|
||||
|
@ -84,7 +80,7 @@ namespace aoc2020
|
|||
|
||||
public LifeGame StepPart1()
|
||||
{
|
||||
var next = new LifeGame {_h = _h, _w = _w, Grid = Grid.Select(s => s.ToArray()).ToArray()};
|
||||
var next = new LifeGame { _h = _h, _w = _w, Grid = Grid.Select(s => s.ToArray()).ToArray() };
|
||||
for (var y = 0; y < _h; y++)
|
||||
for (var x = 0; x < _w; x++)
|
||||
next.Grid[y][x] = Grid[y][x] switch
|
||||
|
@ -115,7 +111,7 @@ namespace aoc2020
|
|||
|
||||
public LifeGame StepPart2()
|
||||
{
|
||||
var next = new LifeGame {_h = _h, _w = _w, Grid = Grid.Select(s => s.ToArray()).ToArray()};
|
||||
var next = new LifeGame { _h = _h, _w = _w, Grid = Grid.Select(s => s.ToArray()).ToArray() };
|
||||
for (var y = 0; y < _h; y++)
|
||||
for (var x = 0; x < _w; x++)
|
||||
next.Grid[y][x] = Grid[y][x] switch
|
||||
|
@ -153,5 +149,4 @@ namespace aoc2020
|
|||
return '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,17 @@
|
|||
using System;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 12: <see href="https://adventofcode.com/2020/day/12" />
|
||||
/// </summary>
|
||||
public sealed class Day12 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 12: <see href="https://adventofcode.com/2020/day/12" />
|
||||
/// </summary>
|
||||
public sealed class Day12 : Day
|
||||
{
|
||||
public Day12() : base(12, "Rain Risk")
|
||||
{
|
||||
}
|
||||
|
||||
private static void Swap(ref int x, ref int y)
|
||||
{
|
||||
var tmp = x;
|
||||
x = y;
|
||||
y = tmp;
|
||||
(y, x) = (x, y);
|
||||
}
|
||||
|
||||
private (int x, int y, int sx, int sy) ProcessInstructions()
|
||||
|
@ -90,5 +86,4 @@ namespace aoc2020
|
|||
var (_, _, sx, sy) = ProcessInstructions();
|
||||
return $"{Math.Abs(sx) + Math.Abs(sy)}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 13: <see href="https://adventofcode.com/2020/day/13" />
|
||||
/// </summary>
|
||||
public sealed class Day13 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 13: <see href="https://adventofcode.com/2020/day/13" />
|
||||
/// </summary>
|
||||
public sealed class Day13 : Day
|
||||
{
|
||||
private readonly long[] _buses;
|
||||
private readonly long _earliest;
|
||||
private readonly string[] _fullSchedule;
|
||||
|
@ -20,7 +18,7 @@ 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);
|
||||
|
@ -50,5 +48,4 @@ namespace aoc2020
|
|||
|
||||
return $"{result}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 14: <see href="https://adventofcode.com/2020/day/14" />
|
||||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 14: <see href="https://adventofcode.com/2020/day/14" />
|
||||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
public Day14() : base(14, "Docking Data")
|
||||
{
|
||||
}
|
||||
|
@ -36,7 +32,7 @@ namespace aoc2020
|
|||
}
|
||||
else
|
||||
{
|
||||
var spl = line.Split(new[] {'[', ']', '='},
|
||||
var spl = line.Split(new[] { '[', ']', '=' },
|
||||
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Skip(1)
|
||||
.Select(ulong.Parse)
|
||||
|
@ -64,7 +60,7 @@ namespace aoc2020
|
|||
else
|
||||
{
|
||||
var value = ulong.Parse(spl[2]);
|
||||
var addr = ulong.Parse(spl[0].Split(new[] {'[', ']'},
|
||||
var addr = ulong.Parse(spl[0].Split(new[] { '[', ']' },
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)[1]);
|
||||
|
||||
var floats = new List<int>();
|
||||
|
@ -81,7 +77,7 @@ namespace aoc2020
|
|||
|
||||
if (floats.Any())
|
||||
{
|
||||
var combos = new List<ulong> {addr};
|
||||
var combos = new List<ulong> { addr };
|
||||
|
||||
foreach (var i in floats)
|
||||
{
|
||||
|
@ -107,5 +103,4 @@ namespace aoc2020
|
|||
|
||||
return $"{memory.Aggregate<KeyValuePair<ulong, ulong>, ulong>(0, (current, w) => current + w.Value)}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 15: <see href="https://adventofcode.com/2020/day/15" />
|
||||
/// </summary>
|
||||
public sealed class Day15 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 15: <see href="https://adventofcode.com/2020/day/15" />
|
||||
/// </summary>
|
||||
public sealed class Day15 : Day
|
||||
{
|
||||
private readonly int[] _turns;
|
||||
private int _current;
|
||||
private int _i;
|
||||
|
@ -44,5 +42,4 @@ namespace aoc2020
|
|||
|
||||
return $"{_current}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 16: <see href="https://adventofcode.com/2020/day/16" />
|
||||
/// </summary>
|
||||
public sealed class Day16 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 16: <see href="https://adventofcode.com/2020/day/16" />
|
||||
/// </summary>
|
||||
public sealed class Day16 : Day
|
||||
{
|
||||
private readonly Dictionary<string, List<Range>> _rules;
|
||||
private readonly List<List<int>> _tickets;
|
||||
|
||||
public Day16() : base(16, "Ticket Translation")
|
||||
{
|
||||
_tickets = new List<List<int>>();
|
||||
_rules = new Dictionary<string, List<Range>>();
|
||||
_tickets = new();
|
||||
_rules = new();
|
||||
|
||||
foreach (var line in Input)
|
||||
{
|
||||
|
@ -56,10 +52,10 @@ namespace aoc2020
|
|||
.SelectMany(r => r)
|
||||
.Any(r => r.Contains(t))))
|
||||
// group by index
|
||||
.SelectMany(inner => inner.Select((item, index) => new {item, index}))
|
||||
.SelectMany(inner => inner.Select((item, index) => new { item, index }))
|
||||
.GroupBy(i => i.index, i => i.item)
|
||||
.Select(g => g.ToList())
|
||||
.Select((val, i) => new {Value = val, Index = i})
|
||||
.Select((val, i) => new { Value = val, Index = i })
|
||||
.ToList();
|
||||
|
||||
var matchedRules = _rules
|
||||
|
@ -87,5 +83,4 @@ namespace aoc2020
|
|||
return
|
||||
$"{departureFields.Aggregate(1L, (l, match) => l * _tickets.First()[match.Index])}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 17: <see href="https://adventofcode.com/2020/day/17" />
|
||||
/// </summary>
|
||||
public sealed class Day17 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 17: <see href="https://adventofcode.com/2020/day/17" />
|
||||
/// </summary>
|
||||
public sealed class Day17 : Day
|
||||
{
|
||||
private readonly Dictionary<(int x, int y, int z), char> _plane;
|
||||
private readonly Dictionary<(int x, int y, int z, int w), char> _plane4;
|
||||
|
||||
|
@ -42,9 +39,9 @@ namespace aoc2020
|
|||
{
|
||||
var neighbors = 0;
|
||||
|
||||
foreach (var i in new[] {-1, 0, 1})
|
||||
foreach (var j in new[] {-1, 0, 1})
|
||||
foreach (var k in new[] {-1, 0, 1})
|
||||
foreach (var i in new[] { -1, 0, 1 })
|
||||
foreach (var j in new[] { -1, 0, 1 })
|
||||
foreach (var k in new[] { -1, 0, 1 })
|
||||
{
|
||||
if (i == 0 && j == 0 && k == 0) continue;
|
||||
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31)] == '#') neighbors++;
|
||||
|
@ -77,10 +74,10 @@ namespace aoc2020
|
|||
{
|
||||
var neighbors = 0;
|
||||
|
||||
foreach (var i in new[] {-1, 0, 1})
|
||||
foreach (var j in new[] {-1, 0, 1})
|
||||
foreach (var k in new[] {-1, 0, 1})
|
||||
foreach (var l in new[] {-1, 0, 1})
|
||||
foreach (var i in new[] { -1, 0, 1 })
|
||||
foreach (var j in new[] { -1, 0, 1 })
|
||||
foreach (var k in new[] { -1, 0, 1 })
|
||||
foreach (var l in new[] { -1, 0, 1 })
|
||||
{
|
||||
if (i == 0 && j == 0 && k == 0 && l == 0) continue;
|
||||
if (plane[((x + i) & 31, (y + j) & 31, (z + k) & 31, (w + l) & 31)] == '#') neighbors++;
|
||||
|
@ -126,5 +123,4 @@ namespace aoc2020
|
|||
|
||||
return $"{plane.Values.Count(v => v == '#')}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 18: <see href="https://adventofcode.com/2020/day/18" />
|
||||
/// </summary>
|
||||
public sealed class Day18 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 18: <see href="https://adventofcode.com/2020/day/18" />
|
||||
/// </summary>
|
||||
public sealed class Day18 : Day
|
||||
{
|
||||
private readonly List<string> _expressions;
|
||||
|
||||
public Day18() : base(18, "Operation Order")
|
||||
|
@ -54,7 +49,7 @@ namespace aoc2020
|
|||
foreach (var c in postfixNotation.ToString())
|
||||
if (char.IsDigit(c))
|
||||
{
|
||||
expressionStack.Push((long) char.GetNumericValue(c));
|
||||
expressionStack.Push((long)char.GetNumericValue(c));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -75,7 +70,6 @@ namespace aoc2020
|
|||
|
||||
public override string Part2()
|
||||
{
|
||||
return $"{_expressions.Sum(expr => Calculate(expr, c => c switch {'+' => 2, '*' => 1, _ => 0}))}";
|
||||
}
|
||||
return $"{_expressions.Sum(expr => Calculate(expr, c => c switch { '+' => 2, '*' => 1, _ => 0 }))}";
|
||||
}
|
||||
}
|
|
@ -1,15 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 19: <see href="https://adventofcode.com/2020/day/19" />
|
||||
/// </summary>
|
||||
public sealed class Day19 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 19: <see href="https://adventofcode.com/2020/day/19" />
|
||||
/// </summary>
|
||||
public sealed class Day19 : Day
|
||||
{
|
||||
private readonly string[] _messages;
|
||||
private readonly Dictionary<string, string[][]> _rules;
|
||||
private readonly Stack<string> _stack;
|
||||
|
@ -48,10 +43,9 @@ namespace aoc2020
|
|||
public override string Part2()
|
||||
{
|
||||
// fix rules 8 and 11
|
||||
_rules["8"] = new[] {new[] {"42"}, new[] {"42", "8"}};
|
||||
_rules["11"] = new[] {new[] {"42", "31"}, new[] {"42", "11", "31"}};
|
||||
_rules["8"] = new[] { new[] { "42" }, new[] { "42", "8" } };
|
||||
_rules["11"] = new[] { new[] { "42", "31" }, new[] { "42", "11", "31" } };
|
||||
var exp = new Regex($"^{MakeRegexExpression("0")}$");
|
||||
return $"{_messages.Count(m => exp.IsMatch(m))}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace aoc2020;
|
||||
|
||||
namespace aoc2020
|
||||
/// <summary>
|
||||
/// Day 20: <see href="https://adventofcode.com/2020/day/20" />
|
||||
/// </summary>
|
||||
public sealed class Day20 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 20: <see href="https://adventofcode.com/2020/day/20" />
|
||||
/// </summary>
|
||||
public sealed class Day20 : Day
|
||||
{
|
||||
private readonly List<Tile> _allPermutations;
|
||||
private readonly List<Tile> _topLefts;
|
||||
|
||||
|
@ -179,5 +175,4 @@ namespace aoc2020
|
|||
return $"Tile {TileId}:\n{string.Join("\n", Pixels.Select(p => new string(p)))}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day 21: <see href="https://adventofcode.com/2020/day/21" />
|
||||
/// </summary>
|
||||
public sealed class Day21 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 21: <see href="https://adventofcode.com/2020/day/21" />
|
||||
/// </summary>
|
||||
public sealed class Day21 : Day
|
||||
{
|
||||
public Day21() : base(21, "Allergen Assessment")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day 22: <see href="https://adventofcode.com/2020/day/22" />
|
||||
/// </summary>
|
||||
public sealed class Day22 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 22: <see href="https://adventofcode.com/2020/day/22" />
|
||||
/// </summary>
|
||||
public sealed class Day22 : Day
|
||||
{
|
||||
public Day22() : base(22, "Crab Combat")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day 23: <see href="https://adventofcode.com/2020/day/23" />
|
||||
/// </summary>
|
||||
public sealed class Day23 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 23: <see href="https://adventofcode.com/2020/day/23" />
|
||||
/// </summary>
|
||||
public sealed class Day23 : Day
|
||||
{
|
||||
public Day23() : base(23, "Crab Cups")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day 24: <see href="https://adventofcode.com/2020/day/24" />
|
||||
/// </summary>
|
||||
public sealed class Day24 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 24: <see href="https://adventofcode.com/2020/day/24" />
|
||||
/// </summary>
|
||||
public sealed class Day24 : Day
|
||||
{
|
||||
public Day24() : base(24, "Lobby Layout")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day 25: <see href="https://adventofcode.com/2020/day/25" />
|
||||
/// </summary>
|
||||
public sealed class Day25 : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day 25: <see href="https://adventofcode.com/2020/day/25" />
|
||||
/// </summary>
|
||||
public sealed class Day25 : Day
|
||||
{
|
||||
public Day25() : base(25, "Combo Breaker")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
/// <summary>
|
||||
/// Day X: <see href="https://adventofcode.com/2020/day/X" />
|
||||
/// </summary>
|
||||
public sealed class DayX : Day
|
||||
{
|
||||
/// <summary>
|
||||
/// Day X: <see href="https://adventofcode.com/2020/day/X" />
|
||||
/// </summary>
|
||||
public sealed class DayX : Day
|
||||
{
|
||||
public DayX() : base(X, "")
|
||||
{
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ namespace aoc2020
|
|||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// increased accuracy for stopwatch based on frequency.
|
||||
/// <see
|
||||
|
@ -17,12 +16,11 @@ namespace aoc2020
|
|||
/// <returns></returns>
|
||||
public static double ScaleMilliseconds(this Stopwatch stopwatch)
|
||||
{
|
||||
return 1_000 * stopwatch.ElapsedTicks / (double) Stopwatch.Frequency;
|
||||
return 1_000 * stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
|
||||
}
|
||||
|
||||
public static bool Contains(this Range range, int i)
|
||||
{
|
||||
return i >= range.Start.Value && i <= range.End.Value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,19 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
|
||||
namespace aoc2020
|
||||
namespace aoc2020;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.BaseType == typeof(Day))
|
||||
.Select(t => (Day) Activator.CreateInstance(t))
|
||||
.OrderBy(d => d.DayNumber);
|
||||
.Select(t => Activator.CreateInstance(t) as Day)
|
||||
.OrderBy(d => d?.DayNumber);
|
||||
|
||||
if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
|
||||
{
|
||||
var day = days.FirstOrDefault(d => d.DayNumber == dayNum);
|
||||
var day = days.FirstOrDefault(d => d?.DayNumber == dayNum);
|
||||
if (day != null)
|
||||
day.AllParts();
|
||||
else
|
||||
|
@ -23,8 +21,7 @@ namespace aoc2020
|
|||
}
|
||||
else
|
||||
{
|
||||
foreach (var d in days) d.AllParts();
|
||||
}
|
||||
foreach (var d in days) d?.AllParts();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -11,4 +13,11 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Collections.Generic"/>
|
||||
<Using Include="System.Collections.Immutable"/>
|
||||
<Using Include="System.Text"/>
|
||||
<Using Include="System.Text.RegularExpressions"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Reference in New Issue