Skip to content

Instantly share code, notes, and snippets.

@underscoreHao
Last active December 2, 2021 19:55
Show Gist options
  • Save underscoreHao/64d9b2e876e5c9c5a2e1093daf94da46 to your computer and use it in GitHub Desktop.
Save underscoreHao/64d9b2e876e5c9c5a2e1093daf94da46 to your computer and use it in GitHub Desktop.
AOC - 2021 - Day 2 in C#
var input = File.ReadLines(@"G:\Code\Lambda\input")
.Select(x => x.Split(" "))
.Select(x => Tuple.Create(x[0], int.Parse(x[1])))
.ToList();
int horizontal = 0;
int depth = 0;
Dictionary<string, Action<int>> funcs = new();
funcs.Add("forward", foo => horizontal += foo);
funcs.Add("up", foo => depth -= foo);
funcs.Add("down", foo => depth += foo);
input.ForEach(x => funcs[x.Item1](x.Item2));
Console.WriteLine(horizontal * depth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment