Question

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.

Write a function (running-sum L) that takes a list of numbers L and generates a list of the runnining sums. See the following examples for clarification.

(running-sum  '(1 2 3)) ---> (1 3 6)
(running-sum  '()) ---> ()
(running-sum  '(3 0 -2 3)) ---> (3 3 1 4)

Homework Answers

Answer #1

Okay, as the name suggests the running sum or the cumulative sum is the sum of all the numbers that has came so far,

Now for the scheme of the function

Def runningsum (list1):

Rs= 0, list2=list() # these are needed to hold results

For x in list1:

Rs=Rs+ int(x)

list2.append(Rs)

Return (list2)

Here we are having a temp variable, with initial zero and after every items of list1 comes we add that that to the temp, getting next item of the running sum list and append it to the list2 and once all elements are over in list 1 we get out of the loop and then send the list2 which we have saved all the sums in as a return value

Know the answer?
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
Similar Questions
This problem need to use DrRacket software. Racket Language. You must write each of the following...
This problem need to use DrRacket software. Racket Language. 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. Write a function (join-together L1 L2) that takes a sorted list (ascending) of integers L1 and a sorted list of elements L2 and returns a sorted list containing all elements of both L1 and L2. See...
Program has to be written in ML language. Write functions in ML to do the following:...
Program has to be written in ML language. Write functions in ML to do the following: 1. Given a list, return that list with its first and third elements deleted. Assume the length of the list is at least 3. 2. Given a list of real pairs, return the list containing the larger element in each pair. Examples: larger_in_pair([]) = [] larger_in_pair([(1.0,2.5),(4.7,3.6),(5.5,8.8)] = [2.5,4.7,8.8] 3. Given two lists of integers, return the list of the sums of the elements in...
Scheme Programming Write a polynomial time scheme program to find the longest non-decreasing subsequent of a...
Scheme Programming Write a polynomial time scheme program to find the longest non-decreasing subsequent of a list of numbers. For example: (longest ''(2 4 3 1 2 1 3 6 1 3 2 1 2 33 4 2 4 10 11 7)) --> (1 1 1 1 2 4 4 10 11). Do not use side-effecting functions (i.e., functions with exclamation point in their names such as set!), sequencing, iteration (e.g., do, for-each) or vectors. Do not use input/output mechanisms...
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function f2 that decides whether a list has an atom inside. Example: (f2 ‘((a b)(c d))) returns nil, (f2 ‘(a (b c))) returns t
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f7 that returns the element at a given location of a list. The locations start at 0. Example: (f7 ‘(c (a b) (d c) (x y)) 2) returns (d c)
Question 1 Write functions that do the following: i) A function that takes 2 arguments and...
Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are...
Your C program will do the following : Must use at least 2 function prototypes &...
Your C program will do the following : Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays. 1. In your main program, create a array of size 7 X 7. 2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function...
IN SML Write a function dupList of type 'a list -> 'a list whose output list...
IN SML Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be []. Do not use explicit recursion but use one of the fold functions. Do...
IN ML(NOT PYTHON) Write a function dupList of type 'a list -> 'a list whose output...
IN ML(NOT PYTHON) Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be []. Do not use explicit recursion but use one of the fold functions....
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT