<commit_before>=begin
                                10001st prime

    By  listing  the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
    that the 6th prime is 13.
    What is the 10 001st prime number?

    note:
    "An  array with 500 million elements is 2 GiBytes in size, which – depending
    on  the  specific OS you are using – is typically the maximum that a process
    can address. In other words: your array is bigger than your address space."
    from: http://stackoverflow.com/questions/3687517/array-size-too-big-ruby/3688388#3688388
=end

def sieve( limit )
    flag = true
    counter = 0
    primes = [ 2 ]

    while flag do
        last = primes.length-1
        puts last
        max = primes[ last ]
        #puts max
        for i in ( 2..max ) do
            ( i+i..max ).step( i ) do | j |
                primes[ j ] = false
            end
        end

        total_primes = primes.inject { | result, element | ( false != element ) ? result + 1 : result + 0 }
        new_primes = total_primes - counter
        counter = counter + new_primes

        #puts counter

        if limit == counter then
            flag = false
        end
    end

    return primes.pop
end

sieve( 10_001 )<commit_msg>Still not done problem 7<commit_after>=begin
                                10001st prime

    By  listing  the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
    that the 6th prime is 13.
    What is the 10 001st prime number?

    note:
    "An  array with 500 million elements is 2 GiBytes in size, which – depending
    on  the  specific OS you are using – is typically the maximum that a process
    can address. In other words: your array is bigger than your address space."
    from: http://stackoverflow.com/questions/3687517/array-size-too-big-ruby/3688388#3688388
=end

def sieve( limit )
    flag = true
    counter = 0
    max_length = 500_000
    numbers = Array.new( max_length ) { | i | i + 1 }
    last = 0

    while flag do
        last = last + 1
        for i in ( 2..last ) do
            ( 2*i..last ).step( i ) do | j |
                numbers[ j ] = -1
            end
        end

        total_primes = numbers.inject { | result, element | ( -1 != element ) ? result + 1 : result + 0 }
        new_primes = total_primes - counter
        counter = counter + new_primes

        puts counter

        if limit == counter then
            flag = false
        end
    end

    return last
end

puts sieve( 10_001 )
{'fraction_non_alphanumeric': 0.0765224358974359, 'fraction_numerical': 0.05008012820512821, 'mean_word_length': 1.75303197353914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1176595', 'n_tokens_mistral': 848, 'n_tokens_neox': 729, 'n_words': 299}