-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_1.cs
More file actions
61 lines (46 loc) · 1.58 KB
/
Copy pathProgram_1.cs
File metadata and controls
61 lines (46 loc) · 1.58 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
58
59
60
61
using System;
using System.IO;
using System.Linq;
namespace Day_16
{
internal class Program
{
private static byte[] _cache;
private static sbyte[] _basePattern = new sbyte[] { 0, 1, 0, -1 };
private static void Round(ref byte[] input, int from = 0)
{
for (int i = from; i < input.Length; i++)
{
long sum = 0;
for (int k = i; k < input.Length; k++)
{
var factor = _basePattern[((k + 1) / (i + 1)) % _basePattern.Length];
sum += input[k] * factor;
}
_cache[i] = (byte)(Math.Abs(sum) % 10);
}
var tmp = input;
input = _cache;
_cache = tmp;
}
private static void Main(string[] args)
{
var input = File.ReadAllText("input3").Select(x => (byte)(x - '0')).ToArray();
int repeats = 1;
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)));
offset = 0;
_cache = new byte[adjustedArray.Length];
for (int i = 0; i < 100; i++)
{
// Console.WriteLine($"Round {i}");
Round(ref adjustedArray, offset);
}
Console.WriteLine(string.Join("", adjustedArray.Skip(offset).Take(8)));
}
}
}