Skip to main content
1 of 4
lll
  • 261
  • 1
  • 8

PHP, 170 chars

Newlines have been added to stop the code block gaining scrollbars, they can safely be removed.

for($i=52,$x='shdcKQJT98765432A',$a=0;$i--;$c[]=$x[4+$i%13].$x[$i/13]); while(is_numeric($i=fgetc(STDIN)))$c[$i]^=$c[$a]^=$c[$i]^=$c[$a=2+($a+++$i)%50]; die(join(' ',$c)); 

Before I get told to add a <?php, let it be known you can invoke PHP without this tag quite easily, using: cat golf.php | php -a

De-golfed and commented:

// Abuse of the for construct to save a bit of space, and to make things more obscure looking in general. for ( // Card suit and number are reversed because we're using a decrementor to count // down from 52, instead of up to 52 $i = 52, $x = 'shdcKQJT98765432A', $a = 0; // Condition AND per-loop decrement $i--; // Add a new element to the array comprising of $i mod 13 + 4 (to skip suit ids) // followed by simply $i divided by 13 to pick a suit id. $c[] = $x[4 + $i % 13] . $x[$i / 13] ); while( // It seems fgetc will return an additional newline at the end of input. Not sure why // This is needed instead of the shorter "false!==" is_numeric( // Assignment inside the condition, a single character from input. $i = fgetc(STDIN) ) ) // In-place swap. Shorter than using a single letter temporary variable. // This is the pseudo-random shuffle. $c[$i] ^= $c[$a] ^= $c[$i] ^= $c[ // We use the input (0 or 1) to identify one of two swap locations at the // start of the array. The input is also added to an accumulator (to make // the increments "random") that represents a swap destination. $a = 2 + ($a++ + $i) % 50 ]; // Dramatic way of doing "echo" in the same space. die( join(' ', $c) ); 
lll
  • 261
  • 1
  • 8