Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Last active December 11, 2015 18:58
Show Gist options
  • Save fumokmm/4645296 to your computer and use it in GitHub Desktop.
Save fumokmm/4645296 to your computer and use it in GitHub Desktop.
String[] deal(int numPlayers, String deck) {
deck.toList().collate(numPlayers, false)
.transpose()*.join() ?: [''] * numPlayers
}
assert deal(3, '123123123') == ['111', '222', '333'] as String[]
assert deal(4, '123123123') == ['12', '23', '31', '12'] as String[]
assert deal(6, '012345012345012345') == ['000', '111', '222', '333', '444', '555'] as String[]
assert deal(4, '111122223333') == ['123', '123', '123', '123'] as String[]
assert deal(1, '012345012345012345') == ['012345012345012345'] as String[]
assert deal(6, '01234') == ['', '', '', '', '', ''] as String[]
assert deal(2, '') == ['', ''] as String[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment