Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving2023 #15

Merged
merged 16 commits into from
Dec 9, 2023
126 changes: 45 additions & 81 deletions 2023/Day05/solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,71 @@ public void SolvePart1()
Console.WriteLine("part 1");

solutionBase sb = new();
var input = sb.getInputLines(@"2023/Day05/testone").ToArray();
//var input = sb.getInputLines(@"2023/Day05/input").ToArray();
//var input = sb.getInputLines(@"2023/Day05/test").ToArray();
var input = sb.getInputLines(@"2023/Day05/input").ToArray();

var firstLine = input[0].Split(' ', StringSplitOptions.RemoveEmptyEntries);

var seeds = firstLine.Where(seed => seed.Any(char.IsDigit));
Dictionary<long,long> seedlist = new();

foreach(var seed in seeds)
{
Console.WriteLine(seed);
}
Console.WriteLine($"seed: {seed} will be calculated");
var s = Convert.ToInt64(seed);
var mapped = false;

//input.Remove(input[0]);
for (int i = 2; i < input.Length; i++)
{
if(input[i] == "") mapped = false;

// List<string> maps = new();
if(!input[i].Contains(':') && input[i] != "" && !mapped)
{
var inputLine = input[i].Split(' ', StringSplitOptions.RemoveEmptyEntries);

// foreach (var line in input)
// {
// if(line.Length > 0 && !line.Contains(':'))
// {
// maps.Add(line);
// }
// }

//inital map
int[] test = new int[100];
for (int i = 0; i < test.Length; i++)
{
test[i] = i;
}
var destination = Convert.ToInt64(inputLine[0]);
var source = Convert.ToInt64(inputLine[1]);
var range = Convert.ToInt64(inputLine[2]);

int[] testmap = new int[100];
if(SeedInRange(s, source, range))
{
s = destination + (s - source);
mapped = true;
}

for (int a = 2; a < input.Length; a++)
{
//Console.WriteLine(input[a].Length);
if(input[a].Contains(':'))
{
Console.WriteLine(input[a]);
Array.Copy(test, testmap, test.Length);
}
else if (input[a].Length == 0)
{
Console.WriteLine(input[a]);
//Array.Copy(testmap, test, test.Length);

for (int i = 0; i < 100; i++)
{
//Console.WriteLine($"{i}: test {test[i]} - testmap {testmap[i]}");
test[i] = testmap[i];
testmap[i] = 1;
//Console.WriteLine($"{i}: test {test[i]} - testmap {testmap[i]}");
//Console.WriteLine($"------------------");
}
}
else
{
Console.WriteLine(input[a]);

var item = input[a];
var destinationRangeStart = Convert.ToInt64(item.Split(' ')[0]);
var sourceRange = Convert.ToInt64(item.Split(' ')[1]);
var rangeLength = Convert.ToInt64(item.Split(' ')[2]);

for (int i = 0; i < rangeLength; i++)
{
testmap[sourceRange + i] = test[destinationRangeStart + i];
Console.WriteLine($"destination: {destination} source: {source} range: {range}");
}
Console.WriteLine($"seed: {seed} - {s}");
}

seedlist.Add(Convert.ToInt64(seed), s);

}

foreach (var seed in seedlist)
{
Console.WriteLine($"seed: {seed.Key} - {seed.Value}");
}

//foreach (var item in maps)
// for(int m = 0; m < maps.Count; m++)
// {
// var item = maps[m];
// var destinationRangeStart = Convert.ToInt64(item.Split(' ')[0]);
// var sourceRange = Convert.ToInt64(item.Split(' ')[1]);
// var rangeLength = Convert.ToInt64(item.Split(' ')[2]);

// for (int i = 0; i < rangeLength; i++)
// {
// testmap[sourceRange + i] = test[destinationRangeStart + i];
// }
// }

//Console.WriteLine(seeds);
// for (int i = 0; i < 100; i++)
// {
// Console.WriteLine($"test{i}: {testmap[i]}");
// }
Console.WriteLine($"testmap");
Console.WriteLine($"79: {testmap[79]}");
Console.WriteLine($"14: {testmap[14]}");
Console.WriteLine($"55: {testmap[55]}");
Console.WriteLine($"13: {testmap[13]}");

Console.WriteLine($"min is: {seedlist.Min(s => s.Value)}");

Console.WriteLine($"still not the right result");
Console.WriteLine($"this should be right: 910845529");
}

public void SolvePart2()
{
Console.WriteLine("under developement");
}

public bool SeedInRange(Int64 seed, Int64 source, Int64 range)
{
if(seed >= source && seed < (source + range))
{
return true;
}
else
{
return false;
}
}
}
2 changes: 1 addition & 1 deletion 2023/Day05/test
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ temperature-to-humidity map:

humidity-to-location map:
60 56 37
56 93 4
56 93 4
Loading