Question

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 binary number and returns its decimal value (binaryToDecimal 1101) returns 13 . A function (addBinary binaryList) that takes a list of binary numbers and returns their 101)) returns 27 value in a simple list of integers s. A function (min list) that returns the smallest 6. A function (myRemove atm list) that removes all occurrences of the atom atm from a simple list, returning list with atm removed. myRemove should return the original list if atm is not found 7. A function (selectionSort list) that returns a simple list of integers in ascending order using a recursive selection sort algorithm. Hint: use your min function All the functions must be written in a functional style and must use only the basic LISP functions car, cdr, cons, null, atom, the equality functions, the arithmetic functions, and the append function
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

(define (binomial N k)

(if (= k 0)

1

(if (= k N)

1

(+ (binomial (- N 1) k) (binomial (- N 1) (- k 1))))))

Output:

>(define (binonial N k) (k e) if (k N) (binontal N 1) k) (binontal (- N 1) (- k 1)))>) > (binonia1 8 3) Value: 56 (binonial 12.

(define (mod N M)

(remainder N M))

Output:

(define (mod N M) (remainder N M)) Value: mod 1 J-> (nod s 3) Value: J(nod 98 22) Value: 103.

(define (binaryToDecimal b)

(if (= b 0)     

0

(+ (remainder b 10) (* 2 (binaryToDecimal (quotient b 10))))))

Output:

(define (binaryToDectal b) Value: binarytodecimal 1 1 (binaryToDecimal 101) Value: 5 -(binaryToDecimal 1011) Value: 11 1 (bin4.

(define (binaryToDecimal b)

(if (= b 0)

0

(+ (remainder b 10) (* 2 (binaryToDecimal (quotient b 10))))))

(define (addBinary binaryList)

(if (null? binaryList)

0

(+ (binaryToDecimal (car binaryList)) (addBinary (cdr binaryList)))))

Output:

(define (addBinary binaryList) (if (null? binaryList) (binaryToDecimal (car binaryList)) (addBinary (cdr binaryList)) Value:

Add a comment
Know the answer?
Add Answer to:
Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lisp Scheme Write a procedure in Lisp Scheme called charflip that takes a string as a...

    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 =...

  • Overview The purpose of this assignment is to practice functional programming in the Racket Programming Language...

    Overview The purpose of this assignment is to practice functional programming in the Racket Programming Language and to also reinforce the notion of the list as a universal data structure, by implementing various operations on binary search trees. Specification A binary search tree is a binary tree which satisfies the following invariant property: for any node X, every node in X's left subtree has a value smaller than that of X, and every node in X's right subtree has a...

  • Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2...

    Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers. For example, 16 = 4^2 = 7 + 5 + 3 + 1. Write a function that takes as input a natural number, n, and that returns the square of its input by adding the first n odd numbers. Your code may not contain delayed operations and must use accumulative recursion.

  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • You must write each of the following scheme functions. You must use only basic scheme functions...

    You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...

  • 1) Describe in your own words the fundamental concept behind declarative programming paradigm 2) Explain what...

    1) Describe in your own words the fundamental concept behind declarative programming paradigm 2) Explain what is happening below. Why are these results looking like this? Describe why it is happening in your own words. >(-10.2 10) 0.1999999999999993 >(-1.2 1) 0.1999999999999996 >(-1.4 1) 0.3999999999999999 >(-2.2 1) 1 .2000000000000002 3)Below is a scheme function. for your answer, write a comment for this piece of code in valid scheme syntax (define( factorial n) if(=n 0) 1 (*n(factorial(-n 1))))) The elements to include...

  • Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you...

    Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...

  • Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with...

    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...

  • You must write each of the following scheme functions. You must use only basic scheme functions...

    You must write each of the following scheme functions. You must use only basic scheme functions (those described in class), do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (key-store L1 KEY) that accepts a list of two-tuples L1 and a value KEY. This function returns the second value of the first tuple that begins with KEY....

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT