Created
October 28, 2017 14:22
-
-
Save dance2die/638139dd386ec7a3b806327aa470911a to your computer and use it in GitHub Desktop.
Parsing and operating on a value iteratively
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 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