Advertisement
Guest User

Untitled

a guest
Mar 8th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.39 KB | None | 0 0
  1. def my_collect
  2.   t = (286..100000).collect{|i| i*(i+1)/2   }
  3.   p = (166..100000).collect{|i| i*(3*i-1)/2 }
  4.   h = (144..100000).collect{|i| i*(2*i-1)   }
  5.   res=(t&p&h).first
  6.   puts res
  7. end
  8.  
  9. def my_each
  10.   p=h=t=[]
  11.   (144..100000).each{|i|
  12.     t.push( i*(i+1)/2   ) if i>285
  13.     p.push( i*(3*i-1)/2 ) if i>165
  14.     h.push( i*(2*i-1)   ) if i>144
  15.   }
  16.   res=(t&p&h).first
  17.   puts res
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement