Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Calculation
- {
- public delegate int Command(int x);
- private List<Command> commands = new List<Command>();
- public void RegisterCommand(Command command) => commands.Add(command);
- public long GetCount(int begin, int[] checkPointsOrder, int[] deprecated = null, Func<int, bool> stop = null)
- {
- if (checkPointsOrder == null || checkPointsOrder.Length == 0) return 0;
- if (deprecated == null) deprecated = new int[]{ };
- if (stop == null) stop = x => false;
- SortedSet<int> depr = new SortedSet<int>(deprecated);
- int Run(int x, int currEnd)
- {
- if (depr.Contains(x) || stop(x)) return 0;
- if (x == currEnd) return 1;
- try
- {
- return commands.Select(f => Run(checked(f(x)), currEnd)).Sum();
- }
- catch(Exception)
- {
- return 0;
- }
- }
- long result = 1;
- foreach(int end in checkPointsOrder)
- {
- result *= Run(begin, end);
- begin = end;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement