d17p2
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1938202174
commit
8459671c89
|
@ -37,7 +37,7 @@ public class DayTests
|
||||||
[DataRow(typeof(Day14), "5656", "12271437788530")]
|
[DataRow(typeof(Day14), "5656", "12271437788530")]
|
||||||
[DataRow(typeof(Day15), "702", "2955")]
|
[DataRow(typeof(Day15), "702", "2955")]
|
||||||
[DataRow(typeof(Day16), "852", "19348959966392")]
|
[DataRow(typeof(Day16), "852", "19348959966392")]
|
||||||
[DataRow(typeof(Day17), "12090", "")]
|
[DataRow(typeof(Day17), "12090", "5059")]
|
||||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
var s = Stopwatch.StartNew();
|
var s = Stopwatch.StartNew();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
public sealed class Day17 : Day
|
public sealed class Day17 : Day
|
||||||
{
|
{
|
||||||
private readonly List<int> _target;
|
private readonly List<int> _target;
|
||||||
|
|
||||||
public Day17() : base(17, "Trick Shot")
|
public Day17() : base(17, "Trick Shot")
|
||||||
{
|
{
|
||||||
_target = Input.First()
|
_target = Input.First()
|
||||||
|
@ -24,5 +24,30 @@ public sealed class Day17 : Day
|
||||||
return (initialYVelocity + 1) * initialYVelocity / 2;
|
return (initialYVelocity + 1) * initialYVelocity / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object Part2() => "";
|
public override object Part2()
|
||||||
}
|
{
|
||||||
|
var successfulVelocities = new HashSet<(int x, int y)>();
|
||||||
|
var xMin = 1;
|
||||||
|
while (xMin * (xMin + 1) / 2 < _target[0]) xMin++;
|
||||||
|
|
||||||
|
for (var x = xMin; x <= _target[1]; x++)
|
||||||
|
for (var y = _target[2]; y < Math.Abs(_target[2]); y++)
|
||||||
|
{
|
||||||
|
int xVelocity = x, yVelocity = y, xPos = 0, yPos = 0;
|
||||||
|
|
||||||
|
while (xPos <= _target[1] && yPos >= _target[2])
|
||||||
|
{
|
||||||
|
xPos += xVelocity;
|
||||||
|
yPos += yVelocity;
|
||||||
|
|
||||||
|
if (xPos >= _target[0] && xPos <= _target[1] && yPos >= _target[2] && yPos <= _target[3])
|
||||||
|
successfulVelocities.Add((x, y));
|
||||||
|
|
||||||
|
xVelocity = xVelocity == 0 ? 0 : xVelocity - 1;
|
||||||
|
yVelocity--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return successfulVelocities.Count;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue