fork download
  1. # https://g...content-available-to-author-only...b.com/1481377
  2. class Array
  3. def bunch(num)
  4. old = self.clone
  5. new = []
  6. while 1
  7. bunched = []
  8. num.times do
  9. bunched << old.shift
  10. end
  11. new << bunched
  12. break if old.empty?
  13. end
  14. new
  15. end
  16. end
  17.  
  18. [1,2,3,5,6,7].keep_if {|i| i unless 0==i%2 }.bunch(2).each {|i| puts "#{i[0]}-#{i[1]}" }
  19.  
Success #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
1-3
5-7