dawmail333

Ruby Comparison #1

Apr 21st, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.28 KB | None | 0 0
  1. numbers = []
  2. for i in 1..999 do
  3.     if i % 3 == 0 or i % 5 == 0
  4.         numbers << i
  5.     end
  6. end
  7. print numbers.inject{|sum,x| sum + x }
  8. print "\r\n" #Linebreak because of the next test
  9.  
  10. #Advanced version of the above:
  11. 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