Created
December 10, 2022 12:34
-
-
Save aevitas/1e7042f39ffafde11227ff67df7118a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void PartOneAlt() | |
{ | |
int numTicks = 0; | |
List<int> reads = new(); | |
Dictionary<int, int> ops = new(); | |
for (int i = 0; i < Input.Length; i++) | |
{ | |
var split = Input[i].Split(' '); | |
var op = split[0]; | |
var arg = split.Length > 1 ? split[1] : string.Empty; | |
if (op == "noop") | |
{ | |
Run(1); | |
continue; | |
} | |
// Effective end of 2 cycles after this, or start of third cycle | |
ops[numTicks + 2] = int.Parse(arg); | |
Run(2); | |
} | |
Run(10); | |
var t = new[] { 20, 60, 100, 140, 180, 220 }; | |
foreach (var c in t) | |
{ | |
var x = ops.Where(k => k.Key <= c).Select(k => k.Value).Sum() + 1; | |
reads.Add(x * c); | |
} | |
Console.WriteLine(reads.Sum()); | |
void Run(int ticks) | |
{ | |
for (int i = 0; i < ticks; i++) | |
{ | |
numTicks++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment