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

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>{7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp1</RootNamespace>
<AssemblyName>ConsoleApp1</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
ConsoleApp1/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>

153
ConsoleApp1/Program.cs Normal file
View File

@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static System.Console;
namespace _2018_04
{
class Program
{
static void Main(string[] args)
{
string[] splitter = new string[] { "[", "]" };
string[] resTab = File.ReadAllLines(@"D:\AdventOfCode\data\2018_04_data.txt");
Array.Sort(resTab);
Dictionary<int, GardDay> gdList = new Dictionary<int, GardDay>();
GardDay gd = null;
//[1518-11-01 00:00] Guard #10 begins shift
//[1518-11-01 00:05] falls asleep
//[1518-11-01 00:25] wakes up
//[1518-11-01 00:30] falls asleep
//[1518-11-01 00:55] wakes up
foreach (var str in resTab)
{
if (str.Contains("#"))
{
if (gd != null)
{
WriteLine(gd.ToString());
if (gdList.ContainsKey(gd.GardNr))
{
for (int vekt = 0; vekt < gdList[gd.GardNr].MinTabell.Length; vekt++)
{
gdList[gd.GardNr].MinTabell[vekt] += gd.MinTabell[vekt];
}
gdList[gd.GardNr].SleepMinutes += gd.SleepMinutes;
}
else
{
gd.fillMinTable();
gdList.Add(gd.GardNr, gd);
}
}
gd = new GardDay(str);
// WriteLine($"Gard day = {gd.ToString()}");
}
else
{
gd.fillNext(str);
}
}
foreach( int key in gdList.Keys)
{
}
//gdList.Add(gd.GardNr, gd);
}
}
public class GardDay
{
string[] splitter = new string[] { "[", "]" };
public int GardNr { get; set; }
public Dictionary<DateTime, string> TimeStamp { get; set; }
public int[] MinTabell { get; set; }
public int SleepMinutes { get; set; }
public void fillMinTable()
{
int saveMin = -1;
foreach (KeyValuePair<DateTime, string> pair in TimeStamp)
{
if (pair.Value == "sleep")
{
saveMin = pair.Key.Minute;
}
else
{
if (saveMin > -1)
{
for (int i = saveMin; i < pair.Key.Minute; i++)
{
MinTabell[i]++;
SleepMinutes++;
}
}
}
}
}
public GardDay(string inRow)
{
MinTabell = new int[60];
SleepMinutes = 0;
string outStr = "";
fillNext(inRow, out outStr);
var xwords = outStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var ystr in xwords)
{
if (ystr.Contains("#"))
{
GardNr = int.Parse(ystr.Substring(ystr.IndexOf("#") + 1));
}
}
}
public void fillNext(string inRow)
{
string tmpOut = null;
fillNext(inRow, out tmpOut);
}
public void fillNext(string inRow, out string outStr)
{
string[] xrow = inRow.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
outStr = xrow[1];
DateTime ts = DateTime.Parse(xrow[0]);
if (TimeStamp == null)
{
TimeStamp = new Dictionary<DateTime, string>();
}
string tmpStep = "sleep";
if (outStr.Contains("Guard") || outStr.Contains("wakes"))
{
tmpStep = "awake";
}
TimeStamp.Add(ts, tmpStep);
}
public override string ToString()
{
StringBuilder outTxt = new StringBuilder();
outTxt.Append($"gardnr {GardNr}");
foreach (var key in TimeStamp.Keys)
{
outTxt.Append($" Time : {key}, {TimeStamp[key]}");
}
return outTxt.ToString();
}
}
}

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("ConsoleApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp1")]
[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("7e85b89b-15d2-4248-ae0d-dd96c84a2e5a")]
// 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")]