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

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,6 +11,76 @@ namespace _2017_01
{
static void Main(string[] args)
{
var Indata = File.ReadAllText(@"I:\Adventofcode_171201\data171201.txt");
//var Indata = "1212";
MethodOne(Indata);
MethodTwo(Indata);
}
private static void MethodOne(string Indata)
{
int value = 0;
char lastFig = ' ';
char firstFig = ' ';
foreach (var figure in Indata.ToCharArray())
{
if (lastFig == ' ')
{
firstFig = figure;
}
if (figure == lastFig)
{
value += int.Parse(figure.ToString());
}
lastFig = figure;
}
if (firstFig == lastFig)
{
value += int.Parse(lastFig.ToString());
}
System.Console.WriteLine("--Method 1--");
System.Console.WriteLine($"---{value}---");
System.Console.WriteLine("----------------");
}
private static void MethodTwo(string Indata)
{
int value = 0;
// char lastFig = ' ';
// char firstFig = ' ';
int locPos = 0;
char[] characters = Indata.ToCharArray();
foreach (var figure in characters)
{
if (figure == jmfChar(characters,locPos))
{
value += int.Parse(figure.ToString());
}
locPos++;
}
System.Console.WriteLine("--Method 2--");
System.Console.WriteLine($"---{value}---");
System.Console.WriteLine("----------------");
}
private static char jmfChar(char[] ind, int pos)
{
char returnChr = ' ';
int chars = ind.Length / 2;
if (pos + chars > ind.Length - 1)
{
returnChr = ind[pos + chars - ind.Length];
}
else returnChr = ind[pos + chars ];
return returnChr;
}
}
}