Solving Algorithms – Largest prime factor

Today I solved this algorithm that is the third problem in Project Euler.
This still need some improvement, because even when the last prime number is found it still counts and takes a really long time when given big numbers.

require 'prime'

def largestPrime(num)
  result = 0
  (2...num).each do |i|
    result = i if (num % i) == 0 && i.prime?
  end
  puts result
end

largestPrime(13195)

I will update this code as soon as I find a better solution but for now it works.

Back on Track

Well I have been on and off programming after leaving College.
This was rekindled after seeing my girlfriend in late 2015 doing a SQL tutorial in Khan’s Academy, which I completed in a few days.
Then restarted LPTHW book, but changed to LRTHW which I began in late in 2014 and never went back to it. I am currently in the 48th exercise and having a hard time with it. This exercise is about building a code to pass an Automated Testing done by the author named Zed A. Shaw. It is so far the hardest for me besides the one with dictionaries that made me quit twice. If I only had opened the terminal and wrote the code in a shell that wall of fire could be overcome easily.
Just to say that pushing through the exercises is making me tougher and ready to conquer the Software Development Industry in the long run. Gotta be bold!

Perhaps it’s good for today and will return tomorrow with full force.