initial add to repository

This commit is contained in:
2018-12-15 09:44:55 +01:00
parent f85ebf48d1
commit d8ea4079ec
30 changed files with 1435 additions and 25 deletions

53
2018_02/2018_02.csproj Normal file
View 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>{03B8F28E-27B5-44BC-8051-58E2CB771E6B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>_2018_02</RootNamespace>
<AssemblyName>2018_02</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_02/App.config Normal file
View 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>

136
2018_02/Program.cs Normal file
View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace _2018_02
{
class Program
{
static void Main(string[] args)
{
int twos = 0, threes = 0;
Dictionary<string, int> resCheck = new Dictionary<string, int>();
string indata = File.ReadAllText(@"I:\Adventofcode_181201\data181202.txt");
//string indata = "abcdef\r\nbababc\r\nabbcde\r\nabcccd\r\naabcdd\r\nabcdee\r\nababab\r\n";
string[] resTab = indata.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var boxId in resTab)
{
char[] characters = boxId.ToArray();
Array.Sort(characters);
analyseString(characters, ref twos, ref threes);
}
System.Console.WriteLine($"twos: {twos} threes: {threes} checksum: {twos * threes} ");
SecondAnalyse(resTab);
}
private static void analyseString(char[] characters, ref int twos, ref int threes)
{
int locTwos = 0, locthrees = 0;
char lastChar = ' ';
byte cnt = 0;
foreach (var tkn in characters)
{
if (tkn == lastChar)
{
cnt++;
}
else
{
if (cnt == 2)
{
if (locTwos == 0)
locTwos++;
}
if (cnt == 3)
{
if (locthrees == 0)
{
locthrees++;
}
}
lastChar = tkn;
cnt = 1;
}
}
if (cnt == 2)
{
if (locTwos == 0)
locTwos++;
}
if (cnt == 3)
{
if (locthrees == 0)
{
locthrees++;
}
}
twos += locTwos;
threes += locthrees;
}
private static void SecondAnalyse(string[] restab)
{
bool ready = false;
var xlen = restab[0].Length;
foreach (var str in restab)
{
for (int i = 0; i < xlen; i++)
{
foreach (var str2 in restab)
{
if (str2 == str) { }
else
{
string stx = "", sty = "";
var st0 = stringUtanPos(str, i, out stx);
var st1 = stringUtanPos(str2, i, out sty);
if (st0 == st1)
{
System.Console.WriteLine($"box 1: {str},\r\nbox 2: {str2} diff chars {stx} , {sty}\r\n{st0}\r\n{st1}");
ready = true;
break;
}
}
if (ready) break;
}
if (ready) break;
}
if (ready) break;
}
}
private static string stringUtanPos(string str, int i, out string stx)
{
string tmp = str;
stx = str.Substring(i, 1);
if (i > 0)
{
tmp = str.Substring(0, i) + str.Substring(i + 1);
}
else
{
tmp = str.Substring(i+1);
}
return tmp;
}
}
}

View 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_02")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("2018_02")]
[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("03b8f28e-27b5-44bc-8051-58e2cb771e6b")]
// 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")]