aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-04-04 18:47:54 +0900
committernsfisis <nsfisis@gmail.com>2022-04-04 18:47:54 +0900
commit9980726569d4be51d654f31f2f9633235c9a658b (patch)
tree54ed5d21536d278cc4a24d4fdde90d28cfeafbe3
parent95159488d61626cab53ffd19edbfe54cc592a2e9 (diff)
downloadPHPerKaigi2022-tokens-9980726569d4be51d654f31f2f9633235c9a658b.tar.gz
PHPerKaigi2022-tokens-9980726569d4be51d654f31f2f9633235c9a658b.tar.zst
PHPerKaigi2022-tokens-9980726569d4be51d654f31f2f9633235c9a658b.zip
Beautify toquine.php
-rw-r--r--toquine.php32
1 files changed, 12 insertions, 20 deletions
diff --git a/toquine.php b/toquine.php
index 44629c2..d046d38 100644
--- a/toquine.php
+++ b/toquine.php
@@ -4,12 +4,6 @@
// This is a quine-like program to generate a PHPer token.
// Execute it like this: php toquine.php | php | php | php | ...
-
-
-
-
-
-
$s = <<<'EOS'
<?php
@@ -17,24 +11,22 @@ $s = <<<'EOS'
// This is a quine-like program to generate a PHPer token.
// Execute it like this: php toquine.php | php | php | php | ...
-%s
-
-$s = %s;
+%s$s = %s;
$xs = [
%s,
];
-const N = %s; $zs = ['','','','','']; for ($i = 0; $i < N; ++$i) foreach ($zs as $j => &$z)
-$z .= ' ' . substr(str_replace(['0','1'], [' ','#'], sprintf(chr(37) . '025b', $xs[$i])), 5*$j, 5);
-$ws = array_map(fn($w) => implode(', ', $w),array_chunk(array_map(fn($x) => sprintf('0x' . chr(37) . '07X', $x), $xs), 10));
-printf($s, implode("\n", $zs), "<<<'EOS'\n{$s}\nEOS", implode(",\n", $ws), [1,N+1][N<26]);
+$t = null.false; for ($i = 0; $i <= intdiv(__LINE__-035,6); ++$i) if (!isset($xs[$i])) break; else
+$t .= implode("\n", str_split(str_replace(['0','1'], [' ','##'], sprintf(chr(37) . '025b', $xs[$i])), 012)) . "\n\n";
+$ws = array_map(fn($w) => implode(', ', $w), array_chunk(array_map(fn($x) => sprintf('0x' . chr(37) . '07X', $x), $xs), 10));
+printf($s, $t, "<<<'EOS'\n{$s}\nEOS", implode(",\n", $ws));
EOS;
$xs = [
-0x0AFABEA, 0x1F8FE10, 0x118FE31, 0x1F8FE10, 0x0020080, 0x118FE31, 0x1151084, 0x1F8FE10, 0x1F87E1F, 0x1F8FE51,
-0x1F21084, 0x1F87E1F, 0x1151151, 0x1F21084, 0x1F8FE10, 0x1F8FE51, 0x1F87E1F, 0x1F8FE10, 0x1F8FE51, 0x1F8C63F,
-0x1F8421F, 0x1F87E1F, 0x1F87C3F, 0x1F87C3F, 0x1F8C63F, 0x1F8FE51,
+0x0AFABEA, 0x1F294A7, 0x1F2109F, 0x1F294A7, 0x0002800, 0x1F2109F, 0x0117041, 0x1F294A7, 0x1FAD6B5, 0x1F295B7,
+0x010FC21, 0x1FAD6B5, 0x1151151, 0x010FC21, 0x1F294A7, 0x1F295B7, 0x1FAD6B5, 0x1F294A7, 0x1F295B7, 0x1F8C63F,
+0x1F8C631, 0x1FAD6B5, 0x17AD6BD, 0x17AD6BD, 0x1F8C63F, 0x1F295B7,
];
-const N = 1; $zs = ['','','','','']; for ($i = 0; $i < N; ++$i) foreach ($zs as $j => &$z)
-$z .= ' ' . substr(str_replace(['0','1'], [' ','#'], sprintf(chr(37) . '025b', $xs[$i])), 5*$j, 5);
-$ws = array_map(fn($w) => implode(', ', $w),array_chunk(array_map(fn($x) => sprintf('0x' . chr(37) . '07X', $x), $xs), 10));
-printf($s, implode("\n", $zs), "<<<'EOS'\n{$s}\nEOS", implode(",\n", $ws), [1,N+1][N<26]);
+$t = null.false; for ($i = 0; $i <= intdiv(__LINE__-035,6); ++$i) if (!isset($xs[$i])) break; else
+$t .= implode("\n", str_split(str_replace(['0','1'], [' ','##'], sprintf(chr(37) . '025b', $xs[$i])), 012)) . "\n\n";
+$ws = array_map(fn($w) => implode(', ', $w), array_chunk(array_map(fn($x) => sprintf('0x' . chr(37) . '07X', $x), $xs), 10));
+printf($s, $t, "<<<'EOS'\n{$s}\nEOS", implode(",\n", $ws));