Skip to content

Instantly share code, notes, and snippets.

@aevitas
Created December 10, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevitas/1e7042f39ffafde11227ff67df7118a3 to your computer and use it in GitHub Desktop.
Save aevitas/1e7042f39ffafde11227ff67df7118a3 to your computer and use it in GitHub Desktop.
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