Merge branch 'master' of R:\AdventOfCode

This commit is contained in:
2018-12-24 01:07:19 +01:00

View File

@ -12,8 +12,8 @@ namespace _2018_08
{
static void Main(string[] args)
{
//string[] resTab = File.ReadAllText(@"..\..\..\Data\Adventofcode_181208\2018_08_data.txt").Split(' ');
string[] resTab = @"2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2".Split(' ');
string[] resTab = File.ReadAllText(@"..\..\..\Data\Adventofcode_181208\2018_08_data.txt").Split(' ');
//string[] resTab = @"2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2".Split(' ');
int[] numbers = new int[resTab.Length];
for (int i = 0; i < resTab.Length; i++)
{
@ -25,13 +25,20 @@ namespace _2018_08
var pgm = new Program();
int x = pgm.CalculateMetaData(numbers);
WriteLine();
WriteLine($"summa = {x}");
ReadKey();
}
private int CalculateMetaData(int[] numbers)
{
int tempSum = 0;
int omgStart = 0;
LinkedList<TreeNode> llT = new LinkedList<TreeNode>();
TreeNode strtNode = new TreeNode(0, numbers);
while (omgStart < numbers.Length)
{
TreeNode strtNode = new TreeNode(omgStart, numbers);
llT.AddLast(strtNode);
int headEnd = 0;
int firstAnt = strtNode.AntChilds;
@ -44,23 +51,37 @@ namespace _2018_08
if (i < firstAnt - 1)
{
nxt = new TreeNode(headEnd, numbers);
llT.AddLast(nxt);
//llT.AddLast(nxt);
}
}
strtNode.PrepMetatab(headEnd - strtNode.NodeEnd + strtNode.AntMetaEntries);
omgStart= strtNode.NodeEnd;
}
WriteLine();
foreach (var ll in llT)
{
Write($"Obj Nr: {ll.ObjNr} ({ll.HeaderStart},{ll.NodeEnd});");
foreach (int x in ll.MetaTab)
{
Write($"{x}, ");
tempSum += x;
}
WriteLine();
}
return tempSum;
}
private int SubProc(TreeNode tn, int[] numbers, LinkedList<TreeNode> ll)
{
ll.AddLast(tn);
int nEnd = 0;
if (tn.AntChilds > 0)
{
var tnx = new TreeNode(tn.HeaderStart + 2, numbers);
ll.AddLast(tnx);
nEnd = SubProc(tnx, numbers, ll);
nEnd = SubProc(tnx, numbers, ll) - tnx.HeaderStart;
}
tn.PrepMetatab(nEnd);
@ -71,6 +92,7 @@ namespace _2018_08
public class TreeNode
{
public int ObjNr { get; set; }
public int HeaderStart { get; set; }
public int AntChilds { get; set; }
public int AntMetaEntries { get; set; }
@ -78,8 +100,11 @@ namespace _2018_08
public int NodeEnd { get; set; }
public int[] NumberTab { get; set; }
static int nr;
public TreeNode(int treeNodeStart, int[] NumTab)
{
TreeNode.nr++;
ObjNr = TreeNode.nr;
NumberTab = NumTab;
HeaderStart = treeNodeStart;
AntChilds = NumberTab[HeaderStart];