diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-04-03 11:17:19 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-04-03 11:17:19 +0900 |
| commit | b4cb8d084cfa177087a1a72fcd2c6141d99003ee (patch) | |
| tree | f492c5ca8a081be762e3471120716bb0513306d6 | |
| parent | ddd7d4f8c77b180d2bc882376ea9fc191cb043d7 (diff) | |
| download | PHPerKaigi2022-tokens-b4cb8d084cfa177087a1a72fcd2c6141d99003ee.tar.gz PHPerKaigi2022-tokens-b4cb8d084cfa177087a1a72fcd2c6141d99003ee.tar.zst PHPerKaigi2022-tokens-b4cb8d084cfa177087a1a72fcd2c6141d99003ee.zip | |
Add toquine.php
| -rw-r--r-- | toquine.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/toquine.php b/toquine.php new file mode 100644 index 0000000..a72022c --- /dev/null +++ b/toquine.php @@ -0,0 +1,38 @@ +<?php + +// This is a quine-line program to generate a PHPer token. +// Execute it like this: php toquine.php | php | php | php | ... + + + + + + + +$s = <<<'EOS' +<?php + +// This is a quine-line program to generate a PHPer token. +// Execute it like this: php toquine.php | php | php | php | ... + +%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]); + +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, +]; +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]); |
