コード例 #1
0
        public void Parse(string problem)
        {
            allsteps = new Dictionary <string, Day7Step>();
            var strings = problem.Split("\r\n");

            foreach (string str in strings)
            {
                if (str.Length >= 36)
                {
                    var blockerID = str.Substring(5, 1);
                    var id        = str.Substring(36, 1);
                    var step      = new Day7Step(id);
                    var blocker   = new Day7Step(blockerID);

                    allsteps.TryAdd(id, step);
                    allsteps.TryAdd(blockerID, blocker);

                    step    = allsteps[id];        //getA
                    blocker = allsteps[blockerID]; //getB

                    step.isBlockedBy(ref blocker); //update both

                    allsteps[id]        = step;    //setA
                    allsteps[blockerID] = blocker; //setB
                }
            }
        }
コード例 #2
0
 public void assignJob(int startTime, ref Day7Step newTask)
 {
     this.readyforwork  = false;
     this.startTime     = startTime;
     this.currentTask   = newTask;
     newTask.inprogress = true;
     foreach (char c in currentTask.id)
     {
         int duration = c - 64;
         finishTime = startTime + duration + 60;
     }
 }
コード例 #3
0
        public List <Day7Step> completeAStep(List <Day7Step> answers, Day7Step step, ref List <Day7Step> queue)
        {
            //this is a step we are trying to solve.
            // step 1, check all "is blocked by".
            // if answers contains every "blocker", add this to answers - it is now solved.
            // then, foreach 'blocks', try and solve

            //currently we're getting repeated things. Worth maintaing a global answers string just for debugging?
            string dbganswerprogress = "";

            foreach (var dbgstep in answers)
            {
                dbganswerprogress += dbgstep.id;
            }

            String dbgstatus = step.id + ": first we're looking at " + step.id + ",  which blocks [";

            foreach (var dbg in step.getSortedBlocks())
            {
                dbgstatus += dbg.id + ", ";
            }
            dbgstatus = dbgstatus.Substring(0, dbgstatus.Length - 2) + "] and is blocked by [";
            foreach (var dbg in step.getSortedBlockedBy())
            {
                dbgstatus += dbg.id + ", ";
            }
            dbgstatus = dbgstatus.Substring(0, dbgstatus.Length - 2) + "].";
            Console.WriteLine(dbgstatus);
            dbgstatus = step.id + ": queue status is [";
            foreach (var dbg in queue)
            {
                dbgstatus += dbg.id;
            }
            dbgstatus += "]";
            Console.WriteLine(dbgstatus);
            string dbg2    = "[";
            var    blocked = false;

            if (dbganswerprogress == "BFLNGIRUSJXEHKQP")
            {  //at Z, going into A, and then D
               //BFLNGIRUSJXEHKQPYVOTCZDWMA -- current
               //BFLNGIRUSJXEHKQPVTYOCZDWMA -- correct
            }
            foreach (var blocker in step.getSortedBlockedBy())
            {
                if (!answers.Contains(blocker))
                {
                    blocked = true;
                    dbg2   += blocker.id + ", ";
                }
            }

            if (!blocked)
            {
                //it's possible that we might find ourselves completing steps more than once.
                if (answers.Contains(step))
                {
                    Console.WriteLine(step.id + ": We have ALREADY completed step " + step.id + ", checking blocked steps");
                }
                else
                {
                    answers.Add(step);
                    Console.WriteLine(step.id + ": Completed step " + step.id + ", now looking at the steps it blocks");
                }



                foreach (Day7Step possiblyUnblocked in step.getSortedBlocks())
                {
                    Console.WriteLine(step.id + "> Queuing start looking at " + possiblyUnblocked.id);
                    if (!queue.Contains(possiblyUnblocked))
                    {
                        queue.Add(possiblyUnblocked);
                    }
                }

                queue.Sort();
                queue.Remove(step);
            }
            else
            {
                Console.WriteLine(step.id + ": Could not complete step " + step.id + ", because" + dbg2.Substring(0, dbg2.Length - 2) + "] are not complete");
            }

            Console.WriteLine(step.id + "< finishing looking at " + step.id + ", going up a level.");
            queue.Remove(step);//we don't need to reprocess this one
            return(answers);
        }