aboutsummaryrefslogtreecommitdiffhomepage
path: root/archive/q/brainf-ck/a/6/index.html
blob: d987184545982227f3cff1a73eea3d6ec17aa5ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>問題 #3 - 回答 #6 | Albatross.PHP</title>
    <link rel="stylesheet" href="../../../../assets/index.css">
    <link rel="icon" type="image/svg+xml" href="../../../../assets/favicon.svg">
    <script type="module" src="../../../../assets/index.js"></script>
  </head>
  <body>
    <header class="container">
      <nav class="navbar">
        <a class="navbar-brand" href="../../../../index.html">Albatross.PHP</a>
      </nav>
    </header>
    <main class="container mt-5">
      <h1 class="mb-4">問題 #3 - 回答 #6</h1>
        <nav>
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="../../../../index.html">問題一覧</a></li>
      <li class="breadcrumb-item"><a href="../../index.html">Brainf*ck</a></li>
      <li class="breadcrumb-item"><a href="../index.html">回答一覧</a></li>
      <li class="breadcrumb-item active">#6</li>
    </ol>
  </nav>

  <h2>Brainf*ck</h2>
  <p>
    Brainf*ck を実装してください。標準入力から Brainf*ck のソースコードが渡されます。Brainf*ck の仕様のうち、入力命令である「,」は未実装で構いません。

一部明確に挙動が定められていない部分については、以下の仕様とします。
メモリの各セルは 8 bit の符号なし整数です。今回の入力でオーバーフローは発生しません。
メモリのアドレスは非負整数です。今回の入力で負のアドレスへポインタを動かすことはありません。
Brainf*ck に存在する命令以外の文字を受け取った場合は無視してください。
今回の入力に不正なプログラムは含まれません。すなわち、「[」と「]」は必ず釣り合っています。
  </p>
  <h2>回答 #6</h2>
  <p>
    nsfisis が 2024-03-07 15:37:59 に投稿
  </p>
  <h2>コード</h2>
  <p>
    355 byte
  </p>
  <pre><code class="hljs language-php">$S=stream_get_contents(STDIN);$s=$m=0;while($s&lt;strlen($S))switch($S[$s++]){case&#039;&gt;&#039;:$m++;break;case&#039;&lt;&#039;:$m--;break;case&#039;+&#039;:$M[$m]++;break;
case&#039;-&#039;:$M[$m]--;break;case&#039;.&#039;:echo chr($M[$m]);break;case&#039;[&#039;:if(!($M[$m]??0)){$d=1;while($d)$d+=$S[++$s]==&#039;[&#039;?1:$S[$s]==&#039;]&#039;?-1:0;}break;case&#039;]&#039;:if($M[$m]??0){$d=1;while($d)$d+=$S[--$s]==&#039;]&#039;?1:$S[$s]==&#039;[&#039;?-1:0;}break;}</code></pre>
  <h2>実行結果</h2>
  <div class="js-phper-token">
      </div>
  <div class="mt-3">
    ステータス: <span class="js-aggregated-execution-status" data-answer-id="34">失敗</span>
      </div>
  <div class="mt-3">
          <h3>テストケース 1</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="77">不正解</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="77">
Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in php.wasm code on line 7

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="77">
</code></pre>
          <h3>テストケース 2</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="78">不正解</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="78">
Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in php.wasm code on line 7

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="78">
</code></pre>
          <h3>テストケース 3</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="79">不正解</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="79">
Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in php.wasm code on line 7

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="79">
</code></pre>
      </div>
  <script type="module" src="../../../../assets/loading.js"></script>
    </main>
    <footer class="container text-center mt-5 mb-4">
      Albatross.PHP - PHPerKaigi 2024
    </footer>
  </body>
</html>