Question
using Dr racket language
Write a function (add-mul L). The function consumes a (listof Int) It performs a series of mathematical operations. It starts
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

#lang racket

(define (add-mul L) ;define the function add-mul with list argument L
(if (empty? L) 0 ;if L is empty return 0, else
(if (equal? (remainder (first L) 2) 0) ;if the first element of L is divisible by 0
(+ (first L) (add-mul (rest L))) ;add it with the return value of add-mul with rest of L as argument
(* (first L) (add-mul (rest L))) ;else multiply it with the return value of add-mul with rest of L as argument
)
)
)

Sample Output

Untitled DrRacket File Edit Vew Language Racket Insert Tabs Help #lang racket define the function add-mul with list argument  

Add a comment
Know the answer?
Add Answer to:
using Dr racket language Write a function (add-mul L). The function consumes a (listof Int) It performs a series of...
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
  • Add or Subtract. Write a function (add-sub-string s). The function consumes a Str of even length,...

    Add or Subtract. Write a function (add-sub-string s). The function consumes a Str of even length, where every even- numbered character is either "+" or "-", and odd-valued characters are numeric The function should add up all the digits that follow a "+", and subtract all the digits that follow a "-". For example, (add-sub-string "+3+4-5") => 2 (add-sub-string "-5+3+4-6-6") - 10 => The interface file contains the function char->nat that converts a numeric Char to the corresponding numeric value....

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • USING PYTHON 3 Write a function no_pairs(L) that consumes a list of natural numbers L and...

    USING PYTHON 3 Write a function no_pairs(L) that consumes a list of natural numbers L and mutates it, replacing any natural numbers which appear exactly twice in the list with -1. The no_pairs function returns None. This function should run in at worst O(n log n) time. HINT: Solving this problem within the demanded runtime will likely require both O(n log n) sorting and O(log n) searching! Samples: L = [254 , 955 , 198 , 590 , 368] after...

  • Write the following function in Java: A function "makeMangler", that takes as input a list M...

    Write the following function in Java: A function "makeMangler", that takes as input a list M of three numbers. It then builds and returns a "Mangler" function based on M. The "Mangler" function that is produced (by your function makeMangler) would have the property that it takes as input a list, and returns the "mangled" version of that list. "Mangling" a list means doing the following sequence of operations to each item in a list: (1) multiply by the first...

  • Using Racket, write a bridgely? function that takes a list of at least 3 numbers and...

    Using Racket, write a bridgely? function that takes a list of at least 3 numbers and returns #true if it is bridgely, otherwise #false. A list of numbers is called "bridgely" if it contains at least 3 numbers, and every number in the list, except for the first and the last, is greater than both the first and the last number. Thus, these lists are bridgely: (list 1 2 3 4 5 6 5 4 3 2 1) (list 0...

  • A) [90 marks] Write a program that .Splits a list into two halves. The function split must modify...

    IN C LANGUEGA(PROGRAMİN C) a) [90 marks] Write a program that .Splits a list into two halves. The function split must modify the original list and return a pointer to the second half of the list, e.g., L = 1 → 2 → 3 → 4 must be 1 2 after execution, and the function must return 3 4 If the size of the original list is odd, add a node with value 99 to the index 4 (recall that...

  • Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified...

    Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops!   CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...

  • C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the +...

    C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the + operator. //Pre : M and N are defined and N > 0. //Post: Returns M x N { int Prod; if (N == 1)     Prod = M;                       //base case else     Prod = M + Multiply(M, N - 1); //recursive step return Prod; } 2) Reverse #include <iostream.h> void Reverse(int N) //Displays string of length N in the reverse order //Pre : N...

  • Write a C++ code based this question n this assignment you will create three additional functions...

    Write a C++ code based this question n this assignment you will create three additional functions for each one of the data structures created in class. You will be provided with a header file which you will modify and a demo program for each data structure. If your functions are implemented correctly the demo programs should compile and execute correctly. Part 0 (Comments) 1. Over the course of the semester we have discussed comments for each data structure. Please add...

  • C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers...

    C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...

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