-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day02.cs
57 lines (49 loc) · 1.56 KB
/
Day02.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
using AdventOfCode.CSharp.Common;
using System;
using System.Collections.Generic;
namespace AdventOfCode.CSharp.Y2017.Solvers;
public class Day02 : ISolver
{
public static void Solve(ReadOnlySpan<byte> input, Solution solution)
{
int part1 = 0;
int part2 = 0;
var nums = new List<int>();
foreach (Range rowRange in input.SplitLines())
{
ReadOnlySpan<byte> row = input[rowRange];
int minValue = int.MaxValue;
int maxValue = int.MinValue;
int quotient = 0;
nums.Clear();
var rowReader = new SpanReader(row);
while (!rowReader.Done)
{
int cell = rowReader.ReadPosIntUntil('\t');
minValue = Math.Min(minValue, cell);
maxValue = Math.Max(maxValue, cell);
if (quotient == 0)
{
foreach (int num in nums)
{
if (cell % num == 0)
{
quotient = cell / num;
break;
}
else if (num % cell == 0)
{
quotient = num / cell;
break;
}
}
nums.Add(cell);
}
}
part1 += maxValue - minValue;
part2 += quotient;
}
solution.SubmitPart1(part1);
solution.SubmitPart2(part2);
}
}