Results 1 to 25 of 27

Thread: , ++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693

    , ++

    , :


    . . :
    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)); }
    :
    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;
    }
    , m n 4 1 -

    , ? . , - . , . - "stopped working".
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	problm.png‎ 
Views:	1403 
Size:	152.9 KB 
ID:	33976   Click image for larger version. 

Name:	0ae4053de098cc9554752b190a38bc56.png‎ 
Views:	1396 
Size:	6.6 KB 
ID:	33977  

  2. #2
    1 siniozeleno's Avatar
    Join Date: Jun:2010
    Location:
    Posts: 75
    a-op a a peae eeo e a o ope.

  3. #3
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693
    . , ? , -?
    :
    Code:
    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;
             }
    - , 5 1

  4. #4
    1 siniozeleno's Avatar
    Join Date: Jun:2010
    Location:
    Posts: 75
    m n m<=3 n<=4.
    ,
    n = formula_ackermann(m, n - 1);
    , .
    a-op a a peae eeo e a o ope.

  5. #5
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    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.
    " , , , , ."

  6. #6
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    BeTaTesTeR, , - m n, , - int.

    Kaspritov, , - :
    compile w/FreeBasic using -t 4096 to get a 4 MB stack...
    ++ 5 :
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	ackermann-bench-no-optimization.jpg‎ 
Views:	1238 
Size:	87.2 KB 
ID:	33984  
    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

  7. #7
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693
    siniozeleno , . , . , , . .

    Kaspirtov . , ? 4 C++?

    4eRNoBiL . , , formula_ackermann - ?

  8. #8
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by BeTaTesTeR View Post
    Kaspirtov .
    . ? 4eRNoBiL, , .

    4eRNoBiL, , INT_MAX e: 2147483647, a A(4, 1) = 65533, .
    " , , , , ."

  9. #9
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    . , Properties , :

    , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  10. #10
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    Dev C++ 4.9.8.0, .
    :
    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;
    }
    , , - "case 1" "case 2", . "", A(4,1) 34 , 2.8 . , Wikipedia.

    4eRNoBiL, , INT_MAX e: 2147483647, a A(4, 1) = 65533, .
    , BeTaTesTeR - 4 1. , .
    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

  11. #11
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by 4eRNoBiL View Post
    , , - "case 1" "case 2", . "", A(4,1) 34 , 2.8 . , Wikipedia.

    , .
    , "case 1" "case 2", VS2008 Project->Properties->Configuration Properties -> Linker -> System -> Stack Reserve Size: 4096, Stack overflow. 41024^(2) , 1/2 .
    " , , , , ."

  12. #12
    . worm4's Avatar
    Join Date: Jul:2005
    Location: Varna
    Posts: 20,295
    off/
    The numbers listed here in a recursive reference are very large and cannot be easily notated in some other form.

    . ...
    , ?
    "Arbeit macht frei" -
    - . , :..,,--?!
    OgiDogi: , , ..,

  13. #13
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    Quote Originally Posted by worm4 View Post
    off/


    . ...
    , ?
    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

  14. #14
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693
    E

    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";
    , . - 5 . 5- . .
    4eRNoBiL - , .

  15. #15
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    , ...

    Quote Originally Posted by BeTaTesTeR
    E ...
    "start = clock();" cin, . , m n cout. 250 . , - , . , .

    , 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

  16. #16
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by 4eRNoBiL View Post
    , , - .
    To !

    , , . , BeTaTesTeR , ( , ):
    Quote Originally Posted by 4eRNoBiL View Post
    "", A(4,1) 34 , 2.8 . , Wikipedia.
    , 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. .. - , :
    Quote Originally Posted by 4eRNoBiL View Post
    "start = clock();" cin, .
    " , , , , ."

  17. #17
    1 siniozeleno's Avatar
    Join Date: Jun:2010
    Location:
    Posts: 75
    a-op a a peae eeo e a o ope.

  18. #18
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by siniozeleno View Post
    ?
    " , , , , ."

  19. #19
    1 siniozeleno's Avatar
    Join Date: Jun:2010
    Location:
    Posts: 75
    , .

    :
    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.

  20. #20
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693
    , . ? .


    , . , -. . 4 0. :
    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;
    }
    siniozeleno,
    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;
    }
    , . Project C++ Source file.



    , .
    siniozeleno , rt ff ? 4 1 , 4 1 , "stopped working" .
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	result.png‎ 
Views:	1116 
Size:	49.9 KB 
ID:	34273   Click image for larger version. 

Name:	setting.png‎ 
Views:	1136 
Size:	36.0 KB 
ID:	34274  

  21. #21
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |