Пример #1
0
        public string Solution(Bomb bomb)
        {
            PairCharacterValue1 = InternalFunctions.GetNumberFromLetter(bomb.GetSerialCharacterAtPosition(4));
            PairCharacterValue2 = InternalFunctions.GetNumberFromLetter(bomb.GetSerialCharacterAtPosition(5));

            ChangeCharacterValue(bomb.GetLitIndicatorsWithLetter(RecievedCharacter1), 1);
            ChangeCharacterValue(bomb.GetLitIndicatorsWithLetter(RecievedCharacter2), 1);
            ChangeCharacterValue(bomb.GetLitIndicatorsWithLetter(RecievedCharacter3), 1);
            ChangeCharacterValue(bomb.GetUnlitIndicatorsWithLetter(RecievedCharacter1), 2);
            ChangeCharacterValue(bomb.GetUnlitIndicatorsWithLetter(RecievedCharacter2), 2);
            ChangeCharacterValue(bomb.GetUnlitIndicatorsWithLetter(RecievedCharacter3), 2);

            if (InternalFunctions.IsSquare(PairCharacterValue1 + PairCharacterValue2))
            {
                ChangeCharacterValue(4, 1);
            }
            else
            {
                ChangeCharacterValue(-4, 2);
            }

            if (RecievedCharacterValue1 > RecievedCharacterValue2)
            {
                if (RecievedCharacterValue1 > RecievedCharacterValue3)
                {
                    ChangeCharacterValue(RecievedCharacterValue1, 1);
                }
                else
                {
                    ChangeCharacterValue(RecievedCharacterValue3, 1);
                }
            }
            else
            if (RecievedCharacterValue2 > RecievedCharacterValue3)
            {
                ChangeCharacterValue(RecievedCharacterValue2, 1);
            }
            else
            {
                ChangeCharacterValue(RecievedCharacterValue3, 1);
            }

            if (InternalFunctions.IsPrime(RecievedCharacterValue1))
            {
                ChangeCharacterValue(-RecievedCharacterValue1, 1);
            }
            if (InternalFunctions.IsPrime(RecievedCharacterValue2))
            {
                ChangeCharacterValue(-RecievedCharacterValue2, 1);
            }
            if (InternalFunctions.IsPrime(RecievedCharacterValue3))
            {
                ChangeCharacterValue(-RecievedCharacterValue3, 1);
            }

            if (InternalFunctions.IsSquare(RecievedCharacterValue1))
            {
                ChangeCharacterValue(-RecievedCharacterValue1, 2);
            }
            if (InternalFunctions.IsSquare(RecievedCharacterValue2))
            {
                ChangeCharacterValue(-RecievedCharacterValue2, 2);
            }
            if (InternalFunctions.IsSquare(RecievedCharacterValue3))
            {
                ChangeCharacterValue(-RecievedCharacterValue3, 2);
            }

            if (bomb.HasManyBatteries(1))
            {
                if (RecievedCharacterValue1 % bomb.GetBatteries() == 0)
                {
                    ChangeCharacterValue(-RecievedCharacterValue1, 1); ChangeCharacterValue(-RecievedCharacterValue1, 2);
                }
                if (RecievedCharacterValue2 % bomb.GetBatteries() == 0)
                {
                    ChangeCharacterValue(-RecievedCharacterValue2, 1); ChangeCharacterValue(-RecievedCharacterValue2, 2);
                }
                if (RecievedCharacterValue3 % bomb.GetBatteries() == 0)
                {
                    ChangeCharacterValue(-RecievedCharacterValue3, 1); ChangeCharacterValue(-RecievedCharacterValue3, 2);
                }
            }

            if (PairCharacterValue1 == PairCharacterValue2)
            {
                return(InternalFunctions.GetMorseFromLetter(InternalFunctions.GetLetterFromNumber(PairCharacterValue1)));
            }
            else
            if (PairCharacterValue1 > PairCharacterValue2)
            {
                return(InternalFunctions.GetMorseFromLetter(InternalFunctions.GetLetterFromNumber(PairCharacterValue1 - PairCharacterValue2)));
            }
            else
            {
                return(InternalFunctions.GetMorseFromLetter(InternalFunctions.GetLetterFromNumber(PairCharacterValue1 + PairCharacterValue2)));
            }
        }