Ackermann function is defined as follows for nonnegative integers m and n: A(m, n) = n+1 if m = 0 A(m-1, 1) if m > 0 and n = 0 A(m-1, A(m, n-1)) if m > 0 and n > 0. /***************************************************************************/ Pseudo-code list functions empty(list) if list is empty, return true else return false head(list) return first element of list tail(list) return list with first element removed cons(element, list) return list that has element inserted as new first element of list Example: list = [2, 4, 6] empty(list) --> false head(list) --> 2 tail(list) --> [4, 6] tail( [6] ) --> [ ] cons ('a', list) --> [ 'a', 2, 4, 6 ] /***************************************************************************/ --- reverse a list --- reverse (list) { return rev (list, []); } rev (list, acc) { if ( empty( list ) ) return acc; return ( rev ( tail( list ), cons( head( list ), acc ) ) ); } --- return a list with element x repeated n times --- replicate ( n, x ) { if ( n == 0 ) return [ ]; return cons( x, replicate (n-1, x) ); } --- return true if element a is contained in list --- elem ( a, list ) { if ( empty( list )) return false; if ( a == head( list ) ) return true; return elem( a, tail (list ) ); } --- count elements in a linked list --- count (head) { if (head == null) return 0; return 1 + count (head.next); } // count on generic list count (list) { if (empty (list) ) return 0; return 1 + count (tail(list)); } --- print elements of linked list --- printList(head) { if (head == null) return; print head.value; printList(head.next); } --- insert new element at end of linked list insertAtEnd (head, n) { if (head == null) return n; head.next = insertAtEnd(head.next, n); return head; } main() { head = null; head = insertAtEnd(head, 1); head = insertAtEnd(head, 10); } /******************************************************************************/ /* Functions in Python */ def ackermann(m, n): if m == 0: return n + 1 if n == 0: return ackermann(m - 1, 1) return ackermann( m - 1, ackermann( m, n - 1 ) )