I am beginning with Ruby and trying to solve the third problem on the

Euler project. When I run the below code I get the following results:

5

7

13

29

65

145

377

1015

2639

But 65, 145, 377, 1015 and 2639 should not be part of the results since

they are not prime.

For some reason I only seem to be testing these numbers:

5, 7, 13, 29, 35, 91, 203, 455 and 1885 (and that must be why 65, 145,

377, 1015, and 2639 are included in the results). But I can’t figure

out why and been looking at this for too many hours now and I am

stumped.

My code:

composite_number_array = []

composite_array_test = []

first_number = 13195

sr_number = Math.sqrt(first_number).ceil

(2…sr_number).each do

|i|

if (first_number % i == 0)

sr_number_pair = first_number / i

composite_number_array.push(i)

composite_number_array.push(sr_number_pair)

end

end

composite_number_array.uniq!

composite_number_array.sort!

puts composite_number_array

puts “beginning work”

composite_number_array.each do

|z|

composite_array_test.push(z)

last_num = z

(2…last_num).each do

|a|

if last_num % a == 0

composite_number_array.delete(last_num)

end

end

end

puts “the results are”

puts composite_number_array

puts “the test array was”

puts composite_array_test

Does anyone see anything wrong? Can anyone point me in the right

direction?

Thank you!