Bash, 156
Because using a real "compression library" is forbidden, I'll abuse base64
from coreutils instead. (xxd -r
to decode submission)
0000000: 7461 696c 202d 3120 2430 7c62 6173 6536 tail -1 $0|base6
0000010: 3420 2d77 307c 7472 2058 595a 205c 202c 4 -w0|tr XYZ \ ,
0000020: 2e0a 6578 6974 0a2e 8ade 9978 a9b2 e997 ..exit.....x....
0000030: 7689 68ad 7b22 b576 a67a d617 7289 ec79 v.h.{".v.z..r..y
0000040: cb5e b6e7 ab5d a762 a62b 1c8a 7817 7a58 .^...].b.+..x.zX
0000050: ad61 7b1e 7577 626a 65e7 a27b a69b 25e7 .a{.uwbje..{..%.
0000060: 89b8 577a e8ac 9a87 57b6 29dc 89db a7b5 ..Wz....W.).....
0000070: 7bad 5e56 a8ad e7ad 5dda 25a2 b797 99a8 {.^V....].%.....
0000080: 2769 76a5 8aab 9a99 77ab 6ad5 efa2 5bad 'iv.....w.j...[.
0000090: a5ab 595d 4b57 c22b 225d e9e2 ..Y]KW.+"]..
I generated the above code using this PHP program:
<?php
$lorem = '<text here>';
$enclorem = base64_decode( strtr( $lorem, ' ,.', 'XYZ' ) );
$prog = "tail -\$3 \$0|base64 -w0|tr XYZ \\ ,.\nexit\n$1";
for ( $i = 0, $n = strlen( $lorem ); $i < $n; $i++ ) {
$cutlorem = substr( $lorem, 0, $i );
for ( $j = 0, $o = strlen( $enclorem ); $j < $o; $j++ ) {
$cutenclorem = substr( $enclorem, 0, $j );
if ( substr( strtr( base64_encode( $cutenclorem ), 'XYZ', ' ,.' ), 0, $i ) === $cutlorem ) {
break;
}
}
$out = strtr( $prog, array(
'$1' => $cutenclorem,
'$2' => $i,
'$3' => substr_count( $cutenclorem, "\n" ) + 1,
) );
echo "\$i=$i strlen(\$out)=" . strlen( $out ) . "\n";
if ( $i === strlen( $out ) ) {
break;
}
}
echo "\nHexdump:\n";
$p = popen( 'xxd', 'w' );
fwrite( $p, $out );
pclose( $p );
echo "\nFinal output check: ";
$tmp = tmpfile();
fwrite( $tmp, $out );
$md = stream_get_meta_data( $tmp );
ob_start();
passthru( 'bash ' . escapeshellarg( $md['uri'] ) );
$buf = rtrim( ob_get_clean() );
echo $buf === substr( $lorem, 0, strlen( $out ) ) ? 'PASS' : 'FAIL', "\n$buf\n";
I don't think the lorem ipsum placeholder text is standardized. What if our program is longer than the provided example? Should it simply repeat from the beginning again? – Mr. Llama – 2013-02-25T21:02:40.370
@GigaWatt I provided an 1000+ character long text as link. If that's not enough then repeat. – randomra – 2013-02-25T21:14:14.960
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer nunc augue, feugiat non, egestas ut, rutrum eu, purus. Vestibulum condimentum commodo pede. Nam in metus eu justo commodo posuere. Nunc varius dui id nulla. Fusce porttitor pretium leo. Quisque in diam. Nulla pellentesque. Donec vitae urna et arcu lobortis varius. Aenean velit eros, varius ac, semper sit amet, lacinia eget, sem. Phasellus mollis nunc a pede cursus fermentum. Proin et odio. Nullam turpis. Fusce eget arcu. Mauris placerat ultricies lectus. Nullam pede nisl, ullamcorper ullamcorper, hendrerit sit amet, molestie – DavidC – 2013-02-25T21:17:04.013
2If we're not allowed to use network/language built-ins/compression, how are we supposed to generate information that's at least as long as the program? That's almost like pulling info out of thin air. – Mr. Llama – 2013-02-25T21:40:43.050
1@GigaWatt compression (assuming it doesn't have to be dynamic in length) – copy – 2013-02-25T21:43:16.907
@GigaWat Self made compression would be the desired way. Dynamic length doesn't need. – randomra – 2013-02-25T21:54:51.917
Is it ok to output extra characters, as long as the first n are correct? (n = source size) – aditsu quit because SE is EVIL – 2013-02-26T19:07:58.973
@aditsu No, you can't output extra characters. – randomra – 2013-02-26T20:15:24.780