Exemplo n.º 1
0
        public Response Decompose(string number)
        {
            if (number.IsInt())
            {
                int        temp          = int.Parse(number);
                List <int> decomposition = new List <int>();
                while (temp != 1)
                {
                    temp /= 2;
                    decomposition.Add(2);
                }

                NumberResponse response = new NumberResponse();
                response.number        = int.Parse(number);
                response.decomposition = decomposition;

                return(response);
            }
            else
            {
                ErrorResponse response = new ErrorResponse();
                response.number = number;
                response.error  = "not a number";

                return(response);
            }
        }
Exemplo n.º 2
0
        public Response Decompose(string number)
        {
            if (number.IsInt())
            {
                int temp = int.Parse(number);
                List<int> decomposition = new List<int>();
                while (temp != 1)
                {
                    temp /= 2;
                    decomposition.Add(2);
                }

                NumberResponse response = new NumberResponse();
                response.number = int.Parse(number);
                response.decomposition = decomposition;

                return response;
            }
            else
            {
                ErrorResponse response = new ErrorResponse();
                response.number = number;
                response.error = "not a number";

                return response;
            }
        }
Exemplo n.º 3
0
        public Response Decompose(string number)
        {
            if (number.IsInt())
            {
                int temp = int.Parse(number);

                if (temp <= 1000000 && temp >= 0)
                {
                    List <int>   factors = new List <int>();
                    PrimeNumbers primes  = new PrimeNumbers();
                    foreach (int prime in primes)
                    {
                        while (temp % prime == 0)
                        {
                            temp /= prime;
                            factors.Add(prime);
                        }

                        if (temp == 1)
                        {
                            break;
                        }
                    }

                    NumberResponse response = new NumberResponse();
                    response.number        = int.Parse(number);
                    response.decomposition = factors;

                    return(response);
                }
                else
                {
                    if (temp >= 0)
                    {
                        BigNumberResponse response = new BigNumberResponse();
                        response.number = temp;
                        response.error  = "too big number (>1e6)";

                        return(response);
                    }
                    else
                    {
                        ErrorResponse response = new ErrorResponse();
                        response.number = number;
                        response.error  = number + " is not an integer > 1";

                        return(response);
                    }
                }
            }
            else
            {
                ErrorResponse response = new ErrorResponse();
                response.number = number;
                response.error  = "not a number";

                return(response);
            }
        }
 public void ThisModel()
 {
     PrimeFactorsModel model = new PrimeFactorsModel();
     response = (NumberResponse)model.Decompose("16");
 }