Skip to content

Commit 44b3e8f

Browse files
authored
Merge pull request #15 from deckelmouck/solving2023
Solving2023
2 parents 25931e3 + ac74d13 commit 44b3e8f

File tree

16 files changed

+3654
-83
lines changed

16 files changed

+3654
-83
lines changed

2023/Day05/solution.cs

Lines changed: 45 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,107 +12,71 @@ public void SolvePart1()
1212
Console.WriteLine("part 1");
1313

1414
solutionBase sb = new();
15-
var input = sb.getInputLines(@"2023/Day05/testone").ToArray();
16-
//var input = sb.getInputLines(@"2023/Day05/input").ToArray();
15+
//var input = sb.getInputLines(@"2023/Day05/test").ToArray();
16+
var input = sb.getInputLines(@"2023/Day05/input").ToArray();
1717

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

2020
var seeds = firstLine.Where(seed => seed.Any(char.IsDigit));
21+
Dictionary<long,long> seedlist = new();
22+
2123
foreach(var seed in seeds)
2224
{
23-
Console.WriteLine(seed);
24-
}
25+
Console.WriteLine($"seed: {seed} will be calculated");
26+
var s = Convert.ToInt64(seed);
27+
var mapped = false;
2528

26-
//input.Remove(input[0]);
29+
for (int i = 2; i < input.Length; i++)
30+
{
31+
if(input[i] == "") mapped = false;
2732

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

30-
// foreach (var line in input)
31-
// {
32-
// if(line.Length > 0 && !line.Contains(':'))
33-
// {
34-
// maps.Add(line);
35-
// }
36-
// }
37-
38-
//inital map
39-
int[] test = new int[100];
40-
for (int i = 0; i < test.Length; i++)
41-
{
42-
test[i] = i;
43-
}
37+
var destination = Convert.ToInt64(inputLine[0]);
38+
var source = Convert.ToInt64(inputLine[1]);
39+
var range = Convert.ToInt64(inputLine[2]);
4440

45-
int[] testmap = new int[100];
41+
if(SeedInRange(s, source, range))
42+
{
43+
s = destination + (s - source);
44+
mapped = true;
45+
}
4646

47-
for (int a = 2; a < input.Length; a++)
48-
{
49-
//Console.WriteLine(input[a].Length);
50-
if(input[a].Contains(':'))
51-
{
52-
Console.WriteLine(input[a]);
53-
Array.Copy(test, testmap, test.Length);
54-
}
55-
else if (input[a].Length == 0)
56-
{
57-
Console.WriteLine(input[a]);
58-
//Array.Copy(testmap, test, test.Length);
59-
60-
for (int i = 0; i < 100; i++)
61-
{
62-
//Console.WriteLine($"{i}: test {test[i]} - testmap {testmap[i]}");
63-
test[i] = testmap[i];
64-
testmap[i] = 1;
65-
//Console.WriteLine($"{i}: test {test[i]} - testmap {testmap[i]}");
66-
//Console.WriteLine($"------------------");
67-
}
68-
}
69-
else
70-
{
71-
Console.WriteLine(input[a]);
72-
73-
var item = input[a];
74-
var destinationRangeStart = Convert.ToInt64(item.Split(' ')[0]);
75-
var sourceRange = Convert.ToInt64(item.Split(' ')[1]);
76-
var rangeLength = Convert.ToInt64(item.Split(' ')[2]);
77-
78-
for (int i = 0; i < rangeLength; i++)
79-
{
80-
testmap[sourceRange + i] = test[destinationRangeStart + i];
47+
Console.WriteLine($"destination: {destination} source: {source} range: {range}");
8148
}
49+
Console.WriteLine($"seed: {seed} - {s}");
8250
}
51+
52+
seedlist.Add(Convert.ToInt64(seed), s);
53+
54+
}
55+
56+
foreach (var seed in seedlist)
57+
{
58+
Console.WriteLine($"seed: {seed.Key} - {seed.Value}");
8359
}
84-
85-
//foreach (var item in maps)
86-
// for(int m = 0; m < maps.Count; m++)
87-
// {
88-
// var item = maps[m];
89-
// var destinationRangeStart = Convert.ToInt64(item.Split(' ')[0]);
90-
// var sourceRange = Convert.ToInt64(item.Split(' ')[1]);
91-
// var rangeLength = Convert.ToInt64(item.Split(' ')[2]);
92-
93-
// for (int i = 0; i < rangeLength; i++)
94-
// {
95-
// testmap[sourceRange + i] = test[destinationRangeStart + i];
96-
// }
97-
// }
98-
99-
//Console.WriteLine(seeds);
100-
// for (int i = 0; i < 100; i++)
101-
// {
102-
// Console.WriteLine($"test{i}: {testmap[i]}");
103-
// }
104-
Console.WriteLine($"testmap");
105-
Console.WriteLine($"79: {testmap[79]}");
106-
Console.WriteLine($"14: {testmap[14]}");
107-
Console.WriteLine($"55: {testmap[55]}");
108-
Console.WriteLine($"13: {testmap[13]}");
10960

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

111-
Console.WriteLine($"still not the right result");
63+
Console.WriteLine($"this should be right: 910845529");
11264
}
11365

11466
public void SolvePart2()
11567
{
11668
Console.WriteLine("under developement");
11769
}
70+
71+
public bool SeedInRange(Int64 seed, Int64 source, Int64 range)
72+
{
73+
if(seed >= source && seed < (source + range))
74+
{
75+
return true;
76+
}
77+
else
78+
{
79+
return false;
80+
}
81+
}
11882
}

2023/Day05/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ temperature-to-humidity map:
3030

3131
humidity-to-location map:
3232
60 56 37
33-
56 93 4
33+
56 93 4

0 commit comments

Comments
 (0)