Question

Write in LISP, Write a function named ackermann that takes two integers. Use the following function...

Write in LISP,

Write a function named ackermann that takes two integers. Use the following function definition: (Note: due to this function’s complexity it may not finish for inputs larger than 3)

?(?,?) = {
? + 1                             ?? ? = 0

?(? − 1,1)                   ?? ? = 0

?(? − 1,?(?,? − 1))   ??ℎ??????

Sample:

(print (ackermann 1 1)))

Sample output:

3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(defun ackermann (x y)
(cond ((= x 0) (+ y 1))
(t (cond ((= y 0) (ackermann (- x 1) 1))
(t (ackermann (- x 1) (ackermann x (- y 1))))
))
))


(print(ackermann 1 1 ))

========================================
SEE OUTPUT



Thanks

Add a comment
Know the answer?
Add Answer to:
Write in LISP, Write a function named ackermann that takes two integers. Use the following function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol...

    Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol and a list. Count the number of instances of x in the list. Do not count the number of x in any sub-lists within the list. Test: count-of 'a '(a 'a(a c) d c a). Result: 2 trim-to (symbol list): Write a function named trim-to that takes a symbol and list as parameters. Return a new list starting from the first occurrence of the...

  • Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates...

    Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates all the duplicate integer integers in the array. The function should take two arguments: (1) an array of integers; (2) an integer that tells the number of cells in the array. The function should return the number of distinct integers in the array.

  • Your task is to write a function definition for a function named non_vowel_words that takes a...

    Your task is to write a function definition for a function named non_vowel_words that takes a string as a parameter.  The function returns a setcontaining the words of the strings that do not start with a vowel (upper or lower case). The vowels are A, E, I, O, U. For full credit, make sure your implementation is pythonic, uses Python built-in capabilities and follows the Python style guide recommendations.  Please include a docstring for your function. You may test your function as...

  • Write a recursive function named multiply that takes two positive integers as parameters and returns the...

    Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...

  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • Write a function named findTarget that takes three parameters: - numbers, an array of integers -...

    Write a function named findTarget that takes three parameters: - numbers, an array of integers - size, an integer representing the size of array - target, a number The function returns true if the target is inside array and false otherwise

  • In Lisp programming language a 16. (20 pts.) Write a function that takes a list of...

    In Lisp programming language a 16. (20 pts.) Write a function that takes a list of 0's and l's and "toggles" each element. Your function should include lambda expression that knows how to flip an individual element, plus an applicative operator to do this to every element of the list. Example: 1 0) List (0 0 1 1 0 1) should be transformed into (1 1 0 0

  • Ouestion 1 (15 pts) Write a lisp function triangle that takes an argument (n) and shows...

    Ouestion 1 (15 pts) Write a lisp function triangle that takes an argument (n) and shows a triangle of printed numbers as shown in the following samples. If the input is decimal or string, it should print an appropriate message (triangle 4) (triangle 5) 1 2 1 2 3 1 2 3 4 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (triangle 2.5), decinal numbers are not valid input, please enter an integer

  • help Question 12 (20 points) Write a function named inverse that takes a single parameter, a...

    help Question 12 (20 points) Write a function named inverse that takes a single parameter, a dictionary. In this key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. dictionary each The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course For...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT