Day 6
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
<None Remove="Problems\AOC2022\Day4\test.txt" />
|
<None Remove="Problems\AOC2022\Day4\test.txt" />
|
||||||
<None Remove="Problems\AOC2022\Day5\input.txt" />
|
<None Remove="Problems\AOC2022\Day5\input.txt" />
|
||||||
<None Remove="Problems\AOC2022\Day5\test.txt" />
|
<None Remove="Problems\AOC2022\Day5\test.txt" />
|
||||||
|
<None Remove="Problems\AOC2022\Day6\input.txt" />
|
||||||
|
<None Remove="Problems\AOC2022\Day6\test.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ internal partial class SupplyStacks : Problem
|
|||||||
{
|
{
|
||||||
private List<char>[] _stacksPart1 = Array.Empty<List<char>>();
|
private List<char>[] _stacksPart1 = Array.Empty<List<char>>();
|
||||||
private List<char>[] _stacksPart2 = Array.Empty<List<char>>();
|
private List<char>[] _stacksPart2 = Array.Empty<List<char>>();
|
||||||
private TextParser<(int, int, int)> _moveParser = from move in Character.Letter.Or(Character.WhiteSpace).Many()
|
private readonly TextParser<(int, int, int)> _moveParser = from move in Character.Letter.Or(Character.WhiteSpace).Many()
|
||||||
from stack in Character.Digit.Many()
|
from stack in Character.Digit.Many()
|
||||||
from frm in Character.Letter.Or(Character.WhiteSpace).Many()
|
from frm in Character.Letter.Or(Character.WhiteSpace).Many()
|
||||||
from source in Character.Digit.Many()
|
from source in Character.Digit.Many()
|
||||||
@@ -32,7 +32,7 @@ internal partial class SupplyStacks : Problem
|
|||||||
Part1 = new string(_stacksPart1.Select(b => b.Last()).ToArray());
|
Part1 = new string(_stacksPart1.Select(b => b.Last()).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PerformBasicMove(List<char>[] data, (int stack, int from, int to) move)
|
private static void PerformBasicMove(List<char>[] data, (int stack, int from, int to) move)
|
||||||
{
|
{
|
||||||
var from = data[move.from-1];
|
var from = data[move.from-1];
|
||||||
var to = data[move.to-1];
|
var to = data[move.to-1];
|
||||||
@@ -44,7 +44,7 @@ internal partial class SupplyStacks : Problem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PerformMove(List<char>[] data, (int stack, int from, int to) move)
|
private static void PerformMove(List<char>[] data, (int stack, int from, int to) move)
|
||||||
{
|
{
|
||||||
var from = data[move.from - 1];
|
var from = data[move.from - 1];
|
||||||
var to = data[move.to - 1];
|
var to = data[move.to - 1];
|
||||||
@@ -105,7 +105,7 @@ internal partial class SupplyStacks : Problem
|
|||||||
return _moveParser.Parse(line);
|
return _moveParser.Parse(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
private (int stack, int from, int to) ParseMoveLineRegex(string line)
|
private static (int stack, int from, int to) ParseMoveLineRegex(string line)
|
||||||
{
|
{
|
||||||
var r = MoveParser().Matches(line);
|
var r = MoveParser().Matches(line);
|
||||||
var items = r.First()
|
var items = r.First()
|
||||||
@@ -115,7 +115,7 @@ internal partial class SupplyStacks : Problem
|
|||||||
return (items[0], items[1], items[2]);
|
return (items[0], items[1], items[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<char> ParseCrateLine(string line)
|
private static List<char> ParseCrateLine(string line)
|
||||||
{
|
{
|
||||||
var result = new List<char>(line.Length / 4);
|
var result = new List<char>(line.Length / 4);
|
||||||
for (int i = 1; i < line.Length; i += 4)
|
for (int i = 1; i < line.Length; i += 4)
|
||||||
|
|||||||
41
AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs
Normal file
41
AdventOfCode/Problems/AOC2022/Day6/TuningTrouble.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using AdventOfCode.Runner.Attributes;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AdventOfCode.Problems.AOC2022.Day6;
|
||||||
|
|
||||||
|
[ProblemInfo(2022, 6, "Tuning Trouble")]
|
||||||
|
internal class TuningTrouble : Problem<int, int>
|
||||||
|
{
|
||||||
|
private string _input = string.Empty;
|
||||||
|
|
||||||
|
public override void CalculatePart1()
|
||||||
|
{
|
||||||
|
Part1 = FindMarker(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int FindMarker(int size = 4)
|
||||||
|
{
|
||||||
|
for (int i = size; i < _input.Length; i++)
|
||||||
|
{
|
||||||
|
var group = _input[(i - size)..i];
|
||||||
|
if (group.All(c => group.Count(gc => gc == c) == 1))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CalculatePart2()
|
||||||
|
{
|
||||||
|
Part2 = FindMarker(14);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadInput()
|
||||||
|
{
|
||||||
|
_input = ReadInputText();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
AdventOfCode/Problems/AOC2022/Day6/input.txt
Normal file
1
AdventOfCode/Problems/AOC2022/Day6/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
djhjvjggdzznllvvrvggscgscsrrffgvfvllfclcrchhwzhzqqlhqhffsdsmmcffnggcttdpttwpwttjvtjvtvqqctcwcmcsswvwzzlnzlnnvbnbdnngmmhchrcrqqhbhllbtllmppgjjtvjvdjvvpcpjcjjfrfzfzzdvzdvvswvvjzzbpzbzzddbndbbgjbjjvpjpjtjqtjqjcjmcjjrtjrjrqqvtvpvwpprhphrhdrddpdhhfsspddqnqwnntrtnrrthrhtrtwtdttmmnvmnmppswsqwqjqwqbqrqbqdbqdqgdqgqtgqqgzzhpzzwswvwmvwwvvrzznwzzbsbhbfhhvcvwvvrzrgzzfhzhhlthlhqhgqgttlmljmlmqqjddtqtctbblplddnqnzqnnzrzjrrqwrqqcfffbdfffspsqswstspsvppqmppdmppdvvfrfddqhqzqddtjddfqfrfllnjjcnnjzjmzmtmddbvdvzvbzzcjzzffdbdbsswshhrwrrfggpccszzzgdgvvlflwwdbbhqhffngffdfdmdgdhdmhdmdsspssctstdtdmdhhzvvcbbrqqmrmwwjmjqjmqjmjjjrmrmlmmbppmgpgttmptpspmmrttcddtjjspsfsqqbhbbzzgbzzznwzzlddmtdmdgmmlnljlvjjtgjjggmmnnvqnqzzfhzhttvbbprpmpmrmlrmllwmlwmlwwsjjlffbgfggqmggqgvglvvrpvrpvpnpphmhnmhhbbqjbbrrvfrfwflldffzwzccscqsqppctctddqbbmggmccdbdvbdvvpdpdbdsdjsjbbwpwcpcbcbmmzdmmvtvqvpvphhlblwwfmwmvvdhdtdwwlblglhhvfvwwqggrnrttpddtvvwqvqmqhhwnnghhbpbvbnvvdqqrqdqwqppmwpwhppnmnjmnjmjttvhhcgchcssrlrwllpdpndpdtptzppqqpvvtffcwffjppvnnjvvjnnwcwnnhlhjhsjsnjjzfjfsfhsssvttvfvsvpspppwswmswwqmwwzvwzzvtzvvwddqqzhhqpqjjwrwlrrbcbvvqllqjllvzvgvmvhmmsppwvpwphhjnndjjtpjtthzzvrrcwcrczzmqmsssvtstqtrrgtrtvtwtccbwcwrwbbdbgbmmcsmcssvjsjqqsnqqtvvbgbfbdffhjffvnnzpplqppzzfwfrfnfcncqccgjjcffhshrhgrhghvhphccqtcqtccjzccdnncggftgttrppnpptlltztqtjqqvfvqvdvmvmjjgqqrqgrqqcggdvvpcvcjvjnnrjjmbmlbmmqvmqmfmwmpwwnhwdtmvhqfwlbpzjplfhfntjgmvqmmjqpbngpvjvpgzpqwjjwhvjwwplrtjhzmzqmdrppgbrspmctlggmflbjzzfcvvdqlrtvqvwhcpjnmlvfgwrwwtblpqstddnqntnmwsbgjfrbdrlnvqdrnttshjmvpmncmggfdbnndwzmswmdvhmmwtgpfglrzzhwcsgvhnnrrhmnhftvvqfdfrsphzbslgscmwsnrwbvqphhswvpvsbbstvnndclhfhdctlvwrmdgzfcfmjmznqvvqrddmdlqznvcsqsgnpcqqhbdwqntcnqljstqvrzhgvzqdltpwmnpvjmqrpjsfhqvhchjnwjnqpdqbdjqdpqsqhbwwmhfthzbrsjnhncpbjrhgqlzmrzlnvrrfvlrmflcqfmqjzjwscrflgzwtbchfrnvsrrtncvhjbnnmlmmfdjcbmbsmgdtwzwcwnthfbsnrgdfwqjncqsdmfnfqgtcwrhjprlnhvrnpmnnhlwstvqjrsprqhjzszzgfznmgwjqglvfrrwpdbptdrnbbwbzbcbhbtcchmfsgmvnmrbdqhqgmvtfmvpgvjzjpgjbdhcfrfhprgdzrprccnhbmzdfjsgldlgpgdrfhbhtmhdttdsbndgbdfccqhhwhqfmlsfhsbbbmdncrwzcnrdvcmhllfwtrgjpgngzwptnqtggtcjwrptffmsrgdpctsdjtpssngsdqwfsbhdbcqvbdrzlhzlsbbzhqthzhcwsftlhrmhgpfzljgcphjjvhpqjzsfnrztwrhlnlbmgcgmstrbbwclpvdtdpclzlhmmpmmpmppnwjglhwppprlbzbvwqwmpgtvvpgdthnwbtblwpwgvmbcbjwjbczlcmzfwzbqvzsvgcmspvrsblldscqlgghdwzbvhhvgcfwgnqwlngclbjfwrpwtdjvqmzwwjztwdjplhzpzfslbbvfdsnpggwcttzwdlzgqgmrnpnclhrlngtwcwblzdjmpgqvzsvsdmzdwlgcdlccnnlrcvtrvspcsmgmzzvwnlzwtznwtqtdjcnhwrqhqrmvqqhrpdtnsmfrlcgpjcnddsqzcppgrnhvwsdbjvvtmvbjdncpdnmzfswmtvzfbdpqfjvwvqlhptnpdfdnlwfrgstpvvmhsqfgggdrsfgldfzbcjzhqzvfwmzccwjrslhjwlbmrpqgzdfnfbhsmdpzwtqnqldtqvshvlvmlnnmqrqbpwvnhqhtcbfclhrcqlqzhsqplsnbczvrbzqwlfwjdtmstzdbswtrvlpzzlrfvgdmldbwcttztrvsgzjwhhpcrvtgzfzppdlrdwswbnjfqqpqfbcqlzdmjsgjtzmvhdzspwlqpdjnccmbtdhnnhfvwqclbzzgglfgmvvgrccdsbwfmpvqwqrhmdzfhhhgbgjgwmnzmnggfrpspchvzpcmcpsbzgldmgqjqqdcjpwwncwrwjbhgzdbbcmbzbbtvprsjrhfwgsppdrrlzvnmtmwrmmrhtlndvsvjvgqmmttbbnpdhnjhwgrvlrdtpbrtwpwvvpslcqnvnrlhpvgdwnrzjmhwmgvpndtrjlzqpfzfbrsgbzjjqcfgsfwchblzstdflblngtzbrzrrvsczqvfhjjdlffrghgqvqfdtstqlnzllsrnnrtvrzdphbhdfpmhlfncqbdtzjqqcfbzpvgzdcsvvbfdvqrfrncbrwmpdmhnlqdscwnvldzblpzfqcvnbzmmtbmwjbczsjvzmfthfpvjcpwftqcbgjwflfrbrggwnvwndtncljfrdfwqwhfbctpjghfvnjnntnrgbfbmhplgmpfvmgvfqjslgnnrnlgztlstpcjwtlhmwlljcfmptfwsphnlsrjwmgtghgqmsvwvqsmblwpdftbrwjcdlzjmjblghszznqhsnqrcmtccgdwrrlsmwswvrjltqmwsdwvpnzltllhrsdvmrntdhtwwbgrqmrffnqbqrczvzchbgmzwtjtfzwntsnlbwbgrlvqjsqmdnwjqlwrdpnfpggzrjvtrhqdbmmbtfmmblgwtrqccqbjnljqflhgtphvrgrgghgrpbgfgdztsmfwrfflsqmrwbfjwsmpfrnbqjwnwdqwcwzpwbsmngjwfmbwdmnprdjnjbmqgfcbvtcvcthpmnmvvzdzgqqbhtjqfcdvhfzwqgfsbtvnwbzpmmtswfntjjppsswgbfrjbrstltdgbmclmbfvlslghbhnqqbdlzgtctgsfnwvbpzbvnwfbjmbfqcpqqvgrzwcbrwzdbdsjsslcjlmtprntpsdmqldzwqlqztwqtqfqzmrnzbtpqlfnsdwfdgggfvmqmrdqmnffnzcwfzsrqfpvrmsfsrbnpbhnqvdglvglllpggpmwmngrhzwgpdlzrbsvjtqmshhnlzwwftdtqwrqwgbbnczqcwmsvcljqlscftwflhwwhgnqwztfchdzsllrzbhbqwcfztjnqtdmsfnlzlcwzfmtlcgwclzfhhldgrnfjvzthzqzmzvwcrnhpdcwswpddsbwtznwlcwsnfqnqwnntngplwnfgwrcnpvgffwrcrszzdbfvzjmrmlrjwcvdvbglgncjwcnnpdfnwsrzsvzgnjrlqmwhvtdgmpbqmjthmhhmzjhpvnbvrqnlspdbcgshwlnvwpvrbcmvbvcsdmgwtmsthqtcfmllsfwvqcrbmdgqtzjwrg
|
||||||
1
AdventOfCode/Problems/AOC2022/Day6/test.txt
Normal file
1
AdventOfCode/Problems/AOC2022/Day6/test.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
|
||||||
@@ -27,23 +27,25 @@ public class AOCRunner
|
|||||||
FindProblemClasses();
|
FindProblemClasses();
|
||||||
|
|
||||||
InitSizing();
|
InitSizing();
|
||||||
if(_years.Count > 0)
|
if (_years.Count > 0)
|
||||||
{
|
{
|
||||||
_selectedDay = _loadedProblems[_selectedYear].Count - 1;
|
_selectedDay = _loadedProblems[_selectedYear].Count - 1;
|
||||||
ConstrainListScroll();
|
ConstrainListScroll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitSizing() {
|
private void InitSizing()
|
||||||
|
{
|
||||||
_maxProblemCount = Console.WindowHeight - 9;
|
_maxProblemCount = Console.WindowHeight - 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConstrainListScroll()
|
private void ConstrainListScroll()
|
||||||
{
|
{
|
||||||
if (_selectedDay >= _maxProblemCount )
|
if (_selectedDay >= _maxProblemCount)
|
||||||
{
|
{
|
||||||
_scollOffset = _loadedProblems[_selectedYear].Count - _maxProblemCount;
|
_scollOffset = _loadedProblems[_selectedYear].Count - _maxProblemCount;
|
||||||
} if(_selectedDay < _scollOffset)
|
}
|
||||||
|
if (_selectedDay < _scollOffset)
|
||||||
{
|
{
|
||||||
_scollOffset = _selectedDay;
|
_scollOffset = _selectedDay;
|
||||||
}
|
}
|
||||||
@@ -91,11 +93,16 @@ public class AOCRunner
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Loading Input data...\n");
|
var time = ReadInput(problem);
|
||||||
problem.LoadInput();
|
time += RunPart("Calculating Part 1", problem.CalculatePart1);
|
||||||
|
time += RunPart("Calculating Part 2", problem.CalculatePart2);
|
||||||
|
|
||||||
RunPart("Calculating Part 1", problem.CalculatePart1);
|
Console.WriteLine();
|
||||||
RunPart("Calculating Part 2", problem.CalculatePart2);
|
Console.Write($"Total Elapsed Time: ");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine($"{time.TotalMilliseconds}ms");
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("Printing Results:");
|
Console.WriteLine("Printing Results:");
|
||||||
@@ -108,7 +115,23 @@ public class AOCRunner
|
|||||||
Console.Write("\n\n");
|
Console.Write("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunPart(string name, Action action)
|
private static TimeSpan ReadInput(IProblem problem)
|
||||||
|
{
|
||||||
|
var sw = new Stopwatch();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.Write("Loading Input data... ");
|
||||||
|
sw.Start();
|
||||||
|
problem.LoadInput();
|
||||||
|
sw.Stop();
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.Write("Done in ");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine($"{sw.Elapsed.TotalMilliseconds:n}ms");
|
||||||
|
return sw.Elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TimeSpan RunPart(string name, Action action)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
var sw = new Stopwatch();
|
var sw = new Stopwatch();
|
||||||
@@ -139,6 +162,7 @@ public class AOCRunner
|
|||||||
sw.Stop();
|
sw.Stop();
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
}
|
}
|
||||||
|
return sw.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderInteractiveMenu()
|
public void RenderInteractiveMenu()
|
||||||
@@ -159,9 +183,10 @@ public class AOCRunner
|
|||||||
private void ReadInput()
|
private void ReadInput()
|
||||||
{
|
{
|
||||||
var input = Console.ReadKey(true);
|
var input = Console.ReadKey(true);
|
||||||
if(_isProblemMode)
|
if (_isProblemMode)
|
||||||
{
|
{
|
||||||
if(input.Key is ConsoleKey.Enter or ConsoleKey.Escape) {
|
if (input.Key is ConsoleKey.Enter or ConsoleKey.Escape)
|
||||||
|
{
|
||||||
_isProblemMode = false;
|
_isProblemMode = false;
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
@@ -169,7 +194,7 @@ public class AOCRunner
|
|||||||
}
|
}
|
||||||
var yearIndex = _years.IndexOf(_selectedYear);
|
var yearIndex = _years.IndexOf(_selectedYear);
|
||||||
var dayMax = _loadedProblems[_selectedYear].Count - 1;
|
var dayMax = _loadedProblems[_selectedYear].Count - 1;
|
||||||
switch(input.Key)
|
switch (input.Key)
|
||||||
{
|
{
|
||||||
case ConsoleKey.LeftArrow:
|
case ConsoleKey.LeftArrow:
|
||||||
_scollOffset = 0;
|
_scollOffset = 0;
|
||||||
@@ -180,7 +205,8 @@ public class AOCRunner
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_selectedYear = _years[--yearIndex];
|
_selectedYear = _years[--yearIndex];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleKey.RightArrow:
|
case ConsoleKey.RightArrow:
|
||||||
_scollOffset = 0;
|
_scollOffset = 0;
|
||||||
_selectedDay = 0;
|
_selectedDay = 0;
|
||||||
@@ -191,6 +217,7 @@ public class AOCRunner
|
|||||||
}
|
}
|
||||||
_selectedYear = _years[++yearIndex];
|
_selectedYear = _years[++yearIndex];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleKey.UpArrow:
|
case ConsoleKey.UpArrow:
|
||||||
if (_selectedDay == 0)
|
if (_selectedDay == 0)
|
||||||
{
|
{
|
||||||
@@ -198,7 +225,8 @@ public class AOCRunner
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_selectedDay--;
|
_selectedDay--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleKey.DownArrow:
|
case ConsoleKey.DownArrow:
|
||||||
if (_selectedDay == dayMax)
|
if (_selectedDay == dayMax)
|
||||||
{
|
{
|
||||||
@@ -211,6 +239,7 @@ public class AOCRunner
|
|||||||
case ConsoleKey.Enter:
|
case ConsoleKey.Enter:
|
||||||
_isProblemMode = true;
|
_isProblemMode = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleKey.Escape:
|
case ConsoleKey.Escape:
|
||||||
_isQuiting = true;
|
_isQuiting = true;
|
||||||
break;
|
break;
|
||||||
@@ -220,8 +249,10 @@ public class AOCRunner
|
|||||||
|
|
||||||
private void RenderTopBar()
|
private void RenderTopBar()
|
||||||
{
|
{
|
||||||
|
if (_isProblemMode)
|
||||||
|
return;
|
||||||
//Render Border
|
//Render Border
|
||||||
DrawBorder(1,0, Console.WindowWidth, 3);
|
DrawBorder(1, 0, Console.WindowWidth, 3);
|
||||||
Console.SetCursorPosition(Console.WindowWidth / 2 - 4, 1);
|
Console.SetCursorPosition(Console.WindowWidth / 2 - 4, 1);
|
||||||
Console.ForegroundColor = ConsoleColor.Blue;
|
Console.ForegroundColor = ConsoleColor.Blue;
|
||||||
Console.Write(" Years ");
|
Console.Write(" Years ");
|
||||||
@@ -240,38 +271,36 @@ public class AOCRunner
|
|||||||
var end = col + buttonWidth;
|
var end = col + buttonWidth;
|
||||||
if (end >= tabMaxPos)
|
if (end >= tabMaxPos)
|
||||||
break;
|
break;
|
||||||
if(year == _selectedYear)
|
if (year == _selectedYear)
|
||||||
DrawSelectedButton(year.ToString(), 2, col, buttonWidth, 1, ConsoleColor.Red, ConsoleColor.Blue);
|
DrawSelectedButton(year.ToString(), 2, col, buttonWidth, 1, ConsoleColor.Red, ConsoleColor.Blue);
|
||||||
else
|
else
|
||||||
DrawButton(year.ToString(), 2, col, buttonWidth, 1, ConsoleColor.Gray, Console.BackgroundColor);
|
DrawButton(year.ToString(), 2, col, buttonWidth, 1, ConsoleColor.Gray, Console.BackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderContentView()
|
private void RenderContentView()
|
||||||
{
|
{
|
||||||
DrawBorder(5, 0, Console.WindowWidth, Console.WindowHeight - 5);
|
if (!_isProblemMode)
|
||||||
Console.SetCursorPosition(Console.WindowWidth/2 - 5, 5);
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Blue;
|
DrawBorder(5, 0, Console.WindowWidth, Console.WindowHeight - 5);
|
||||||
Console.Write(" Problems ");
|
Console.SetCursorPosition(Console.WindowWidth / 2 - 5, 5);
|
||||||
if (_isProblemMode)
|
Console.ForegroundColor = ConsoleColor.Blue;
|
||||||
RenderProblemResults();
|
Console.Write(" Problems ");
|
||||||
else
|
|
||||||
RenderProblemList();
|
RenderProblemList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
RenderProblemResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderProblemList()
|
private void RenderProblemList()
|
||||||
{
|
{
|
||||||
if(_loadedProblems.Count == 0)
|
if (_loadedProblems.Count == 0)
|
||||||
{
|
{
|
||||||
DrawButton("There are no problems...", 6, 2, Console.WindowWidth - 2, Console.WindowHeight - 7);
|
DrawButton("There are no problems...", 6, 2, Console.WindowWidth - 2, Console.WindowHeight - 7);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var problems = _loadedProblems[_selectedYear];
|
var problems = _loadedProblems[_selectedYear];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var listEnd = Math.Min(_maxProblemCount, problems.Count);
|
var listEnd = Math.Min(_maxProblemCount, problems.Count);
|
||||||
|
|
||||||
for (int i = 0; i < listEnd; i++)
|
for (int i = 0; i < listEnd; i++)
|
||||||
@@ -296,6 +325,7 @@ public class AOCRunner
|
|||||||
Console.SetCursorPosition(2, 7);
|
Console.SetCursorPosition(2, 7);
|
||||||
RunDay(_selectedYear, _selectedDay);
|
RunDay(_selectedYear, _selectedDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawSelectedButton(string text, int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black, bool centered = true, int padding = 0)
|
private void DrawSelectedButton(string text, int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black, bool centered = true, int padding = 0)
|
||||||
{
|
{
|
||||||
//text = $"\ue0c7{text}\ue0c6";
|
//text = $"\ue0c7{text}\ue0c6";
|
||||||
@@ -317,11 +347,10 @@ public class AOCRunner
|
|||||||
Console.ForegroundColor = background;
|
Console.ForegroundColor = background;
|
||||||
Console.SetCursorPosition(col, row + height / 2);
|
Console.SetCursorPosition(col, row + height / 2);
|
||||||
Console.Write('\ue0c7');
|
Console.Write('\ue0c7');
|
||||||
Console.SetCursorPosition(col + width -1, row + height / 2);
|
Console.SetCursorPosition(col + width - 1, row + height / 2);
|
||||||
Console.Write('\ue0c6');
|
Console.Write('\ue0c6');
|
||||||
|
|
||||||
Console.BackgroundColor = origBg;
|
Console.BackgroundColor = origBg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawButton(string text, int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black, bool centered = true, int padding = 0)
|
private void DrawButton(string text, int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black, bool centered = true, int padding = 0)
|
||||||
@@ -341,7 +370,6 @@ public class AOCRunner
|
|||||||
Console.SetCursorPosition(col + xOffset, row + yOffset);
|
Console.SetCursorPosition(col + xOffset, row + yOffset);
|
||||||
Console.Write(text);
|
Console.Write(text);
|
||||||
Console.BackgroundColor = origBg;
|
Console.BackgroundColor = origBg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawBorder(int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, bool drawFill = false)
|
private void DrawBorder(int row, int col, int width, int height, ConsoleColor color = ConsoleColor.Gray, bool drawFill = false)
|
||||||
@@ -367,9 +395,8 @@ public class AOCRunner
|
|||||||
Console.Write('║');
|
Console.Write('║');
|
||||||
else if (y == row || y == h)
|
else if (y == row || y == h)
|
||||||
Console.Write('═');
|
Console.Write('═');
|
||||||
else if(drawFill)
|
else if (drawFill)
|
||||||
Console.Write(' ');
|
Console.Write(' ');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user