Find the greatest product of five consecutive digits in the 1000-digit Continue Reading
Ruby Kata 2 – Karate Chop
I like to solve little programming challenges that I find online. Code challenges are a fun way to sharpen your skills and become a better problem solver. It's been around for a while now but I recently discovered Codekata. The first real challenge is Kata Two - Karate Chop. Description below. Click the link below the description to get the full details of the challenge. A binary chop Continue Reading
Project Euler Problem 4 in Ruby
Here I have two solutions for Project Euler problem 4 as well as a method for timing the two solutions. One solution uses a loop and the other uses recursion. # A palindromic number reads the same both ways. # The largest palindrome made from the product of # two 2-digit numbers is 9009 = 91 99. # Find the largest palindrome made from the product of two 3-digit numbers. def Continue Reading
Project Euler Problem 3 in Ruby
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? # if n is 1, end the method and return empty array # set var factor = first number in range 2..n # that has a remainder of 0 when divided by x # x being the current iteration of 2..n # put factor var into an array and then call the # method we are currently in again passing the Continue Reading
Project Euler Problem 1 in Ruby
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. sum, i = 0, 0 while i < 1000 sum += i if i % 3 == 0 || i % 5 == 0 i += 1 end puts sum # => 233168 Please comment with your own solution or let me know how this can be improved. Continue Reading
Project Euler Problem 2 in Ruby
Please comment with your own solution or let me know how this can be improved. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. # Continue Reading
Classes in Ruby Using Getters and Setters
The second week of Code Academy has passed and we've learned a number of new concepts. Instead of basically just bulleting everything we learned I'm going to pick one thing and go a little more in depth with it. In this post I'm going to talk about Classes in Ruby. If you're not familiar with object oriented programming this may or may not confuse you a little but continue reading if you wish, I'm Continue Reading