int ackermann(int m, int n) { if (m == 0) return n + 1; else if (n == 0) return ackermann(m - 1, 1); else return ackermann(m - 1, ackermann(m, n - 1)); }
int ackermann(int m, int n) { if (m==0) { return n+1; } if (n==0) { return ackermann(m-1,1); } return ackermann(m-1,ackermann(m,n-1)); }
int ackermann(m, n){ if(m == 0){ return n + 1; }else if(n == 0){ return ackermann(m-1, 1); }else if(n > 0){ return ackermann(m-1, ackermann(m, n-1)); } printf("ERROR\n"); }
int ackermannStart() { int m, n; printf("Enter m: "); scanf("%d", &m); printf("Enter n: "); scanf("%d", &n); ackermann(m, n); printf("Result: %d\n", ackermann(m,n)); getchar(); return 0; }
int main() { for (unsigned m = 0; m < 4; ++m) { for (unsigned n = 0; n < 10; ++n) { std::cout << "A(" << m << ", " << n << ") = " << ackermann(m, n) << "\n"; } } std::cout << "A(4, 1) = " << ackermann(4, 1) << "\n"; std::stringstream ss; ss << ackermann(4, 2); auto text = ss.str(); std::cout << "A(4, 2) = (" << text.length() << " digits)\n" << text.substr(0, 80) << "\n...\n" << text.substr(text.length() - 80) << "\n"; }
int ackermann(int m, int n) { if(m == 0) { n++; return(n); //A(0 , n) = n + 1 for n >= 0 } else if(n == 0) { return ackermann(m - 1, 1); //A(m , 0) = A(m – 1 , 1) for m > 0 } else return ackermann(m - 1, ackermann(m, n - 1)); //A(m , n) = A(m – 1 , A(m , n - 1)) for n >= 0 }
int ackermann(int m, int n) { int idx, res; if (!m) return n + 1; if (n >= 1<<n_bits) { printf("%d, %d\n", m, n); idx = 0; } else { idx = (m << n_bits) + n; if (cache[idx]) return cache[idx]; } if (!n) res = ackermann(m - 1, 1); else res = ackermann(m - 1, ackermann(m, n - 1)); if (idx) cache[idx] = res; return res; }
int main() { int m = __VERIFIER_nondet_int(); int n = __VERIFIER_nondet_int(); int result = ackermann(m,n); if (m < 2 || result >= 4) { return 0; } else { ERROR:assert(0); goto ERROR; } }
int main(int argc, char* argv[]) { if(argc != 3){ printf("You must enter two inputs.\n"); return 0; } int m, n; m = strtoint(argv[1]); n = strtoint(argv[2]); printf("Ack(%d,%d) = %d\n", m, n, ackermann(m, n)); }
int main(){ int n,m,res; printf("Ingrese n \n"); scanf("%d",&n); printf("Ingrese m \n"); scanf("%d",&m); res=ackermann(n,m); printf("Resultado %d\n,res"); return 0; }
int main() { int m, n; m_bits = 3; n_bits = 20; /* can save n values up to 2**20 - 1, that's 1 meg */ cache = malloc(sizeof(int) * (1 << (m_bits + n_bits))); memset(cache, 0, sizeof(int) * (1 << (m_bits + n_bits))); for (m = 0; m <= 4; m++) for (n = 0; n < 6 - m; n++) { printf("A(%d, %d) = %d\n", m, n, ackermann(m, n)); return 0; }
int main() { int m = __VERIFIER_nondet_int(); if (m < 0 || m > 3) { return 0; } int n = __VERIFIER_nondet_int(); if (n < 0 || n > 23) { return 0; } int result = ackermann(m,n); if (m < 0 || n < 0 || result >= 0) { return 0; } else { ERROR: __VERIFIER_error(); } }
int main(void) { int r, m, n; struct timeval t1, t2, tv; createstack(); printf("Enter m and n: "); scanf("%d%d", &m, &n); gettimeofday(&t1,NULL); r = ackermann(m,n); gettimeofday(&t2,NULL); printf("Result = %d\n", r); timersub(&t2,&t1,&tv); printf("Time taken for ackermann: %ld milliseconds\n", ((1000000*tv.tv_sec+tv.tv_usec)/1000)); return 0; }
int main(){ volatile int a=ackermann(4,1); return 0; }
int ackermann(int m, int n) { if (m == 0) return n+1; else return ackermann(m-1, (n==0) ? 1 : ackermann(m, n-1)); }
int main() { printf("ackerman(%d, %d) = %d\n", 2, 2, ackermann(2, 2)); return 0; }