Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

This need to be done in lisp N Factorial. Takes a positive integer and returns its factorial. Search. A function that receives an integer and

This need to be done in lisp

  1. N Factorial. Takes a positive integer and returns its factorial.
  2. Search. A function that receives an integer and a list. The list will have a mix of integers and words, and may have nested lists. The function returns a count of how many times the integer value is found.
  3. Divide by 3 counter. A function that receives a list of numbers, possibly nested, and returns a count of how many are divisible by 3. Uses a helper predicate function that returns true if its numeric argument is evenly divisible by 3.

Sample: (divide-by-3 (3 15 78 100 4 12)) ==> 4

  1. Has duplicates. Given a list of integers (order unknown, not nested), report whether the list has any duplicates (true) or not (false).
  2. Remove negatives. A function that receives a list of integers, not nested, and returns a list with all negative values removed.
  3. Temperature conversion. Receives a list containing two pieces of data, a number and a letter, where the number is a value for a temperature, and the letter is either C or F (meaning centigrade or Fahrenheit) and returns the converted value (not in a list). Three functions: convert, which calls F-to-C or C-to-F as needed, based on the letter given. Assumption: the numeric value is a legitimate integer, holding a valid temperature.

Sample: (convert (100 C)) ==> 212

  1. Count groups. Given a list of words and / or numbers, not nested, count the number of groups (a group is two or more identical adjacent items).

Examples:

(count-clumps '(a b c)) ==> 0

(count-clumps '(here kitty kitty)) ==> 1

(count-clumps '(happy happy joy joy)) ==> 2

(count-clumps '(yes no no 23 -101 yes yes yes) ==> 2

(count-clumps '(7 7 7 7 7 7)) ==> 1

  1. Sort by recency. Takes a word and a list of words, not nested. If the word is not in the list, it is added at the beginning of the list. If the word is in the list, its position is changed to be first in the list. In both cases, the word most recently added is now at the front of the list. Assumption: the incoming list has no duplicates.

Examples:

(make-recent cat '(a cat came in)) ==> (cat a came in)

(make-recent boy '(cat dog tree)) ==> (boy cat dog tree)

  1. Enforce upper limit. A function that receives a number (an upper limit) and a list of words and / or numbers, possibly nested. The function produces a new list in which all values originally over the limit are replaced by the limit. Assumption: the limit will be a number.

Examples:

(enforce-limit (5 '(6 2 kitty 5 -16)) ==> (5 2 kitty 5 -16)

(enforce-limit (8 '(1 66 2 kitty -16)) ==> (1 8 2 kitty -16)

(enforce-limit '(33 (20 (35 9) 7 100 2 () 2))) ==> (20 (33 9) 7 33 2 () 2)

  1. Twin. Receives a list, not nested, and doubles all elements.

Example:

(twin (dog 2 cat)) ==> (dog dog 2 2 cat cat)

(twin (3 3 4)) ==> (3 3 3 3 4 4)

  1. Expression syntax checker. A function which checks the syntax of a (possibly nested) list of expressions with numeric operands and binary infix operators (the operators are the actual words): plus, minus, times, dividedby. The checker returns nil if any of the following conditions are found, true otherwise: wrong number of tokens in an expression (i.e., not three), operands not numeric, invalid operator. Do not consider any other errors. Your main function should call three helper functions which each check one condition.

Examples of top-level function:

(checker (7 plus 11)) ==> T (true, valid)

(checker (25 minus (17 times 12))) ==> T (true, valid)

(checker (-4 plus)) ==> nil (wrong number of tokens)

(checker (-4 plus (cat minus dog))) ==> nil (operands not numeric)

(checker ((7 + 3) minus 12)) ==> nil (invalid operator +)

(checker (-4 plus (cat minus dog))) ==> nil (operands not numeric)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students explore these related Databases questions