about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-12-17 16:46:29 -0500
committerBen Harris <ben@tilde.team>2021-12-17 16:46:29 -0500
commit1938202174413562858506316bb9444c81a73852 (patch)
tree3f2b7abeb840fd7be0fe91e3621c3366477efec7
parentbf8e77441bb6ae200a29b32a04d8607a41c03e93 (diff)
d17p1
-rw-r--r--aoc2021.test/DayTests.cs2
-rw-r--r--aoc2021/Day17.cs28
-rw-r--r--aoc2021/input/day17.in1
-rw-r--r--aoc2021/input/test17.in1
4 files changed, 32 insertions, 0 deletions
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;
+
+/// <summary>
+/// Day 17: <see href="https://adventofcode.com/2021/day/17"/>
+/// </summary>
+public sealed class Day17 : Day
+{
+    private readonly List<int> _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