Just for fun, seeing if anyone can make a block that defines a standard 52 card deck faster than this.
Code php:function createDeck() { $deck = array(); for ($i = 0, $i < 52; $i++) { switch(floor($i / 13)) { case 0: $suit = 'S'; break; case 1: $suit = 'H'; break; case 2: $suit = 'D'; break; case 3: $suit = 'C'; break; } switch($i % 13) { case 0: $pip = 'A'; break; case 12: $pip = 'K'; break; case 11: $pip = 'Q'; break; case 10: $pip = 'J'; break; default: $pip = $i + 1; break; } $deck[$i] = $pip.$suit; } return $deck; }
The challenge is - while keeping it legible, find a solution in fewer lines.
DISCLAIMER - Code above untested.




Reply With Quote



Bookmarks