Skip to main content
deleted 5 characters in body
Source Link
lll
  • 261
  • 1
  • 8
// 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'; // 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( // Assignment inside the condition, a single character from input. false !== ord($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) ); 
// 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'; // 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( // Assignment inside the condition, a single character from input. false !== $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) ); 
// 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'; // 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( // Assignment inside the condition, a single character from input. ord($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) ); 
Generates an error but doesn't affect output.
Source Link
lll
  • 261
  • 1
  • 8

PHP, 165158 chars

for($i=52,$x='shdcKQJT98765432A';$i--;$c[]=$x[4+$i%13].$x[$i/13]); while(is_numericord($i=fgetc(STDIN)))$c[$i]^=$c[$a]^=$c[$i]^=$c[$a=2+($a+++$i)%50]; die(join(' ',$c)); 
// 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'; // 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.   false !== $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) ); 

There are two expected errors, that do not affect the output of the program.

The first is because $a is not initialised, but the NULL is converted to 0 and the program continues.

The second is because the character stream seems to get a newline from somewhere, even if it's not supplied (good ol' PHP), and that is an undefined index in the array. It's the last character of input, and does not affect output.

PHP, 165 chars

for($i=52,$x='shdcKQJT98765432A';$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)); 
// 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'; // 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) ); 

PHP, 158 chars

for($i=52,$x='shdcKQJT98765432A';$i--;$c[]=$x[4+$i%13].$x[$i/13]); while(ord($i=fgetc(STDIN)))$c[$i]^=$c[$a]^=$c[$i]^=$c[$a=2+($a+++$i)%50]; die(join(' ',$c)); 
// 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'; // 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( // Assignment inside the condition, a single character from input. false !== $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) ); 

There are two expected errors, that do not affect the output of the program.

The first is because $a is not initialised, but the NULL is converted to 0 and the program continues.

The second is because the character stream seems to get a newline from somewhere, even if it's not supplied (good ol' PHP), and that is an undefined index in the array. It's the last character of input, and does not affect output.

Removed initialisation of $a - remnant from earlier code - Thanks @DaveRandom
Source Link
lll
  • 261
  • 1
  • 8

PHP, 170165 chars

for($i=52,$x='shdcKQJT98765432A',$a=0;$i$x='shdcKQJT98765432A';$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)); 
// 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;'shdcKQJT98765432A'; // 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) ); 

PHP, 170 chars

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)); 
// 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) ); 

PHP, 165 chars

for($i=52,$x='shdcKQJT98765432A';$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)); 
// 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'; // 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) ); 
Source Link
lll
  • 261
  • 1
  • 8
Loading