Project Euler Problem 3

Problem 3, using the mixin i already developed, and showcasing the less traditional end of ruby syntax.

  target = 600851475143
  first = 2
  last = (Math.sqrt(target).ceil) + 1

  last.downto first do |i|
  
    next unless i.factorOf? target    
    next unless i.prime?

    puts "answer is " + i.to_s
    break

  end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s