Ejemplo n.º 1
0
        // --------------------------------------------------------------------
        public string PuzzleB(StepRules rules, int availableWorkers, int timeAdder = 0)
        {
            int seconds = 0;
            var wp      = new WorkProcessor(availableWorkers);

            wp.TimeAdder = timeAdder;

            List <string> ready;

            while (true)
            {
                ready = rules.GetReadySteps();
                wp.LoadWorkQueue(ref ready);

                if (wp.IsTaskQueueEmpty())
                {
                    break;
                }

                var completed = wp.ProcessQueue();
                seconds++;

                rules.RemoveDependencies(completed);
            }

            return(seconds.ToString());
        }
Ejemplo n.º 2
0
        // --------------------------------------------------------------------
        public async Task <StepRules> LoadStepRules()
        {
            var data = await GetInput(DATANAME);

            var rules = new StepRules();

            foreach (var d in data)
            {
                rules.AddRule(d);
            }

            return(rules);
        }
Ejemplo n.º 3
0
        // --------------------------------------------------------------------
        public string PuzzleA(StepRules rules)
        {
            var sequence = new List <string>();

            while (true)
            {
                var ready = rules.GetNextReadyStep();
                if (String.IsNullOrEmpty(ready))
                {
                    break;
                }

                sequence.Add(ready);
                rules.RemoveDependency(ready);
            }

            return(String.Join(String.Empty, sequence));
        }