From 1938202174413562858506316bb9444c81a73852 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 17 Dec 2021 16:46:29 -0500 Subject: [PATCH] d17p1 --- aoc2021.test/DayTests.cs | 2 ++ aoc2021/Day17.cs | 28 ++++++++++++++++++++++++++++ aoc2021/input/day17.in | 1 + aoc2021/input/test17.in | 1 + 4 files changed, 32 insertions(+) create mode 100644 aoc2021/Day17.cs create mode 100644 aoc2021/input/day17.in create mode 100644 aoc2021/input/test17.in diff --git a/aoc2021.test/DayTests.cs b/aoc2021.test/DayTests.cs index 09d2e89..46c0c98 100644 --- a/aoc2021.test/DayTests.cs +++ b/aoc2021.test/DayTests.cs @@ -37,6 +37,7 @@ public class DayTests [DataRow(typeof(Day14), "5656", "12271437788530")] [DataRow(typeof(Day15), "702", "2955")] [DataRow(typeof(Day16), "852", "19348959966392")] + [DataRow(typeof(Day17), "12090", "")] public void CheckAllDays(Type dayType, string part1, string part2) { var s = Stopwatch.StartNew(); @@ -83,6 +84,7 @@ public class DayTests [DataRow(typeof(Day14), "1588", "2188189693529")] [DataRow(typeof(Day15), "40", "315")] [DataRow(typeof(Day16), "16", "15")] + [DataRow(typeof(Day17), "45", "112")] public void CheckTestInputs(Type dayType, string part1, string part2) { Day.UseTestInput = true; diff --git a/aoc2021/Day17.cs b/aoc2021/Day17.cs new file mode 100644 index 0000000..a8256a9 --- /dev/null +++ b/aoc2021/Day17.cs @@ -0,0 +1,28 @@ +namespace aoc2021; + +/// +/// Day 17: +/// +public sealed class Day17 : Day +{ + private readonly List _target; + + public Day17() : base(17, "Trick Shot") + { + _target = Input.First() + .Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) + .Skip(2) + .SelectMany(i => i.Split('=')[1].Split("..")) + .Select(i => i.TrimEnd(',')) + .Select(int.Parse) + .ToList(); + } + + public override object Part1() + { + var initialYVelocity = Math.Abs(_target[2]) - 1; + return (initialYVelocity + 1) * initialYVelocity / 2; + } + + public override object Part2() => ""; +} diff --git a/aoc2021/input/day17.in b/aoc2021/input/day17.in new file mode 100644 index 0000000..28408a5 --- /dev/null +++ b/aoc2021/input/day17.in @@ -0,0 +1 @@ +target area: x=94..151, y=-156..-103 diff --git a/aoc2021/input/test17.in b/aoc2021/input/test17.in new file mode 100644 index 0000000..a07e02d --- /dev/null +++ b/aoc2021/input/test17.in @@ -0,0 +1 @@ +target area: x=20..30, y=-10..-5