def print_results(self): result_counter = 0 number = 1 while number < Primes.SIEVE_SIZE: if self.sieve[number] == 0: result_counter = columns.print_column(Primes.COLUMNS, Primes.RESULT_FORMAT, number, result_counter) number += 1 columns.finish_column(Primes.COLUMNS, result_counter) sys.stdout.write("%d prime numbers\n" % (result_counter))
def factorials(): factor = 1 result_counter = 0 result = 1 while LIMIT / result > factor: result *= factor result_counter = columns.print_column(COLUMNS, RESULT_FORMAT, result, result_counter) factor += 1 columns.finish_column(COLUMNS, result_counter)
def powers(factor): sys.stdout.write("Powers of %d:\n" % (factor)) number = factor max = LIMIT / factor sys.stdout.write(RESULT_FORMAT % (factor)) result_counter = 1 while number <= max: number *= factor result_counter = columns.print_column(COLUMNS, RESULT_FORMAT, number, result_counter) columns.finish_column(COLUMNS, result_counter)
def fibonacci(): fibo_index = 0 current = 1 previous = 0 while LIMIT - previous >= current: (current, previous) = ( (fibo_index, 0) if fibo_index < 2 else (current + previous, current) ) fibo_index = columns.print_column(COLUMNS, RESULT_FORMAT, current, fibo_index) columns.finish_column(COLUMNS, fibo_index)