From aba86313665bc4fd380bcec01372484109bd028c Mon Sep 17 00:00:00 2001 From: Parnic Date: Wed, 21 Dec 2022 13:27:12 -0600 Subject: [PATCH] Reformat code, remove unnecessary function --- src/20.cs | 22 +++------------------- src/Util/Math.cs | 14 ++++++++++---- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/20.cs b/src/20.cs index 14e247b..6982ba8 100644 --- a/src/20.cs +++ b/src/20.cs @@ -2,28 +2,12 @@ internal class Day20 : Day { - private List<(int num, int origIdx)> nums = new(); + private readonly List<(long num, int origIdx)> nums = new(); internal override void Parse() { foreach (var line in Util.Parsing.ReadAllLines("20")) { - nums.Add((int.Parse(line), nums.Count)); - } - } - - private static void mix(List<(int num, int origIdx)> mixedNums, IList<(int num, int origIdx)> origNums) - { - for (int i = 0; i < origNums.Count; i++) - { - if (origNums[i].num == 0) - { - continue; - } - - var idx = mixedNums.FindIndex(n => n.origIdx == origNums[i].origIdx); - mixedNums.RemoveAt(idx); - var newIdx = Util.Math.Modulo(idx + origNums[i].num, mixedNums.Count); - mixedNums.Insert((int)newIdx, origNums[i]); + nums.Add((long.Parse(line), nums.Count)); } } @@ -45,7 +29,7 @@ internal class Day20 : Day internal override string Part1() { - var mixedNums = new List<(int num, int origIdx)>(nums); + var mixedNums = new List<(long num, int origIdx)>(nums); mix(mixedNums, nums); var zeroIdx = mixedNums.FindIndex(n => n.num == 0); diff --git a/src/Util/Math.cs b/src/Util/Math.cs index b73ee88..aedfe15 100644 --- a/src/Util/Math.cs +++ b/src/Util/Math.cs @@ -44,18 +44,24 @@ public static class Math return (a * b) / GCD(a, b); } - public static long Modulo(long numer, long denom) { + public static long Modulo(long numer, long denom) + { // long q = numer / denom; long r = numer % denom; - if (r < 0) { - if (denom > 0) { + if (r < 0) + { + if (denom > 0) + { // q = q - 1; r = r + denom; - } else { + } + else + { // q = q + 1; r = r - denom; } } + return r; } } \ No newline at end of file