Created
December 4, 2010 03:37
-
-
Save mrjabba/727893 to your computer and use it in GitHub Desktop.
creating a deck of cards and shuffling in 4 lines of Ruby code -> via Dec Ruby issue PragPub -> http://www.pragprog.com/news/pragmatic-programmer-magazine-special-ruby-issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suits = %w{ C D H S } | |
ranks = [ *'2'..'10', *%w{ J Q K A } ] | |
deck = suits | |
.product(ranks) | |
.map(&:join) | |
hands = deck | |
.shuffle | |
.each_slice(13) | |
puts hands.first.join(", ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 2: syntax error, unexpected ',', expecting ']'
ranks = [ *'2'..'10', *%w{ J Q K A } ]
^
Line 2: syntax error, unexpected ']', expecting tCOLON2 or '[' or '.'
ranks = [ *'2'..'10', *%w{ J Q K A } ]
^
Line 4: syntax error, unexpected '.', expecting $end
.product(ranks)
^