Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created October 28, 2017 14:22
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/638139dd386ec7a3b806327aa470911a to your computer and use it in GitHub Desktop.
Save dance2die/638139dd386ec7a3b806327aa470911a to your computer and use it in GitHub Desktop.
Parsing and operating on a value iteratively
public static int[] ParseIteratively(string data)
{
var results = new List<int>();
var sum = 0;
foreach (var cmd in data)
{
switch (cmd)
{
case 'i':
sum++;
break;
case 'd':
sum--;
break;
case 's':
sum = sum * sum;
break;
case 'o':
results.Add(sum);
break;
}
}
return results.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment