Nära lösning dag 8
This commit is contained in:
53
2018_08/2018_08.csproj
Normal file
53
2018_08/2018_08.csproj
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{832314D4-E3BC-4745-A90D-B6F373FAFF7A}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>_2018_08</RootNamespace>
|
||||
<AssemblyName>2018_08</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
6
2018_08/App.config
Normal file
6
2018_08/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
101
2018_08/Program.cs
Normal file
101
2018_08/Program.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Console;
|
||||
|
||||
namespace _2018_08
|
||||
{
|
||||
class Program
|
||||
{
|
||||
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(' ');
|
||||
int[] numbers = new int[resTab.Length];
|
||||
for (int i = 0; i < resTab.Length; i++)
|
||||
{
|
||||
numbers[i] = int.Parse(resTab[i]);
|
||||
}
|
||||
WriteLine($"Antal värden = {resTab.Length}");
|
||||
ReadKey();
|
||||
|
||||
var pgm = new Program();
|
||||
int x = pgm.CalculateMetaData(numbers);
|
||||
|
||||
}
|
||||
|
||||
private int CalculateMetaData(int[] numbers)
|
||||
{
|
||||
int tempSum = 0;
|
||||
LinkedList<TreeNode> llT = new LinkedList<TreeNode>();
|
||||
TreeNode strtNode = new TreeNode(0, numbers);
|
||||
llT.AddLast(strtNode);
|
||||
int headEnd = 0;
|
||||
int firstAnt = strtNode.AntChilds;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return tempSum;
|
||||
}
|
||||
|
||||
private int SubProc(TreeNode tn, int[] numbers, LinkedList<TreeNode> ll)
|
||||
{
|
||||
int nEnd = 0;
|
||||
|
||||
if (tn.AntChilds > 0)
|
||||
{
|
||||
var tnx = new TreeNode(tn.HeaderStart + 2, numbers);
|
||||
ll.AddLast(tnx);
|
||||
nEnd = SubProc(tnx, numbers, ll);
|
||||
|
||||
}
|
||||
|
||||
tn.PrepMetatab(nEnd);
|
||||
return tn.NodeEnd;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TreeNode
|
||||
{
|
||||
public int HeaderStart { get; set; }
|
||||
public int AntChilds { get; set; }
|
||||
public int AntMetaEntries { get; set; }
|
||||
public int[] MetaTab { get; set; }
|
||||
public int NodeEnd { get; set; }
|
||||
public int[] NumberTab { get; set; }
|
||||
|
||||
public TreeNode(int treeNodeStart, int[] NumTab)
|
||||
{
|
||||
NumberTab = NumTab;
|
||||
HeaderStart = treeNodeStart;
|
||||
AntChilds = NumberTab[HeaderStart];
|
||||
AntMetaEntries = NumberTab[HeaderStart + 1];
|
||||
NodeEnd = HeaderStart + 2 + AntMetaEntries;
|
||||
}
|
||||
|
||||
public void PrepMetatab(int subLen)
|
||||
{
|
||||
NodeEnd += subLen;
|
||||
MetaTab = new int[AntMetaEntries];
|
||||
for (int i = 0, j = NodeEnd - AntMetaEntries; j < NodeEnd; j++, i++)
|
||||
{
|
||||
MetaTab[i] = NumberTab[j];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
2018_08/Properties/AssemblyInfo.cs
Normal file
36
2018_08/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("2018_08")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("2018_08")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("832314d4-e3bc-4745-a90d-b6f373faff7a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user