source/euler07.rb
def th_prime 
    return false if self < 1
    return 2 if self == 1
    primes = Set.new([2])
    n = 2 
    until primes.length() == self
      n += 1
      prime = false
      primes.each do |p|
        break if n % p == 0
        if p * p > n
          prime = true
          break
        end
      end
      primes << n if prime
    end
    return primes.max
  end
# This is gnarly; there are prettier ways I could've written this, but they
# are much slower.
This is gnarly; there are prettier ways I could've written this, but they
are much slower.
This is gnarly ; there are prettier ways I could ' ve written this but they are much slower .
def th_prime 
    return false if self < 1
    return 2 if self == 1
    primes = Set.new([2])
    n = 2 
    until primes.length() == self
      n += 1
      prime = false
      primes.each do |p|
        break if n % p == 0
        if p * p > n
          prime = true
          break
        end
      end
      primes << n if prime
    end
    return primes.max
  end
def th_prime return false if self < 1 return 2 if self == 1 primes = Set . new ( [ 2 ] ) n = 2 until primes . length ( ) == self n += 1 prime = false primes . each do | p | break if n % p == 0 if p * p > n prime = true break end end primes << n if prime end return primes . max end
This is gnarly; there are prettier ways I could've written this, but they
are much slower.
This is gnarly ; there are prettier ways I could ' ve written this but they are much slower .