示例#1
0
        public static MessageResponse GeneralValidation(MutantDnaRequest request)
        {
            var apiValidation = new MessageResponse();

            var cache = InvalidDnaCacheRapper.Instance;

            if (cache.IsInDnaInvalidCache(request.Dna.ToList().GetDeterministicHashCode()))
            {
                apiValidation.Success = false;
                apiValidation.Message = "ADN INVALIDO";
                return(apiValidation);
            }
            else
            {
                //NORMALIZACION DE DNAS
                var upperDna = DnaHelper.UpperDna(request.Dna.ToList());
                request.Dna = upperDna;


                //VALIDACION DE DNAS
                apiValidation = DnaValidator.ValidateDna(upperDna);

                if (apiValidation.Success == false)
                {
                    cache.AddToDnaInvalidCAche(request);
                }

                return(apiValidation);
            }
        }
示例#2
0
        public bool IsMutant(List <string> dnas)
        {
            dnas = DnaHelper.UpperDna(dnas);

            var muttantPatterns = new List <string>();
            var verticalDnas    = new List <string>();
            var diagonalDnas    = new List <string>();


            Parallel.Invoke(() => {
                muttantPatterns = GetMutantsPatternsToCompare();
            },
                            () => {
                verticalDnas = DnaHelper.GetVerticalDnas(dnas);
            },
                            () => {
                diagonalDnas = DnaHelper.GetDiagonalDnas(dnas);
            }
                            );


            int countRepeatedLetters = 0;

            //CON DETECTAR 2 O + REPETICIONES CANCELAMOS LA BÚSQUEDA DE LOS PATRONES
            for (int i = 0; i < muttantPatterns.Count && countRepeatedLetters < 2; i++)
            {
                var pattern = muttantPatterns[i];

                //ANALISIS EN HORIZONTAL DE LA MATRIZ
                countRepeatedLetters += dnas
                                        .Select(s => Regex.Matches(s, Regex.Escape(pattern)).Count)
                                        .Sum();


                if (countRepeatedLetters < 2)
                {
                    //ANALISIS EN VERTICAL DE LA MATRIZ
                    countRepeatedLetters += verticalDnas
                                            .Select(s => Regex.Matches(s, Regex.Escape(pattern)).Count)
                                            .Sum();
                }

                if (countRepeatedLetters < 2)
                {
                    //ANALISIS DE LAS DIAGONALES DE LA MATRIX
                    countRepeatedLetters += diagonalDnas
                                            .Select(s => Regex.Matches(s, Regex.Escape(pattern)).Count)
                                            .Sum();
                }
            }
            return(countRepeatedLetters > 1);
        }