Results 1 to 25 of 27
Thread: , ++
Hybrid View
-
8th November 2010 21:46 #1
, ++
, :
. . :
:Code:#include <iostream.h> int m,n; long int AckRekursiv (int m , int n){ if(m==0) return n+1; if (m>0 && n==0) return AckRekursiv (m-1,1); if (m>0 && n>0) return AckRekursiv( m-1,AckRekursiv(m,n-1)); }
, m n 4 1 -Code:long int iterative_ackermann(unsigned int m, unsigned int n) { while (m != 0) { if (n == 0) { n = 1; } else { n = iterative_ackermann(m, n - 1); } m--; } return n+1; }
, ? . , - . , . - "stopped working".
-
8th November 2010 22:42 #2
. . (http://en.wikipedia.org/wiki/Ackermann_function).
, . .
http://en.literateprograms.org/Acker...nction_%28C%29
if ... else.
.a-op a a peae eeo e a o ope.
-
8th November 2010 23:38 #3
. , ? , -?
:
- , 5 1Code:unsigned int formula_ackermann(unsigned int m, unsigned int n) { while(1) { switch(m) { case 0: return n + 1; case 1: return n + 2; case 2: return (n << 1) + 3; case 3: return (1 << (n+3)) - 3; default: if (n == 0) { n = 1; } else { n = formula_ackermann(m, n - 1); } m--; break; }
-
9th November 2010 11:22 #4
m n m<=3 n<=4.
,
n = formula_ackermann(m, n - 1);
, .a-op a a peae eeo e a o ope.
-
9th November 2010 12:39 #5
http://home.versatel.nl/vspickelen/L...s/Ackerman.htm
It's the classic mad benchmark. This function will either overflow the stack or the 32-bit computer word size - if the cpu doesn't burn out from prolonged strain.
get a 4 MB stack, and you can even compute
A(4, 1) = 65533; this will easily take a quarter of an hour though.
" , , , , ."
-
9th November 2010 20:25 #6
BeTaTesTeR, , - m n, , - int.
Kaspritov, , - :
++ 5 :compile w/FreeBasic using -t 4096 to get a 4 MB stack...
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
9th November 2010 23:05 #7
siniozeleno , . , . , , . .
Kaspirtov . , ? 4 C++?
4eRNoBiL . , , formula_ackermann - ?
-
9th November 2010 23:38 #8
-
10th November 2010 04:52 #9
-
10th November 2010 11:03 #10
Dev C++ 4.9.8.0, .
:
, , - "case 1" "case 2", . "", A(4,1) 34 , 2.8 . , Wikipedia.Code:#include <iostream> #include <stdlib.h> using namespace std; unsigned long iterations = 0; unsigned long ackermann(unsigned long m, unsigned long n) { iterations++; switch (m) { case 0: return n+1; break; /* case 1: return n+2; break; case 2: return 2*n + 3; break; */ default: if (!n) return ackermann(m-1, 1); else return ackermann(m-1, ackermann(m, n-1)); } } int main(int argc, char *argv[]) { clock_t start = clock(); cout<<"Ackerman: "<<ackermann(4,1); cout<<", "<<((double)(clock() - start) / CLOCKS_PER_SEC)<<"sec, " <<iterations<<" iterations"<<endl; system("PAUSE"); return 0; }
, BeTaTesTeR - 4 1.4eRNoBiL, , INT_MAX e: 2147483647, a A(4, 1) = 65533, .
, .
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
10th November 2010 11:36 #11
-
10th November 2010 11:10 #12
off/
The numbers listed here in a recursive reference are very large and cannot be easily notated in some other form.
. ...
, ?
-
21st November 2010 12:18 #13
10 , -.
, , .
A α(x), - n, ack(n, n) ≥ x. A ( ) , α(x) , , α(x) 4
A , Disjoint sets. , , , . ( ), - .. α(x) , x ( , "Application"). , . , 10 - " ". .., , Disjoint sets , , , ,
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
21st November 2010 13:01 #14
E
, . - 5 . 5- . .Code:void main () { long int i, j,m=5; while (m!=0) { clock_t start = clock(); cout << "Enter m,n:"; cin>>i>>j; cout<<"Ackermann Recursion is:"<<ack_recursion (i,j)<< " (" <<((double)(clock() - start) / CLOCKS_PER_SEC)<<"sec"<<")"<<endl; cout << "Ackermann Iterative is:" <<ack_iterative (i, j)<< " (" << ((double)(clock() - start) / CLOCKS_PER_SEC) << "sec)\n\n";
4eRNoBiL - , .
-
28th November 2010 15:25 #15
, ...

"start = clock();" cin, . , m n cout. 250 . , - , . ,
Originally Posted by BeTaTesTeR
.
, for while , , . , , , . , "" m n, . - .
. - anrieff Pesho , .
, , - . .
Last edited by 4eRNoBiL; 28th November 2010 at 15:28. Reason:
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
28th November 2010 16:04 #16
To !
, , . , BeTaTesTeR , ( , ):
, m < 4 (Cheat - direct computation for m < 4) - -, :
.Code:default: if (!n) return ackermann(m-1, 1); else return ackermann(m-1, ackermann(m, n-1));
- - , (m, n) m < 4. .. - , :
" , , , , ."
-
10th November 2010 12:20 #17
BASIC - http://home.versatel.nl/vspickelen/L...s/Ackerman.htm
Visual Studio .a-op a a peae eeo e a o ope.
-
10th November 2010 12:39 #18
-
10th November 2010 12:55 #19
, .
:
Code:#include <iostream> #include <stack> #include <time.h> using namespace std; unsigned long ack (int m, int n); void main () { int i, j; clock_t start = clock(); cout << "Test!\n"; for (i = 0; i <= 4; i++) { for (j = 0; j <= 5; j++) { cout << "[" << i << "][" << j <<"] = " << ack (i, j) << " (" << ((double)(clock() - start) / CLOCKS_PER_SEC) << "sec)\n"; } } system ("PAUSE"); } unsigned long ack (int m, int n) { stack<unsigned long> stk; unsigned long rt, ff, x = NULL, y = NULL, z = NULL; bool exit = false; do { while(m != 0) { if(n == 0){ rt = 1; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = 1; m = m - 1; } else { rt = 2; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = n - 1; } } ff = n + 1; exit = false; while(!stk.empty() && exit == false) { z = stk.top(); stk.pop(); y = stk.top(); stk.pop(); x = stk.top(); stk.pop(); n = stk.top(); stk.pop(); m = stk.top(); stk.pop(); rt = stk.top(); stk.pop(); if( rt == 3 ) z = ff; else if(rt == 2){ y = ff; rt = 3; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = y; m = m - 1; exit = true; } } } while(!stk.empty()); return ff; }Last edited by siniozeleno; 12th November 2010 at 09:56.
a-op a a peae eeo e a o ope.
-
20th November 2010 21:28 #20
, . ? .
, . , -. . 4 0. :
siniozeleno,Code:unsigned long ack_recursion(unsigned long m, unsigned long n) { switch (m) { case 0: return n+1; break; case 1: return n+2; break; case 2: return 2*n + 3; break; default: if (!n) return ack_recursion(m-1, 1); else return ack_recursion(m-1, ack_recursion(m, n-1)); } return 0; }
, . Project C++ Source file.Code:unsigned long ack_iterative (int m, int n) { stack<unsigned long> stk; unsigned long rt, ff, x = NULL, y = NULL, z = NULL; bool exit = false; do { while(m != 0) { if(n == 0){ rt = 1; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = 1; m = m - 1; } else { rt = 2; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = n - 1; } } ff = n + 1; exit = false; while(!stk.empty() && exit == false) { z = stk.top(); stk.pop(); y = stk.top(); stk.pop(); x = stk.top(); stk.pop(); n = stk.top(); stk.pop(); m = stk.top(); stk.pop(); rt = stk.top(); stk.pop(); if( rt == 3 ) z = ff; else if(rt == 2){ y = ff; rt = 3; stk.push(rt); stk.push(m); stk.push(n); stk.push(x); stk.push(y); stk.push(z); n = y; m = m - 1; exit = true; } } } while(!stk.empty()); return ff; }
, .
siniozeleno , rt ff ? 4 1 , 4 1 , "stopped working" .
-
21st November 2010 11:53 #21
main(), . , ,
. - , - . , , . while , , . , .
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19




Reply With Quote


Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in