Skip to content

Instantly share code, notes, and snippets.

@zaz
Forked from thatrubylove/example-1.rb
Last active August 29, 2015 14:07
Show Gist options
  • Save zaz/826255d0b871d5809215 to your computer and use it in GitHub Desktop.
Save zaz/826255d0b871d5809215 to your computer and use it in GitHub Desktop.
numbers = [1,3,5,8,10,54,99]
cards = [5,3,4,6,2]
# get only the values where the distance is greater than 10
numbers.each_cons(2).select {|a,b| b-a>10 } #=> [[10, 54], [54, 99]]
# determine if the hand is a straight
cards.sort.each_cons(5).all? do |series|
series.last - series.first == 4
end #=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment