Solved Part 1 of day05

This commit is contained in:
Nikurasu 2023-04-11 10:51:19 +02:00
parent 425b9e6eb3
commit 626e0b6502
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
// See https://aka.ms/new-console-template for more information
using System;
using System.Text.RegularExpressions;
namespace day05
{
@ -40,9 +40,39 @@ namespace day05
}
}
}
Console.WriteLine(lines[instructionsStartLine]);
Instruction test = new Instruction(12, 2, 3);
for(int i = 0; i < stacks.Length; i++)
{
stacks[i].Reverse();
}
List<Instruction> instrucList = new List<Instruction>();
for (int i = instructionsStartLine; i < lines.Length; i++)
{
List<int> nums = new List<int>();
foreach(string word in lines[i].Split(" "))
{
if (Regex.IsMatch(word, "^[\\d+$]"))
{
nums.Add(int.Parse(word));
}
}
if(nums.Count > 0)
{
instrucList.Add(new Instruction(nums[0], nums[1], nums[2]));
}
}
foreach(Instruction instruc in instrucList)
{
for (int i = 0; i < instruc.Ammont; i++)
{
stacks[instruc.Destination - 1].Add(stacks[instruc.Source - 1].Last());
stacks[instruc.Source - 1].RemoveAt(stacks[instruc.Source - 1].Count - 1);
}
}
// Print Results
foreach(List<char> stack in stacks)
{
Console.Write(stack[stack.Count - 1] + "\t");
}
}
}