Question

In: Computer Science

*LISP PROGRAM* 2. Write a function that, given a list of lists, returns the total length...

*LISP PROGRAM*

2. Write a function that, given a list of lists, returns the total length of all the lists. This problem can be solved two different ways.

3. Write a program that prompts the user to enter two numbers and then outputs the sum of the two numbers.

4.Write ALLODDP, a recursive function that returns T if all the numbers in a list are odd.

Solutions

Expert Solution

2. Write a function that, given a list of lists, returns the total length of all the lists. This problem can be solved two different ways.

(defun totalLength(mylist)
(setq total 0)
(loop
    (setq total (+ total (length (car mylist))))
    (setf mylist (cdr mylist))
    (if (endp mylist) (return))
   )
   total
)

(format t "~%Total length of list: ~s ~%~%" (totalLength '((a) (a b) (a b c))))

output

3. Write a program that prompts the user to enter two numbers and then outputs the sum of the two numbers.

(write-line "Enter first number")
(setq number1 (read))
(write-line "Enter second number")
(setq number2 (read))
(setq total (+ number1 number2))
(format t "~%~s+~s=~s ~%" number1 number2 total)

output

Completed 2 questions. For the answer of last question post a new post with only that question.


Related Solutions

Given a list of items, write a program that generates a list of lists of the...
Given a list of items, write a program that generates a list of lists of the following form: [a,b,c,...,z]⇒[[z], [y,z], [x,y,z], ... , [a,b, ... ,y,z]] Hint: Slicing is your friend. please write a python program
Write a function in lisp XIT that counts the number of items in each sub-list of...
Write a function in lisp XIT that counts the number of items in each sub-list of a list and returns the count in a list. It should only work if there are two levels of brackets in the parameter (simple lists inside the parent list). Thus:             (XIT '((A B C)))        -> (3)             (XIT '((A) (A B) (A B C))) -> (1 2 3)             (XIT '((1 2)))              -> (2)             (XIT '(1 (2 3)))...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
CODE USING LISP... No other language please trim-to (symbol list) Write a function named trim-to that...
CODE USING LISP... No other language please 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 input symbol in the input list. If there is no occurrence of the symbol, return nil. For example: (trim-to ‘c ‘(a b c d e)) This should return the following list: ‘(c d e) ackermann (number number) Write a function named ackermann that takes two integers....
We were asked this: Write a function that takes a list, and returns a list representing...
We were asked this: Write a function that takes a list, and returns a list representing each word whose reverse is also in the list. def find_reversals(lst: List[str]) -> List[str]: Each pair, such as 'abut', 'tuba', should be represented by the first element encountered. Don't report the same pairs twice. Don't list palindromes. I wrote this, which might not be optimal but passes the unit test! def find_reversals(lst): #Place to save to found_reversals=[]    #Make each string lowercase for i...
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Use Scheme Language Write a Scheme function that takes a list and returns a list identical...
Use Scheme Language Write a Scheme function that takes a list and returns a list identical to the parameter except the third element has been deleted. For example, (deleteitem '(a b c d e)) returns ‘(a b d e) ; (deleteitem '(a b (c d) e)) returns ‘(a b e).
Write a function child_indices(parent, branch_factor) that returns a list containing the list of indices where the...
Write a function child_indices(parent, branch_factor) that returns a list containing the list of indices where the children of the node at index parent will be stored for a heap list with the given branch_factor (ie, a branch_factor-heap). Python language Notes: The function should return all possible indices and the indices should be in order from smallest to biggest. The values in the heap list start at index 1 - that is the root of the heap is at index 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT