64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using static System.Console;
|
|
|
|
namespace _2018_05
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
int removes = 0;
|
|
string resTab = File.ReadAllText(@"..\..\..\Data\Adventofcode_181205\2018_05_data.txt");
|
|
//string resTab = "dabAcCaCBAcCcaDA";
|
|
|
|
|
|
|
|
int varv = 0;
|
|
|
|
string nextStr = nextLevelStr(resTab,ref removes, ref varv);
|
|
while (removes > 0)
|
|
{
|
|
nextStr= nextLevelStr(nextStr, ref removes, ref varv);
|
|
}
|
|
|
|
WriteLine($"Resulterande sträng : {nextStr} , {nextStr.Length} tkn");
|
|
ReadKey();
|
|
|
|
}
|
|
|
|
private static string nextLevelStr(string resTab,ref int removes, ref int varv)
|
|
{
|
|
string tmp = "";
|
|
removes = 0;
|
|
WriteLine($"inLängd: {resTab.Length}");
|
|
foreach(char tkn in resTab.ToCharArray())
|
|
{
|
|
tmp += tkn;
|
|
if (tmp.Length > 1)
|
|
{
|
|
string v = tmp.Substring(tmp.Length - 2, 1);
|
|
string z = tmp.Substring(tmp.Length - 1, 1);
|
|
|
|
if ((v.ToUpper()== v && z.ToLower() == z || (z.ToUpper() == z && v.ToLower() == v))
|
|
&& (v.ToUpper() == z.ToUpper()))
|
|
{
|
|
if (tmp.Length > 2)
|
|
{
|
|
tmp = tmp.Substring(0, tmp.Length - 2);
|
|
removes++;
|
|
}
|
|
else tmp = "";
|
|
}
|
|
}
|
|
}
|
|
WriteLine($"varv {++varv} ; aktuell längd: {tmp.Length} removes = {removes}");
|
|
return tmp;
|
|
}
|
|
}
|
|
}
|