]> granicus.if.org Git - clang/commitdiff
Since we're counting number of steps, switch to turing machines which maximize
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 May 2013 22:18:32 +0000 (22:18 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 May 2013 22:18:32 +0000 (22:18 +0000)
#steps not #1s, and use a more traditional step count where the 'halt' step is
not counted.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182057 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaCXX/constexpr-turing.cpp

index 07c04eff30839682199f4b00ca34c5bf50237a3a..75aefbf2ab7aafc1d0240c80bb4ee90a3313faae 100644 (file)
@@ -33,24 +33,24 @@ constexpr Tape move(const Tape &old, Dir dir) { return Tape(old, dir); }
 // Run turing machine 'tm' on tape 'tape' from state 'state'. Return number of
 // steps taken until halt.
 constexpr unsigned run(const State *tm, const Tape &tape, unsigned state) {
-  return state == halt ? 1 :
+  return state == halt ? 0 :
          run(tm, move(update(tape, tm[state][tape.val].tape),
                       tm[state][tape.val].dir),
              tm[state][tape.val].next) + 1;
 }
 
-// 3-state busy beaver. 14 steps.
+// 3-state busy beaver. S(bb3) = 21.
 constexpr State bb3[] = {
-  { { true, R, 1 }, { true, L, 2 } },
-  { { true, L, 0 }, { true, R, 1 } },
-  { { true, L, 1 }, { true, R, halt } }
+  { { true, R, 1 }, { true, R, halt } },
+  { { true, L, 1 }, { false, R, 2 } },
+  { { true, L, 2 }, { true, L, 0 } }
 };
-static_assert(run(bb3, Tape(), 0) == 14, "");
+static_assert(run(bb3, Tape(), 0) == 21, "");
 
-// 4-state busy beaver. 108 steps.
+// 4-state busy beaver. S(bb4) = 107.
 constexpr State bb4[] = {
   { { true, R, 1 }, { true, L, 1 } },
   { { true, L, 0 }, { false, L, 2 } },
   { { true, R, halt }, { true, L, 3 } },
   { { true, R, 3 }, { false, R, 0 } } };
-static_assert(run(bb4, Tape(), 0) == 108, "");
+static_assert(run(bb4, Tape(), 0) == 107, "");