-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay4.cs
44 lines (43 loc) · 1.27 KB
/
Day4.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
using System;
using System.Collections;
using System.Linq;
using Godot;
public partial class DayUI
{
IEnumerator Day4(string inputfile)
{
// var lines = ReadLinesSkipEmpty("test.txt");
var lines = ReadLinesSkipEmpty(inputfile);
int displayEvery = lines.Length / 100;
int r1 = 0;
int r2 = 0;
int[] multiplier = new int[lines.Length];
foreach (var (l, lineIndex) in lines.Select((l, i) => (l, i)))
{
var g = l.Split(new char[] { ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool[] cards = new bool[100];
int i = 2;
for (; i < g.Length && g[i] != "|"; ++i)
{
cards[g[i].ToInt()] = true;
}
int v = 0;
for (i++; i < g.Length; ++i)
{
if (cards[g[i].ToInt()]) v++;
}
r1 += (1 << v) / 2;
for (int j = 0; j < v; j++)
{
multiplier[lineIndex + j + 1] += multiplier[lineIndex] + 1;
}
r2 += multiplier[lineIndex] + 1;
if (lineIndex % displayEvery == 0)
{
Result(r1, r2);
yield return null;
}
}
Result(r1, r2);
}
}