# Euler Project Problem 1

**URL:** <https://www.ruby-forum.com/t/euler-project-problem-1/207847>\
**Category:** Ruby\
**Created:** [June 4, 2011, 5:52am UTC](https://www.ruby-forum.com/t/euler-project-problem-1/207847 "2011-06-04T05:52:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 4, 2011, 5:52am UTC](https://www.ruby-forum.com/t/euler-project-problem-1/207847/1 "2011-06-04T05:52:39Z")

</div>

Hi All,

I’m working on solving the first problem on [ProjectEuler.net](http://ProjectEuler.net) and I just  
can’t seem to figure out why the following code doesn’t output the  
correct answer. I’ve found other solutions, but I want to make mine  
work rather than copy someone else’s. Any ideas?

Here’s the problem: 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.

And my (wrong) solution:

c = 0  
d = 0

c.step(999, 3) { |number| c += number }

d.step(999, 5) { |number| d += number }

puts (c + d)

Thanks,  
Ryan

---

<div class="post-metadata">

**Author:** ![mindel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@mindel](https://www.ruby-forum.com/u/mindel)\
**Post date:** [June 4, 2011, 7:28am UTC](https://www.ruby-forum.com/t/euler-project-problem-1/207847/2 "2011-06-04T07:28:42Z")

</div>

There are lot of numbers that are divisible by both 5 and 3, and in your  
sulution you add each of them twice (first as divisible by 3, second as  
divisible by 5).

---

<div class="post-metadata">

**Author:** ![mindel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@mindel](https://www.ruby-forum.com/u/mindel)\
**Post date:** [June 4, 2011, 6:10pm UTC](https://www.ruby-forum.com/t/euler-project-problem-1/207847/3 "2011-06-04T18:10:38Z")

</div>

That was it! Can’t believe I missed it, but thank you for pointing it  
out.

I added an ugly line stepping through in increments of 15 and subtracted  
the result.

Most solutions I’ve seen have been looking for numbers divisible by 3 or  
5 with no remainder, but I wanted to try something different.

Thanks!
