コード例 #1
0
 def filter_prime(self):
     """
         Eliminates all numbers that are not prime from the sequence
         Returns:
             A sequence containing all prime numbers of the sequence
     """
     result_sequence = []
     for i in range(0, len(self.sequence_store.sequence)):
         if(isPrime(self.sequence_store.sequence[i])):
             result_sequence.append(self.sequence_store.sequence[i])
     if(len(result_sequence) != len(self.sequence_store.sequence)):
         self.sequence_store.sequence = deepcopy(result_sequence)
         self._save_sequence()
     return result_sequence
コード例 #2
0
 def display_prime(self, index_start = -1, index_end = -1):
     """
         Prints a list containing all prime numbers in the given subsequence
         Input:
             index_start - The starting index
             index_end - The ending index
         Returns:
             A list of all prime numbers between the given indexes
         Raises IndexError if any of the indexes are invalid
     """
     result_list = []
     Validator.validate_index(self.sequence_store.sequence, index_start, index_end)
     for i in range(index_start, index_end + 1):
         if(isPrime(self.sequence_store.sequence[i])):
             result_list.append(self.sequence_store.sequence[i])
     return result_list