Skip to content

Instantly share code, notes, and snippets.

@ender672
Created April 24, 2009 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ender672/101276 to your computer and use it in GitHub Desktop.
Save ender672/101276 to your computer and use it in GitHub Desktop.
irb(main):001:0> a = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb(main):002:0> a.each_with_index{|elem, index| a[index..a.size].each{|second_elem| p "#{elem}, #{second_elem}"}}
"1, 1"
"1, 2"
"1, 3"
"1, 4"
"1, 5"
"2, 2"
"2, 3"
"2, 4"
"2, 5"
"3, 3"
"3, 4"
"3, 5"
"4, 4"
"4, 5"
"5, 5"
=> [1, 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment