-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day15.cs
68 lines (58 loc) · 1.91 KB
/
Day15.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2016
{
class Day15 : Day
{
public dynamic Input
{
get
{
return
@"Disc #1 has 7 positions; at time=0, it is at position 0.
Disc #2 has 13 positions; at time=0, it is at position 0.
Disc #3 has 3 positions; at time=0, it is at position 2.
Disc #4 has 5 positions; at time=0, it is at position 2.
Disc #5 has 17 positions; at time=0, it is at position 0.
Disc #6 has 19 positions; at time=0, it is at position 7.";
}
}
public string Part1(dynamic input)
{
var positions = new List<int>();
var sizes = new List<int>();
foreach (var line in Utils.splitLines(input))
{
var parts = line.Replace(".", "").Split(' ');
var size = int.Parse(parts[3]);
var position = int.Parse(parts[parts.Length - 1]);
positions.Add((position + positions.Count + 1) % size);
sizes.Add(size);
}
int steps = 0;
while (!positions.All(p => p == 0))
{
for (int i = 0; i < positions.Count; i++)
{
positions[i] = (positions[i] + 1) % sizes[i];
}
steps++;
}
return steps.ToString();
}
public string Part2(dynamic input)
{
return Part1(input + "\nDisc #7 has 11 positions; at time=0, it is at position 0.");
}
public void Test()
{
Utils.Test(Part1,
@"Disc #1 has 5 positions; at time=0, it is at position 4.
Disc #2 has 2 positions; at time=0, it is at position 1.",
"5");
}
}
}