Given an arbitrarily large file containing integers, return the largest N numbers, highest first
Consider remembering the n largest numbers:

def top_n(filename, n = 100)
    require 'set'

    topn = SortedSet.new()

    File.foreach(filename) do |line|
        num = line.to_i
        if topn.length &lt; n
            topn.add(num)
        elsif num &gt; topn.first
            topn.delete(topn.first)
            topn.add(num)
        end
    end
    return topn.to_a
end