Skip to content

Instantly share code, notes, and snippets.

@banyan
Created December 17, 2009 13:38
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 banyan/258741 to your computer and use it in GitHub Desktop.
Save banyan/258741 to your computer and use it in GitHub Desktop.
# encoding: utf-8
class Cards
def deal(num_players, deck)
if num_players > deck.scan(/./).size
ary = []
num_players.times do
ary << ""
end
return ary
end
hash = {}
i = 0
deck.scan(/./) do |s|
i += 1
if hash.has_key?(i)
hash[i] = hash[i] + s
else
hash[i] = s
end
if (i % num_players) == 0 then
i = 0
end
end
hash.values
end
end
cards = Cards.new
#ret = cards.deal(3, "012345012345012345")
#ret = cards.deal(1, "012345012345012345")
#ret = cards.deal(6, "01234")
ret = cards.deal(2, "")
#ret = cards.deal(3, "123123123")
p ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment