Question

In: Computer Science

Write LISP functions GEFILTER and LFILTER. GEFILTER takes a numeric atom and a list of numbers...

Write LISP functions GEFILTER and LFILTER. GEFILTER takes a numeric atom and a list of numbers and returns a list consisting all numbers in the list which are greater than or equal to the given number. LFILTER takes a numeric atom and a list of numbers and returns a list consisting of all numbers in the list less than the given number. For example: (GEFILTER 4 ‘(3 5 8 2 4 1 9)) Returns the list (5 8 4 9) and (LFILTER 4 ‘(3 5 8 2 4 1 9)) Return the list (3 2 1)

Solutions

Expert Solution

Code:

(defun GEFILTER (atom list)
(cond ((null list) '()) ;;if list is null returns empty list
((>= (car list) atom) (cons (car list) (GEFILTER atom (cdr list)))) ;;if first element is greatet than or equal to atom add it to list and continue
(t (GEFILTER atom (cdr list)))));;else continue with rest of list

(defun LFILTER (atom list)
(cond ((null list) '()) ;;if list is null returns empty list
((< (car list) atom) (cons (car list) (LFILTER atom (cdr list)))) ;;if first element isless than atom add it to list and continue
(t (LFILTER atom (cdr list))))) ;;else continue with rest of list

Snapshot of Code:

Output:


Related Solutions

Write a LISP function COUNTX which takes an atom and a list and returns the number...
Write a LISP function COUNTX which takes an atom and a list and returns the number of top-level occurrences of the atom in the list. For example: (COUNTX ‘A ‘(A (A B) B A B A (B A)) Returns the value 3, the other two A’s are not at the top level
Write a LISP function POWER that takes a list containing exactly two numeric atoms and computes...
Write a LISP function POWER that takes a list containing exactly two numeric atoms and computes the first atom raised to the power of the second atom. For example: (POWER ‘(2 4) Returns the value 16
Write a function that takes a numeric or integer vector and adds up only the numbers...
Write a function that takes a numeric or integer vector and adds up only the numbers whose integer parts are even. Modify your answer to question above to include an option that allows you to choose whether to sum numbers whose integer parts are even or are odd. Your function should have as a default that it gives the same output as the function in question 4. In other words, if the user doesn’t specify whether to sum evens or...
Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and...
Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and turns them into words and sentences. The code should use the 0 to represent a space between words and 00 to represent a period at the end of a sentence. The 26 letters of the alphabet should be represented in reverse order. In other words, Z is 26 and A is one. In your final product, only the first letter of a sentence should...
Write a C function str_to_float() that takes a numeric string as input and converts it to...
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below int str_to_float(char * str, float * number);
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list...
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the even numbers in values (i.e., the even numbers raised to the third power). For example: >>> cube_evens_lc([2, 5, 6, 4, 1]) result: [8, 216, 64] This version of the function may not use recursion. Write a function cube_evens_rec(values) that takes as input a...
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)))...
Using Matlab, write a function that takes numeric data as its input argument and prints a...
Using Matlab, write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative. Please include a copiable code and the associated screenshots.
*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.
List the quantum numbers for the electrons in the ground state of a neon atom. What...
List the quantum numbers for the electrons in the ground state of a neon atom. What are the quantum numbers for the next state to be filled in this scheme? If a single electron were excited by the minimum amount of energy possible, what would then be the configuration of the atom?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT