From c5f9c49bea393e2d0d9d492f6950f7e174f0fee1 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sat, 9 Dec 2023 00:47:02 -0600 Subject: [PATCH] chore: add xml comments --- 08/HauntedWasteland/Program.cs | 65 ++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/08/HauntedWasteland/Program.cs b/08/HauntedWasteland/Program.cs index 98ce232..df08344 100644 --- a/08/HauntedWasteland/Program.cs +++ b/08/HauntedWasteland/Program.cs @@ -37,14 +37,32 @@ public class Program } } +/// +/// A map of the Haunted Wasteland. +/// +/// The turns to take at each step. +/// The nodes in the map. +/// An instance of . public class Map( List turns, List nodes ) { + /// + /// Gets the turns to take at each step. + /// public List Turns { get; init; } = turns; + + /// + /// Gets the nodes in the map. + /// public List Nodes { get; init; } = nodes; + /// + /// Parses a map from a string array. + /// + /// The map input. + /// An instance of . public static Map Parse(string[] mapInput) { var turns = mapInput[0].ToList(); @@ -55,6 +73,10 @@ public class Map( return new Map(turns, nodes); } + /// + /// Counts the number of steps to the Z node. + /// + /// The number of steps to the Z node. public int CountStepsToZ() { var current = Nodes.First(n => n.Current == "AAA"); @@ -75,9 +97,11 @@ public class Map( return steps; } - // This method finds the prime factors of a given number. - // It takes an integer 'number' as input and returns a list of prime factors. - + /// + /// Finds the prime factors of a number. + /// + /// The number to find the prime factors of. + /// The prime factors of the number. public List FindPrimeFactors(long number) { var factors = new List(); @@ -106,6 +130,11 @@ public class Map( return factors; } + /// + /// Finds the least common multiple of a list of numbers. + /// + /// The numbers to find the least common multiple of. + /// The least common multiple of the numbers. public long FindLeastCommonMultiple(List numbers) { var primeFactors = numbers.Select(FindPrimeFactors).ToList(); @@ -132,6 +161,10 @@ public class Map( return result; } + /// + /// Counts the number of steps to all Z nodes. + /// + /// The number of steps to all Z nodes. public long CountStepsToAllZNodes() { var startNodes = Nodes.Where(n => n.Current.EndsWith('A')).ToList(); @@ -161,21 +194,47 @@ public class Map( } } +/// +/// A node in the map. +/// +/// The current node. +/// The left node. +/// The right node. +/// An instance of . public class Node( string current, string left, string right ) { + /// + /// Gets the current node. + /// public string Current { get; init; } = current; + + /// + /// Gets the left node. + /// public string Left { get; init; } = left; + + /// + /// Gets the right node. + /// public string Right { get; init; } = right; + /// + /// Casts the node to a string. + /// public override string ToString() { return $"{Current} = ({Left},{Right})"; } + /// + /// Parses a node from a string. + /// + /// The node string. + /// An instance of . public static Node Parse(string nodeString) { var parts = nodeString.Split(