예제 #1
0
    def test_dynamic_prog(self):
        """Tests the dynamic_prog function in module invariant_python
            which returns the no of iterations to reach 6174 for a given
            number. It should have value 5 for number 1112
        """

        no_of_iterations = dynamic_prog(1112)
        self.assertEqual(no_of_iterations, 5)
예제 #2
0
def main_method(number_list):
    
    #checking if all numbers are 4 digit numbers
    if max(number_list) > 9999 or min(number_list) < 1000:
        raise ValueError, "all numbers are not 4 digit numbers"
    
    #dictionary to hold (Iterations:Total count of numbers)
    iter_dict = {}
    
    for number in number_list:
        if number % 1111 != 0 and number!=6174:
            no_of_iter = dynamic_prog(number)
            # putting it into a dictionary
            iter_dict[no_of_iter] = iter_dict.get(no_of_iter,0) + 1

    # when the number is 6174 ,the no of iterations is zero
    iter_dict[0] = 1
    return iter_dict