Forgetful me

According to Kurzweil, the singularity (the moment when we will start to invent things instantaneously) will occur in 2045. According to me the singularity (the moment when I forget things fast than I can learn things) occurs in 2009.

Every time I start over with Ruby (or XSLT or …) I find that I have forgotten the most basic things (like how to construct an object).

Anyway, thanks to Project Euler (according to which, I am 4% genius), I had an excuse to go go back and learn Ruby all over again.

Here’s my prime number generator (which is about a third of the size of my Java version):

class Primes
  def initialize
    @primes = []
    @next_candidate = 2

  def prime? number
    root = Math.sqrt number
    find_primes_less_than root

    @primes.each do |prime|
      return true if prime > root
      return false if number % prime == 0

  def find_primes_less_than limit
    until @next_candidate > limit
      @primes << @next_candidate if prime? @next_candidate
      @next_candidate += 1

  def [] index
    until @primes.size > index
      find_primes_less_than @next_candidate + 100
    return @primes[index]

The answer to problem #7 is @primes[10000], in case you were wondering.

Published by

Ragged Clown

Based in San Jose, California

One thought on “Forgetful me”

Leave a Reply

Your email address will not be published. Required fields are marked *