Skip to main content
Second improved version added
Source Link
YetiCGN
  • 1.1k
  • 6
  • 9

PHP, 131131 115 bytes

Just a FGITW, maybe I can improve upon it more. Turns out, I can!

First version at 131 bytes:

<?$s=file($argv[1]);foreach($s as$l){$a=str_split(trim($l));echo join(' ',$a).'
';$i=0;while($c=ord($l{$i++}))echo$c.'  ';echo'
';};

The filename is supplied as the first argument after the script name: php aliens.php helloworld.c

Second version at 115 bytes:

function($s){foreach($s as$l){$a=str_split($l);echo join('  ',$a);$i=0;while($c=ord($a[$i++]))echo$c.'  ';echo'
';}};

The first version accounts for missing newlines at the end of the line, but after the additional clarification, we can leave that code out and put everything in a function to save 16 bytes.

The whitespace characters in join(' ',$a) as well as in echo$c.' ' are tab characters = \t. The newlines in the code are on purpose.

The filename is supplied as the first argument after the script name: php aliens.php helloworld.c

PHP, 131 bytes

Just a FGITW, maybe I can improve upon it more.

<?$s=file($argv[1]);foreach($s as$l){$a=str_split(trim($l));echo join(' ',$a).'
';$i=0;while($c=ord($l{$i++}))echo$c.'  ';echo'
';};

The whitespace characters in join(' ',$a) as well as in echo$c.' ' are tab characters = \t. The newlines in the code are on purpose.

The filename is supplied as the first argument after the script name: php aliens.php helloworld.c

PHP, 131 115 bytes

Just a FGITW, maybe I can improve upon it more. Turns out, I can!

First version at 131 bytes:

<?$s=file($argv[1]);foreach($s as$l){$a=str_split(trim($l));echo join(' ',$a).'
';$i=0;while($c=ord($l{$i++}))echo$c.'  ';echo'
';};

The filename is supplied as the first argument after the script name: php aliens.php helloworld.c

Second version at 115 bytes:

function($s){foreach($s as$l){$a=str_split($l);echo join('  ',$a);$i=0;while($c=ord($a[$i++]))echo$c.'  ';echo'
';}};

The first version accounts for missing newlines at the end of the line, but after the additional clarification, we can leave that code out and put everything in a function to save 16 bytes.

The whitespace characters in join(' ',$a) as well as in echo$c.' ' are tab characters = \t. The newlines in the code are on purpose.

Source Link
YetiCGN
  • 1.1k
  • 6
  • 9

PHP, 131 bytes

Just a FGITW, maybe I can improve upon it more.

<?$s=file($argv[1]);foreach($s as$l){$a=str_split(trim($l));echo join(' ',$a).'
';$i=0;while($c=ord($l{$i++}))echo$c.'  ';echo'
';};

The whitespace characters in join(' ',$a) as well as in echo$c.' ' are tab characters = \t. The newlines in the code are on purpose.

The filename is supplied as the first argument after the script name: php aliens.php helloworld.c