1
( defun piece(x)
(if (<= x 0)
(format t "piece(x)= ~5f" -1))
( if (and (> x 0) (< x 1))
(format t "piece(x)= ~5f" x))
( if (and (>= x 1))
(format t "piece(x)= ~5f" 1))
)
( piece 1 )
OUTPUT :-
in above function it will print 1 if x is greater or equal to 1 and print x if 0<x<1 and print -1 if x<=0
it is written in lisp and it is a linear function.
2.
(defun intlist(a b)
(loop for x from a to b
do (print x)
))
(intlist 2 4)
OUTPUT :-
in above function it will print integer between a to b .
if we give input intlist 2 4 it will print 2 3 4
1. Write a Lisp function called piece which takes a single argument x and implements the followin...
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...
USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...
Write a function called ''minandmax'' . Function ''minandmax'' takes only one input argument that is a matrix M . This matrix M can be any size (any number of columns and rows) with any random integer values . Function ''minandmax'' returns two output arguments. The first output argument is called ''difference_row'' that returns a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. The second output argument is called ''difference_all''...
Lisp Scheme Write a procedure in Lisp Scheme called charflip that takes a string as a parameter and returns a copy of this string, flipping the case of every character in an odd position (index 1, 3, 5, etc..). I suggest that you do this recursively. This means cons, car and cdr will come in handy, as will these functions: • char-upper-case? • char-downcase • char-upcase • list->string • string->list Here’s this function in action. scheme@(guile-user)> (charflip "hatburg") $16 =...
Write a function called smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32
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
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].
Write a program call p1.py. Add a function called make_rand_list(n) to your program that takes an integer n as input and returns a list of n random integers in the range [1,100]. Add another function called product(list) that takes a list of random numbers as an argument and return the product of all the random numbers of that list. Sample run: make_rand_list(7) returns list = [34, 18, 35, 26, 53, 9, 48] product(list) returns 12751240320
2. Write a LISP function COUNTLETS which takes a list and returns the number of top-level alphabetic atoms in the list. For example: COUNTLETS ( (A 2) B 3 C4 (D 5))) Returns the value 2, the letters A and D are not at the top level
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