initial add to repository
This commit is contained in:
60
2018_01/Program.cs
Normal file
60
2018_01/Program.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using static System.Console;
|
||||
|
||||
namespace _2018_01
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
long longVar = 0;
|
||||
int varv = 0;
|
||||
bool stopped = false;
|
||||
Dictionary<string, int> resCheck = new Dictionary<string, int>();
|
||||
string indata = File.ReadAllText(@"I:\Adventofcode_181201\data181201.txt");
|
||||
//string indata = "+1\r\n-2\r\n+3\r\n+1\r\n+1\r\n-2\r\n";
|
||||
string[] resTab = indata.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
while (!stopped)
|
||||
{
|
||||
varv++;
|
||||
foreach (var str in resTab)
|
||||
{
|
||||
longVar += long.Parse(str);
|
||||
WriteLine($"freq: {longVar} nr :{str.ToString()}");
|
||||
if (checkAdd(resCheck, longVar) > 1)
|
||||
{
|
||||
stopped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
WriteLine($"The answer is {longVar} at varv {varv}");
|
||||
//foreach (var keyStr in resCheck.Keys)
|
||||
//{
|
||||
// WriteLine($"freq: {keyStr} nr :{resCheck[keyStr].ToString()}");
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
private static int checkAdd(Dictionary<string, int> work, long newVal)
|
||||
{
|
||||
int times = 0;
|
||||
int res;
|
||||
if (work.TryGetValue(newVal.ToString(), out res))
|
||||
{
|
||||
work[newVal.ToString()] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
work.Add(newVal.ToString(), 1);
|
||||
}
|
||||
|
||||
times = work[newVal.ToString()];
|
||||
|
||||
return times;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user