Please help with all four questions regarding LISP Programming. Thank you.
Please answer all questions with output plesase.
LISP Programming Assignment
It is a good idea to start this assignment early; Lisp programming,
while not inherently difficult, often seem somewhat foreign at
first, particularly when it comes to recursion and list
manipulation. This assignment is loosely based on material by Dr.
Henri Casanova.
Problem #1 Define a function that takes two arguments and returns
the greater of the two.
Problem #2 Write a function called inches that accepts feet and
inches and returns the equivalent length in centimeters. If x is
the first argument and y is the second, the formula is 2.54(12x +
y). For example,
USER(1): (inches 0 1)
2.54
USER(1): (inches 6 2.5)
189.22999999999999
Problem #3 - Remove an element from a list using
Iteration
Write a Common Lisp function called my-remove that takes an atom
and a list in input, and returns a list that is identical to the
input list, but with elements equal to the input atom removed, if
any. Examples of the function in operation are shown below (user
input is in red):
CL-USER(1): (my-remove 'b '(a b c b d)) (a c d) CL-USER(2):
(my-remove 'b '(a c d e f)) (a c d e f) CL-USER(3): (my-remove 'a
'(b (a d) a d)) (b (a d) d) CL-USER(4): (my-remove 'a '())
nil
Problem #4 - Remove an element from a list using
Recursion
Write a Common Lisp function called my-recursive-remove that takes
an atom and a list in input, and returns a list that is identical
to the input list, but with all occurrences of the input atom
removed, if any. Examples of the function in operation are shown
below (user input is in red):
CL-USER(1): (my-recursive-remove 'a '(a b c d)) (b c d) CL-USER(2):
(my-recursive-remove 'a '((a b) a (c d e a) (a a) b)) ((b) (c d e)
nil b)) CL-USER(3): (my-recursive-remove 'a '((((a)))))
(((nil)))
Problem #5 - Flatten a list
Write a Common Lisp function called flatten that takes a list that
may have embedded lists, and returns a flattened version of it
(i.e., a list whose elements are only atoms and empty lists have
been removed). Examples of the function in operation (user input is
in red):
CL-USER(1): (flatten '(a b c d)) (a b c d) CL-USER(2): (flatten '(a
() b (c d))) (a b c d) CL-USER(3): (flatten '(a (()))) (a)
CL-USER(4): (flatten '(a (b c) (d e (f) ((((((g)))) h)) i) j (k)
l)) (a b c d e f g h i j k l)
Here is the code that you can try :
1 . (defun greater (a b) (if (> a b) a b))
(print (greater 6 7))
2. (defun convert-one (inches)
(* inches 2.54))
3. (defun my-remove (lst elem &optional
final)
(cond
((and (atom lst) (eql lst elem)) nil)
((listp lst) (mapcan (lambda (e) ( my-remove e elem final))
lst))
(t (nconc final lst))))
4. (defun my-recursive-remove (thing l)
(cond ((null l) '())
((eql thing l) '())
((atom l) l)
((eql (first l) thing) (my-recursive-remove thing (rest l)))
((atom (first l)) (cons (first l)
(my-recursive-remove thing (rest l))))
(t (cons (my-recursive-remove thing (first l))
(my-recursive-remove thing (rest l))))))
5. (defun flatten (lst)
(cond
((null lst) nil)
((atom lst) (list lst))
(t (loop for a in lst appending (flatten a)))))
If any doubts ,comment below ...
Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with...
Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or LISP if you prefer) . A function (binomial N k) that returns the binomial coefficients C(N, k), defined recursively as: C(NO) = 1, C(N, N) = 1, and, for 0<k < N E(N, k) = C(N-1, k) + C(N-1, k-1) 2. A function (mod N M) that returns the modulus remainder when dividing N by M 3. A function (binaryToDecimal b) that takes a...
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...
5. Define a LISP function MONTH-INTEGER which takes as argument a symbol that should be the name of a month, and which returns the number of the month. For example, (MONTH-INTEGER MARCH) 3 and (MONTH-INTEGER JUNE) 6. If the argument is not a symbol that is the name of a month, the function should return the symbol ERROR. E.g., (MONTH-INTEGER C) ERROR, (MONTH-INTEGER 7) ERROR ( MONTH-INTEGER 'QUOTE)-> ERROR, and ( MONTH-INTEGER "(MAY))-> ERROR. 6. Define a LISP function SCORE->GRADE...
Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns all the items of each list concatenated together into one new 1D list. For example: flatten ([["a", "b"],["c","0"],["e","f"]]) would return ["a", "b","C","d", "e","f"] Save the function in a PyDev library module named functions.py Write a program t03.py that tests flatten function and prints the returned flat list to the screen. Test your program with a different list, hardcoded in t03.py • Copy the results...
PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...
Please Provide me all Necessary Screenshot with copy able code. Thanks Write a scheme function named up-to-first-number that takes a list as its input and returns a list containing all the elements up to the first numeric element in the input list. You can use the number? predicate function to determine whether an element is a number or not. Sample runs: (up-to-first-number '(a b c d 1 2 3 )) returns (a b c d) (up-to-first-number '(d e f 7))...
Please place all of the following functions (defun …) into a SINGLE .lsp file As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number. Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers. Do not worry about efficiency here. HINT: You can use ONEFIB...
Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...
C++ Programming please answer both questions and if anyone knows the source of this questions (Book, Website, ...) please let me know. thanks A. (10 Points) Recursive Minimum Write a recursive method that computes the minimum element of an array Hint: The minimum value in an array is either the first element, or the minimum number in the rest of the array, whichever is smaller. B. (10 Points) Recursive Count Write a recursive function to count (from 1) up to...
PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a list of albums. The named tuples used for Albums and Songs are defined below, and an example of a music collection is given. (DO NOT HARDCODE THE VALUES FOR MUSIC!) Album = namedtuple('Album', 'id artist title year songs') Song = namedtuple('Song', 'track title length play_count') MUSIC = [ Album("1", "Peter Gabriel", "Up", 2002, [Song(1, "Darkness", 411, 5), Song(2, "Growing Up",...