diff options
Diffstat (limited to 'vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html')
| -rw-r--r-- | vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html b/vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html index 1f7ad6ba..ed87f02e 100644 --- a/vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html +++ b/vhosts/blog/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html @@ -14,8 +14,7 @@ <meta property="og:locale" content="ja_JP"> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHP カンファレンス沖縄で出題されたコードゴルフの問題を解いてみた|REPL: Rest-Eat-Program Loop</title> - <link rel="stylesheet" href="/style.css?h=79020a898c7052f79b32e90376a4497d"> - <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> + <link rel="stylesheet" href="/style.css?h=60eb349e583f5bd51518a7eb98598043"> </head> <body class="single"> <header class="header"> @@ -121,7 +120,9 @@ 書いたものがこちら: </p> - <pre class="highlight" language="php"><code class="highlight">[<span class="hljs-meta"><?php</span> <span class="hljs-variable">$n</span>=<span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>];<span class="hljs-keyword">foreach</span>([<span class="hljs-number">1e4</span>,<span class="hljs-number">5e3</span>,<span class="hljs-number">2e3</span>,<span class="hljs-number">1e3</span>,<span class="hljs-number">500</span>,<span class="hljs-number">100</span>,<span class="hljs-number">50</span>,<span class="hljs-number">10</span>,<span class="hljs-number">5</span>,<span class="hljs-number">1</span>]<span class="hljs-keyword">as</span><span class="hljs-variable">$x</span>)<span class="hljs-keyword">for</span>(;<span class="hljs-variable">$n</span>>=<span class="hljs-variable">$x</span>;<span class="hljs-variable">$n</span>-=<span class="hljs-variable">$x</span>)<span class="hljs-variable">$r</span>[]=<span class="hljs-variable">$x</span>;<span class="hljs-keyword">echo</span> <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">', '</span>,<span class="hljs-variable">$r</span>??[]);<span class="hljs-meta">?></span>]</code></pre> + <div class="codeblock" language="php"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#24292E">[</span><span style="color:#D73A49"><?</span><span style="color:#005CC5">php</span><span style="color:#24292E"> $n</span><span style="color:#D73A49">=</span><span style="color:#24292E">$argv[</span><span style="color:#005CC5">1</span><span style="color:#24292E">];</span><span style="color:#D73A49">foreach</span><span style="color:#24292E">([</span><span style="color:#005CC5">1e4</span><span style="color:#24292E">,</span><span style="color:#005CC5">5e3</span><span style="color:#24292E">,</span><span style="color:#005CC5">2e3</span><span style="color:#24292E">,</span><span style="color:#005CC5">1e3</span><span style="color:#24292E">,</span><span style="color:#005CC5">500</span><span style="color:#24292E">,</span><span style="color:#005CC5">100</span><span style="color:#24292E">,</span><span style="color:#005CC5">50</span><span style="color:#24292E">,</span><span style="color:#005CC5">10</span><span style="color:#24292E">,</span><span style="color:#005CC5">5</span><span style="color:#24292E">,</span><span style="color:#005CC5">1</span><span style="color:#24292E">]</span><span style="color:#D73A49">as</span><span style="color:#24292E">$x)</span><span style="color:#D73A49">for</span><span style="color:#24292E">(;$n</span><span style="color:#D73A49">>=</span><span style="color:#24292E">$x;$n</span><span style="color:#D73A49">-=</span><span style="color:#24292E">$x)$r[]</span><span style="color:#D73A49">=</span><span style="color:#24292E">$x;</span><span style="color:#005CC5">echo</span><span style="color:#005CC5"> implode</span><span style="color:#24292E">(</span><span style="color:#032F62">', '</span><span style="color:#24292E">,$r</span><span style="color:#D73A49">??</span><span style="color:#24292E">[]);</span><span style="color:#D73A49">?></span><span style="color:#24292E">]</span></span></code></pre> + </div> <p> しめて 123 バイトとなった (末尾改行を含めずにカウント)。 @@ -131,15 +132,17 @@ こちらは改行とスペースを追加したバージョン: </p> - <pre class="highlight" language="php"><code class="highlight">[<span class="hljs-meta"><?php</span> - -<span class="hljs-variable">$n</span> = <span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>]; -<span class="hljs-keyword">foreach</span> ([<span class="hljs-number">1e4</span>, <span class="hljs-number">5e3</span>, <span class="hljs-number">2e3</span>, <span class="hljs-number">1e3</span>, <span class="hljs-number">500</span>, <span class="hljs-number">100</span>, <span class="hljs-number">50</span>, <span class="hljs-number">10</span>, <span class="hljs-number">5</span>, <span class="hljs-number">1</span>] <span class="hljs-keyword">as</span> <span class="hljs-variable">$x</span>) - <span class="hljs-keyword">for</span> (; <span class="hljs-variable">$n</span> >= <span class="hljs-variable">$x</span>; <span class="hljs-variable">$n</span> -= <span class="hljs-variable">$x</span>) - <span class="hljs-variable">$r</span>[] = <span class="hljs-variable">$x</span>; -<span class="hljs-keyword">echo</span> <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">', '</span>, <span class="hljs-variable">$r</span> ?? []); - -<span class="hljs-meta">?></span>]</code></pre> + <div class="codeblock" language="php"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#24292E">[</span><span style="color:#D73A49"><?</span><span style="color:#005CC5">php</span></span> +<span class="line"></span> +<span class="line"><span style="color:#24292E">$n </span><span style="color:#D73A49">=</span><span style="color:#24292E"> $argv[</span><span style="color:#005CC5">1</span><span style="color:#24292E">];</span></span> +<span class="line"><span style="color:#D73A49">foreach</span><span style="color:#24292E"> ([</span><span style="color:#005CC5">1e4</span><span style="color:#24292E">, </span><span style="color:#005CC5">5e3</span><span style="color:#24292E">, </span><span style="color:#005CC5">2e3</span><span style="color:#24292E">, </span><span style="color:#005CC5">1e3</span><span style="color:#24292E">, </span><span style="color:#005CC5">500</span><span style="color:#24292E">, </span><span style="color:#005CC5">100</span><span style="color:#24292E">, </span><span style="color:#005CC5">50</span><span style="color:#24292E">, </span><span style="color:#005CC5">10</span><span style="color:#24292E">, </span><span style="color:#005CC5">5</span><span style="color:#24292E">, </span><span style="color:#005CC5">1</span><span style="color:#24292E">] </span><span style="color:#D73A49">as</span><span style="color:#24292E"> $x)</span></span> +<span class="line"><span style="color:#D73A49"> for</span><span style="color:#24292E"> (; $n </span><span style="color:#D73A49">>=</span><span style="color:#24292E"> $x; $n </span><span style="color:#D73A49">-=</span><span style="color:#24292E"> $x)</span></span> +<span class="line"><span style="color:#24292E"> $r[] </span><span style="color:#D73A49">=</span><span style="color:#24292E"> $x;</span></span> +<span class="line"><span style="color:#005CC5">echo</span><span style="color:#005CC5"> implode</span><span style="color:#24292E">(</span><span style="color:#032F62">', '</span><span style="color:#24292E">, $r </span><span style="color:#D73A49">??</span><span style="color:#24292E"> []);</span></span> +<span class="line"></span> +<span class="line"><span style="color:#D73A49">?></span><span style="color:#24292E">]</span></span></code></pre> + </div> </section> <section id="section--techniques"> |
