Ändringar med ny variant
This commit is contained in:
@ -7,99 +7,183 @@ namespace _2018_08
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
bool own = false;
|
||||
int y = 0;
|
||||
//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 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2".Split(' ');
|
||||
string[] resTab = @"2 3 2 1 2 3 1 1 0 2 1 2 3 0 3 4 5 6 7 8 9 0 4 10 11 12 13 14 2 2 0 3 15 16 17 0 2 18 19 20 21 22 23 24".Split(' ');
|
||||
string[] resTab = @"2 3 2 1 2 3 1 1 0 2 1 2 3 0 3 4 5 6 7 8 9 0 4 10 11 12 13 14 2 2 0 3 15 16 17 0 2 18 19 20 21 22 23 24".Split(' '); own = true;
|
||||
int[] numbers = new int[resTab.Length];
|
||||
for (int i = 0; i < resTab.Length; i++)
|
||||
{
|
||||
numbers[i] = int.Parse(resTab[i]);
|
||||
}
|
||||
int y = 0;
|
||||
for(int z = 1; z < 25; z++)
|
||||
if (own)
|
||||
{
|
||||
for (int z = 1; z < 25; z++)
|
||||
{
|
||||
y += z;
|
||||
}
|
||||
}
|
||||
|
||||
Write($"Antal värden = {resTab.Length}");
|
||||
if (own)
|
||||
{
|
||||
WriteLine($" svar = {y}");
|
||||
}
|
||||
else WriteLine();
|
||||
|
||||
WriteLine($"Antal värden = {resTab.Length} svar = {y}");
|
||||
ReadKey();
|
||||
|
||||
var pgm = new Program();
|
||||
int x = pgm.CalculateMetaData(numbers);
|
||||
//int x = pgm.CalculateMetaData(numbers);
|
||||
int x = pgm.CalcMetaData(numbers);
|
||||
|
||||
WriteLine();
|
||||
WriteLine($"summa = {x}");
|
||||
ReadKey();
|
||||
}
|
||||
|
||||
#region oldCode
|
||||
//private int CalculateMetaData(int[] numbers)
|
||||
//{
|
||||
// int tempSum = 0;
|
||||
// int omgStart = 0;
|
||||
// LinkedList<TreeNode> llT = new LinkedList<TreeNode>();
|
||||
// while (omgStart < numbers.Length)
|
||||
// {
|
||||
// TreeNode strtNode = new TreeNode(omgStart, numbers);
|
||||
// llT.AddLast(strtNode);
|
||||
// int headEnd = 0;
|
||||
// int firstAnt = strtNode.AntChilds;
|
||||
|
||||
private int CalculateMetaData(int[] numbers)
|
||||
{
|
||||
int tempSum = 0;
|
||||
int omgStart = 0;
|
||||
LinkedList<TreeNode> llT = new LinkedList<TreeNode>();
|
||||
while (omgStart < numbers.Length)
|
||||
{
|
||||
TreeNode strtNode = new TreeNode(omgStart, numbers);
|
||||
llT.AddLast(strtNode);
|
||||
int headEnd = 0;
|
||||
int firstAnt = strtNode.AntChilds;
|
||||
// TreeNode nxt = new TreeNode(strtNode.HeaderStart + 2, numbers);
|
||||
|
||||
TreeNode nxt = new TreeNode(strtNode.HeaderStart + 2, numbers);
|
||||
// for (int i = 0; i < firstAnt; i++)
|
||||
// {
|
||||
// headEnd = this.SubProc(nxt, numbers, llT);
|
||||
// if (i < firstAnt - 1)
|
||||
// {
|
||||
// nxt = new TreeNode(headEnd, numbers);
|
||||
// //llT.AddLast(nxt);
|
||||
// }
|
||||
// }
|
||||
// Write($"start: {strtNode.HeaderStart}, init. end: {strtNode.NodeEnd}, ant. Metas: {strtNode.AntMetaEntries}, ");
|
||||
// strtNode.PrepMetatab(headEnd - strtNode.NodeEnd + strtNode.AntMetaEntries);
|
||||
// WriteLine($" fakt. slut {strtNode.NodeEnd}");
|
||||
|
||||
for (int i = 0; i < firstAnt; i++)
|
||||
{
|
||||
headEnd = this.SubProc(nxt, numbers, llT);
|
||||
if (i < firstAnt - 1)
|
||||
{
|
||||
nxt = new TreeNode(headEnd, numbers);
|
||||
//llT.AddLast(nxt);
|
||||
}
|
||||
}
|
||||
Write($"start: {strtNode.HeaderStart}, init. end: {strtNode.NodeEnd}, ant. Metas: {strtNode.AntMetaEntries}, ");
|
||||
strtNode.PrepMetatab(headEnd - strtNode.NodeEnd + strtNode.AntMetaEntries);
|
||||
WriteLine($" fakt. slut {strtNode.NodeEnd}");
|
||||
// omgStart = strtNode.NodeEnd;
|
||||
// if (omgStart < numbers.Length)
|
||||
// {
|
||||
// for (int i = omgStart; i < omgStart + 5; i++)
|
||||
// {
|
||||
// Write($"numbers[{i}]:{numbers[i]}, ");
|
||||
// }
|
||||
// WriteLine();
|
||||
// Write(" ");
|
||||
// }
|
||||
// }
|
||||
|
||||
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();
|
||||
// }
|
||||
|
||||
for (int i = omgStart; i < omgStart + 5; i++)
|
||||
// return tempSum;
|
||||
//}
|
||||
|
||||
//private int SubProc(TreeNode tn, int[] numbers, LinkedList<TreeNode> ll)
|
||||
//{
|
||||
// ll.AddLast(tn);
|
||||
// int nEnd = 0;
|
||||
// int scndAnt = tn.AntChilds;
|
||||
|
||||
// if (scndAnt > 0)
|
||||
// {
|
||||
// var tnx = new TreeNode(tn.HeaderStart + 2, numbers);
|
||||
|
||||
// for (int k = 0; k < scndAnt; k++)
|
||||
// {
|
||||
|
||||
// var xs = SubProc(tnx, numbers, ll);
|
||||
// WriteLine($"-- tillbaka tnx obj: {tnx.ObjNr} nEnd: {nEnd} svnAnt: {scndAnt} tn obj: {tn.ObjNr}");
|
||||
// nEnd = xs - tnx.HeaderStart;
|
||||
// if (k < scndAnt - 1)
|
||||
// {
|
||||
// //tnx = new TreeNode(nEnd, numbers);
|
||||
// tnx = new TreeNode(tnx.NodeEnd, numbers);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (scndAnt > 1) {
|
||||
// nEnd = xs;
|
||||
// }
|
||||
// //else
|
||||
// //{
|
||||
// // nEnd = xs - tn.NodeEnd;
|
||||
// //}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// tn.PrepMetatab(nEnd);
|
||||
// return tn.NodeEnd;
|
||||
//}
|
||||
#endregion
|
||||
|
||||
private int CalcMetaData(int[] nums)
|
||||
{
|
||||
Write($"numbers[{i}]:{numbers[i]}, ");
|
||||
}
|
||||
WriteLine();
|
||||
Write(" ");
|
||||
int metaSum = 0;
|
||||
int last_pos = 0;
|
||||
LinkedList<TreeNode> ll = new LinkedList<TreeNode>();
|
||||
TreeNode tnStart = new TreeNode(0, nums, ll);
|
||||
|
||||
last_pos = diverge(tnStart, ll);
|
||||
|
||||
WriteLine($" last_pos= {last_pos}");
|
||||
ReadKey();
|
||||
|
||||
return metaSum;
|
||||
}
|
||||
|
||||
WriteLine();
|
||||
foreach (var ll in llT)
|
||||
private int diverge(TreeNode tn, LinkedList<TreeNode> lnk)
|
||||
{
|
||||
Write($"Obj Nr: {ll.ObjNr} ({ll.HeaderStart},{ll.NodeEnd});");
|
||||
foreach (int x in ll.MetaTab)
|
||||
int last_pos = 0;
|
||||
int[] workTable = tn.NumberTab;
|
||||
int level_amount = tn.AntChilds;
|
||||
int level_akt_ch = 0;
|
||||
|
||||
if (level_amount > 0)
|
||||
{
|
||||
Write($"{x}, ");
|
||||
tempSum += x;
|
||||
}
|
||||
WriteLine();
|
||||
var tnx = new TreeNode(tn.HeaderStart + 2, workTable, lnk);
|
||||
last_pos = tnx.NodeEnd;
|
||||
last_pos += diverge(tnx, lnk);
|
||||
tnx.PrepMetatab( last_pos);
|
||||
}
|
||||
|
||||
return tempSum;
|
||||
}
|
||||
|
||||
private int SubProc(TreeNode tn, int[] numbers, LinkedList<TreeNode> ll)
|
||||
if (level_akt_ch < level_amount)
|
||||
{
|
||||
ll.AddLast(tn);
|
||||
int nEnd = 0;
|
||||
|
||||
if (tn.AntChilds > 0)
|
||||
{
|
||||
var tnx = new TreeNode(tn.HeaderStart + 2, numbers);
|
||||
nEnd = SubProc(tnx, numbers, ll) - tnx.HeaderStart;
|
||||
level_akt_ch++;
|
||||
var tny = new TreeNode(last_pos, workTable, lnk);
|
||||
last_pos = tny.NodeEnd;
|
||||
last_pos += diverge(tny, lnk);
|
||||
tny.PrepMetatab(tny.NodeEnd + last_pos);
|
||||
}
|
||||
|
||||
tn.PrepMetatab(nEnd);
|
||||
return tn.NodeEnd;
|
||||
tn.PrepMetatab(tn.AntMetaEntries + last_pos);
|
||||
last_pos = tn.NodeEnd;
|
||||
|
||||
return last_pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class TreeNode
|
||||
@ -111,9 +195,8 @@ namespace _2018_08
|
||||
public int[] MetaTab { get; set; }
|
||||
public int NodeEnd { get; set; }
|
||||
public int[] NumberTab { get; set; }
|
||||
|
||||
static int nr;
|
||||
public TreeNode(int treeNodeStart, int[] NumTab)
|
||||
public TreeNode(int treeNodeStart, int[] NumTab, LinkedList<TreeNode> links)
|
||||
{
|
||||
TreeNode.nr++;
|
||||
ObjNr = TreeNode.nr;
|
||||
@ -122,11 +205,13 @@ namespace _2018_08
|
||||
AntChilds = NumberTab[HeaderStart];
|
||||
AntMetaEntries = NumberTab[HeaderStart + 1];
|
||||
NodeEnd = HeaderStart + 2 + AntMetaEntries;
|
||||
links.AddLast(this);
|
||||
WriteLine(this.ToString());
|
||||
}
|
||||
|
||||
public void PrepMetatab(int subLen)
|
||||
{
|
||||
NodeEnd += subLen;
|
||||
NodeEnd = subLen;
|
||||
MetaTab = new int[AntMetaEntries];
|
||||
for (int i = 0, j = NodeEnd - AntMetaEntries; j < NodeEnd; j++, i++)
|
||||
{
|
||||
@ -134,5 +219,10 @@ namespace _2018_08
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string retStr = $"Nr: {ObjNr}, Start: {HeaderStart}, Subobj: {AntChilds}, Metafält: {AntMetaEntries}, Nodend: {NodeEnd}";
|
||||
return retStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Data/AdventOfCode_181208/egetex.xlsx
Normal file
BIN
Data/AdventOfCode_181208/egetex.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user