Part 1 181206 working
This commit is contained in:
@ -14,47 +14,141 @@ namespace _2018_06
|
||||
{
|
||||
string[] resTab = File.ReadAllLines(@"..\..\..\Data\Adventofcode_181206\2018_06_data.txt");
|
||||
List<Tuple<string, int, int>> koords = new List<Tuple<string, int, int>>();
|
||||
Tuple<int, int> tuple = null;
|
||||
Tuple<string, int, int> tuple = null;
|
||||
int antal = 0;
|
||||
foreach (string v in resTab)
|
||||
{
|
||||
string[] nums = v.Split(new char[] { ',' });
|
||||
tuple = Tuple.Create(int.Parse(nums[0]), int.Parse(nums[1]));
|
||||
tuple = Tuple.Create(ChNumber(antal), int.Parse(nums[0]), int.Parse(nums[1]));
|
||||
koords.Add(tuple);
|
||||
antal++;
|
||||
}
|
||||
|
||||
int points = 0;
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
|
||||
foreach (Tuple<int,int> tp in koords)
|
||||
foreach (Tuple<string, int, int> tp in koords)
|
||||
{
|
||||
points++;
|
||||
WriteLine($"point {points}, X: {tp.Item1} Y: {tp.Item2}");
|
||||
if (tp.Item1 > a)
|
||||
WriteLine($"point {points}, id: {tp.Item1}, X: {tp.Item2} Y: {tp.Item3}");
|
||||
if (tp.Item2 > a)
|
||||
{
|
||||
a = tp.Item1;
|
||||
a = tp.Item2;
|
||||
}
|
||||
|
||||
if (tp.Item2 > b)
|
||||
if (tp.Item3 > b)
|
||||
{
|
||||
b = tp.Item2;
|
||||
b = tp.Item3;
|
||||
}
|
||||
}
|
||||
WriteLine($"max value: {a},{b}");
|
||||
ReadKey();
|
||||
|
||||
string[,] area = new string[360, 360];
|
||||
|
||||
for (int i = 0; i < 360; i++)
|
||||
{
|
||||
for (int j = 0; j < 360; j++)
|
||||
{
|
||||
int dist = 10000;
|
||||
foreach (Tuple<string, int, int> tp1 in koords)
|
||||
{
|
||||
int part1 = tp1.Item2 - i;
|
||||
int part2 = tp1.Item3 - j;
|
||||
int ldist = Math.Abs(part1) + Math.Abs(part2);
|
||||
if (ldist < dist)
|
||||
{
|
||||
dist = ldist;
|
||||
area[i, j] = tp1.Item1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ldist == dist)
|
||||
{
|
||||
area[i, j] = ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
//Write($" {area[i, j]}");
|
||||
}
|
||||
//WriteLine();
|
||||
}
|
||||
|
||||
WriteLine("Skapat avståndsmap");
|
||||
|
||||
ReadKey();
|
||||
|
||||
SortedSet<string> infinites = new SortedSet<string>();
|
||||
|
||||
for (int i = 0; i < 360; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
infinites.Add(area[0, i]);
|
||||
infinites.Add(area[359, i]);
|
||||
infinites.Add(area[i, 0]);
|
||||
infinites.Add(area[i, 359]);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
|
||||
foreach (var item in infinites)
|
||||
{
|
||||
Write($" {item}");
|
||||
|
||||
}
|
||||
|
||||
public string ChNumber(int i)
|
||||
WriteLine();
|
||||
WriteLine("Kontrollerat ytterkanter");
|
||||
|
||||
ReadKey();
|
||||
|
||||
Dictionary<string, int> areas = new Dictionary<string, int>();
|
||||
foreach (var item in area)
|
||||
{
|
||||
if (infinites.Contains(item))
|
||||
{ }
|
||||
else
|
||||
{
|
||||
if (areas.Keys.Contains(item))
|
||||
{
|
||||
areas[item]++;
|
||||
}
|
||||
else areas.Add(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int maxUnits = 0;
|
||||
string maxArea = "";
|
||||
|
||||
foreach(var item in areas.Keys)
|
||||
{
|
||||
WriteLine($"{item}= {areas[item]}");
|
||||
if (areas[item] > maxUnits)
|
||||
{
|
||||
maxUnits = areas[item];
|
||||
maxArea = item;
|
||||
}
|
||||
}
|
||||
|
||||
WriteLine($"Vinnare {maxArea}= {areas[maxArea]}");
|
||||
|
||||
ReadKey();
|
||||
|
||||
}
|
||||
|
||||
public static string ChNumber(int i)
|
||||
{
|
||||
const string nbr = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
|
||||
var cnbr = nbr.ToCharArray();
|
||||
string tmpSvar = "";
|
||||
|
||||
int a = i / 24;
|
||||
int b = i - a * 24;
|
||||
|
||||
tmpSvar = cnbr[a].ToString() + cnbr[b].ToString();
|
||||
|
||||
return tmpSvar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user