From 1c32616861a5bbee6a146863c8ee1e8e48550cc2 Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 15 Dec 2020 09:02:28 -0600 Subject: [PATCH] Slightly faster day 15, still not great --- Q15.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Q15.cs b/Q15.cs index b5b8ca6..baecdd6 100644 --- a/Q15.cs +++ b/Q15.cs @@ -34,15 +34,15 @@ namespace _2020 static int GetNumAt(int turn) { - var numsSaidDict = new Dictionary>(); + var numsSaidDict = new Dictionary(); int lastNumSaid = 0; - List entry = null; + int[] entry = null; for (int i = 0; i < turn; i++) { if (i < list.Count) { - numsSaidDict.Add(list[i], new List() { i }); + numsSaidDict.Add(list[i], new int[2] { i, -1 }); lastNumSaid = list[i]; } else @@ -55,7 +55,7 @@ namespace _2020 { if (entry != null) { - lastNumSaid = entry.Count == 1 ? 0 : entry[^1] - entry[^2]; + lastNumSaid = entry[1] == -1 ? 0 : entry[0] - entry[1]; } else { @@ -66,11 +66,19 @@ namespace _2020 numsSaidDict.TryGetValue(lastNumSaid, out entry); if (entry == null) { - entry = new List(); + entry = new int[2] { -1, -1 }; numsSaidDict.Add(lastNumSaid, entry); } - entry.Add(i); + if (entry[0] == -1) + { + entry[0] = i; + } + else + { + entry[1] = entry[0]; + entry[0] = i; + } } }