AdventOfCode2022/Kalender/day10.cs
2022-12-10 17:19:18 +01:00

71 lines
2.0 KiB
C#

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);
static public void part1()
{
Dictionary<int, int> cycles = new Dictionary<int, int>();
int cycle = 1;
int x = 1;
int result = 0;
int endResult = 0;
cycles.Add(cycle, x);
foreach (string line in lines)
{
if (line != "noop")
{
cycle++;
cycles.Add(cycle, 0);
cycle++;
cycles.Add(cycle, int.Parse(line.Substring(4)));
}
else
{
cycle++;
cycles.Add(cycle, 0);
}
}
foreach (var item in cycles)
{
result += item.Value;
switch (item.Key)
{
case 20:
endResult += (item.Key * result);
break;
case 60:
endResult += (item.Key * result);
break;
case 100:
endResult += (item.Key * result);
break;
case 140:
endResult += (item.Key * result);
break;
case 180:
endResult += (item.Key * result);
break;
case 220:
endResult += (item.Key * result);
break;
}
}
Console.WriteLine($"Part 1: {endResult}");
}
}
}