-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (43 loc) · 1.36 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (43 loc) · 1.36 KB
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 System;
using System.IO;
using System.Linq;
namespace Day_16
{
internal class Program
{
private static byte[] _cache;
private static void Round(ref byte[] input, int from = 0)
{
var longsum = 0;
for (int k = from; k < input.Length; k++)
{
longsum += input[k];
}
for (int i = from; i < input.Length; i++)
{
_cache[i] = (byte)(longsum % 10);
longsum -= input[i];
}
var tmp = input;
input = _cache;
_cache = tmp;
}
private static void Main(string[] args)
{
var input = File.ReadAllText("input").Select(x => (byte)(x - '0')).ToArray();
int repeats = 10_000;
var adjustedArray = new byte[input.Length * repeats];
for (int i = 0; i < repeats; i++)
{
Buffer.BlockCopy(input, 0, adjustedArray, input.Length * i, input.Length);
}
var offset = int.Parse(string.Join("", input.Take(7)));
_cache = new byte[adjustedArray.Length];
for (int i = 0; i < 100; i++)
{
Round(ref adjustedArray, offset);
}
Console.WriteLine(string.Join("", adjustedArray.Skip(offset).Take(8)));
}
}
}