Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- numbers = []
- for i in 1..999 do
- if i % 3 == 0 or i % 5 == 0
- numbers << i
- end
- end
- print numbers.inject{|sum,x| sum + x }
- print "\r\n" #Linebreak because of the next test
- #Advanced version of the above:
- print (1..999).find_all{ |i| i%3==0 or i%5==0 }.inject{|sum,x| sum + x }
Advertisement
Add Comment
Please, Sign In to add comment