12 #ifndef __ACKERMANN_HH__
13 #define __ACKERMANN_HH__
110 static void Akm_rec(
int x,
int y);
128 printf(
"\nAckermannLoop(%i, %i) = %i\n", x, y, result);
129 printf(
"AckermannLoop(%i, %i) took %ld clicks (%f seconds).\n", x, y, t, ((
float)t) / CLOCKS_PER_SEC);
140 std::cout <<
"\nCurrent call:\n";
142 std::cout <<
"Current deep: " << std::scientific << std::setw(10) << std::left <<
Akm_deep <<
" Max deep: " << std::setw(10) <<
deep_max;
143 std::cout <<
"\nRecursion terminated.\n";
146 printf(
"\nAckermann(%i, %i) = %i\n", x, y, result);
147 printf(
"Ackermann(%i, %i) took %ld clicks (%f seconds).\n", x, y, t, ((
float)t) / CLOCKS_PER_SEC);
152 static time_t begTime = time(
nullptr);
157 std::cout <<
"Max deep: " << std::setw(10) << std::left << std::setw(10) <<
Akm_t::deep_max <<
"Time(s): " << std::defaultfloat << difftime(time(
nullptr), begTime) <<
'\r';
181 time_t begTime = time(
nullptr);
183 struct SnapShotStruct
193 SnapShotStruct currentSnapshot{m, n, 0};
194 SnapShotStack.
push(currentSnapshot);
196 std::cout <<
"Current top:\n";
197 while (!SnapShotStack.
isEmpty())
199 currentSnapshot = SnapShotStack.
top();
205 std::cout <<
"Max deep: " << std::setw(10) << std::left << std::setw(10) <<
Akm_t::deep_max <<
"Stack size(kB): " << std::setw(10) << SnapShotStack.
elemMem() / 1024 <<
"Time(s): " << difftime(time(
nullptr), begTime) <<
'\r';
208 switch (currentSnapshot.stage)
212 if (!currentSnapshot.m)
214 retVal = currentSnapshot.n + 1;
218 if (!currentSnapshot.n)
220 SnapShotStruct newSnapshot{currentSnapshot.m - 1, 1, 0};
221 SnapShotStack.
push(newSnapshot);
225 currentSnapshot.stage = 1;
226 SnapShotStack.
push(currentSnapshot);
227 SnapShotStruct newSnapshot{currentSnapshot.m, currentSnapshot.n - 1, 0};
228 SnapShotStack.
push(newSnapshot);
235 SnapShotStruct newSnapshot{currentSnapshot.m - 1, retVal, 0};
236 SnapShotStack.
push(newSnapshot);
243 std::cout <<
"Current deep: " << std::scientific << std::setw(10) << std::left << std::setw(10) <<
Akm_t::Akm_deep <<
" Max deep: " << std::setw(10) <<
Akm_t::deep_max <<
"Stack size(kB): " << std::setw(10) << SnapShotStack.
elemMem() / 1024;
244 std::cout <<
"\nStack's cleared.\n";