Ejemplo n.º 1
0
        internal void SolveInteractively()
        {
            initialInput = new CaseInput(commsStream.ReadSingleLineOfLongsInput());

            var firstStepInput = new CaseStepInput(commsStream.ReadSingleLineOfLongsInput());

            samples = new List <Sample>();
            samples.Add(new Sample {
                Value = firstStepInput.NumberOfPassages, Weight = 1
            });
            knownRooms.Add(firstStepInput.RoomNumber);

            var maxSteps = Math.Min(initialInput.K, initialInput.N);

            for (int step = 1; step < maxSteps + 1; step++)
            {
                var nextAction = DetermineNextAction(step);
                commsStream.WriteSingleInteractiveOutput(nextAction.ToString());
                var stepInput = new CaseStepInput(commsStream.ReadSingleLineOfLongsInput());
                UpdateSamples(step, stepInput);
            }

            var integerGuess = CalculateFinalGuess();

            commsStream.WriteSingleInteractiveOutput(CaseStepOutput.FinalGuess(integerGuess).ToString());
        }
Ejemplo n.º 2
0
 private void UpdateSamples(int step, CaseStepInput stepInput)
 {
     if (step % 2 == 0)
     {
         samples.Add(new Sample
         {
             Value  = stepInput.NumberOfPassages,
             Weight = 1
         });
     }
     else
     {
         var previousStepValue = samples.Last().Value;
         samples.Add(new Sample
         {
             Value  = stepInput.NumberOfPassages,
             Weight = (decimal)previousStepValue / stepInput.NumberOfPassages
         });
     }
 }