Example #1
0
def run(args):
    assert_correct_input(args)
    target = int(args[0]) + 1 # we don't count 1 as a prime in this problem

    num = 1
    one_percent = target / 100
    for prime in generate_primes():
        if num == target:
            solution = prime
            break

        # Let's print some percentages while we wait
        if num % one_percent == 0:
            percentage = float(num) / float(target) * 100.0
            print "%d%%" % percentage
        num += 1

    print "Solution:", solution
Example #2
0
def run(args):
    assert_usage(args)
    max_number = int(args[0])
    total = 0
    print "Started"
    single_percent = max_number / 100
    prev_percentage = 0
    for prime in generate_primes():
        if prime == 1:
            continue  # we don't consider 1 a prime in this problem

        percentage = prime / single_percent
        if percentage > prev_percentage:
            print "%d%%" % percentage
        prev_percentage = percentage

        if prime >= max_number:
            break
        total += prime

    print "Solution:", total