AdventOfCode2022/Kalender/day10.cs

71 lines
2.0 KiB
C#
Raw Normal View History

2022-12-10 08:36:39 +01:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kalender
{
internal class day10
{
static string file = "../../../Kalender/files/day10.txt";
static string[] lines = File.ReadAllLines(file);
2022-12-10 17:19:18 +01:00
2022-12-10 08:36:39 +01:00
static public void part1()
{
2022-12-10 17:19:18 +01:00
Dictionary<int, int> cycles = new Dictionary<int, int>();
int cycle = 1;
2022-12-10 08:36:39 +01:00
int x = 1;
int result = 0;
2022-12-10 17:19:18 +01:00
int endResult = 0;
cycles.Add(cycle, x);
2022-12-10 08:36:39 +01:00
foreach (string line in lines)
{
2022-12-10 17:19:18 +01:00
if (line != "noop")
{
cycle++;
cycles.Add(cycle, 0);
cycle++;
cycles.Add(cycle, int.Parse(line.Substring(4)));
}
else
2022-12-10 08:36:39 +01:00
{
2022-12-10 17:19:18 +01:00
cycle++;
cycles.Add(cycle, 0);
2022-12-10 08:36:39 +01:00
}
2022-12-10 17:19:18 +01:00
}
2022-12-10 08:36:39 +01:00
2022-12-10 17:19:18 +01:00
foreach (var item in cycles)
{
result += item.Value;
2022-12-10 08:36:39 +01:00
2022-12-10 17:19:18 +01:00
switch (item.Key)
2022-12-10 08:36:39 +01:00
{
case 20:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
case 60:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
case 100:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
case 140:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
case 180:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
case 220:
2022-12-10 17:19:18 +01:00
endResult += (item.Key * result);
2022-12-10 08:36:39 +01:00
break;
}
}
2022-12-10 17:19:18 +01:00
Console.WriteLine($"Part 1: {endResult}");
2022-12-10 08:36:39 +01:00
}
}
}