Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created October 28, 2017 14:23
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 dance2die/067a741bca0d2bce5024567e05eb8e2a to your computer and use it in GitHub Desktop.
Save dance2die/067a741bca0d2bce5024567e05eb8e2a to your computer and use it in GitHub Desktop.
Parse functionally.
public static int[] Parse(string data)
{
var result = new List<int>();
var commands = new Dictionary<char, Func<int, int>>
{
{'i', n => ++n },
{'d', n => --n },
{'s', n => n * n },
{'o', n => { result.Add(n); return n; } }
};
var value = 0;
data.Select(c => value = commands[c](value)).ToList();
return result.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment