Scheme Language: Define a function nondecreastream, which takes in a stream of numbers and outputs a stream of lists, which overall has the same numbers in the same order, but grouped into segments that are non-decreasing.
For example, if the input is a stream containing elements 1 2 3 4 1 2 3 4 1 1 1 2 1 1 0 4 3 2 1 ...
the output should contain elements (1 2 3 4) (1 2 3 4) (1 1 1 2) (1 1) (0 4) (3) (2) (1) ...
If the input is an infinite stream, the output should be an infinite stream and if the input is finite, the output should also be finite.
Hint: avoid any direct recursive calls outside the context of a second part of a call to cons-stream, otherwise your solution won't work for infinite streams!
(define (nondecreastream s)
'YOUR-CODE-HERE)
Scheme Language: Define a function nondecreastream, which takes in a stream of numbers and outputs a...
USING SCHEME PROGRAMMING LANGUAGE define a function addSubList that processes a list of lists of numbers and adds up all sub-lists. The output of your function is a flat list of numbers. (You can assume that your function only receives valid input). Example: (define Q '(1 2 (3 4) 1 5 (7 8))) ;;;;;;;;;;;;;;;;;;;;; ; (addSubList Q) ; => '(1 2 7 1 5 15) ;;;;;;;;;;;;;;;;;;;
Define in Scheme an infinite stream consisting of twin prime numbers. All primes ? with the property that ? + 2 or ? − 2 are also prime should be included, each one only once. Hint: Apply the Sieve of Eratosthenes.
Define in Scheme an infinite stream consisting of all pairs of twin prime numbers, i.e. all pairs of prime numbers differing by 2, listed in increasing order according to the first number of a pair, in every pair the first item being smaller than the second item. Hint: Apply the sieve of Eratosthenes in order to construct a predicate is-prime?
Write a program in scheme using eopl language. Define a function "symbol-count" which takes a flat list of symbols and returns a list of lists in which each symbol is paired with the count of how many times it occurs in the original input. > (symbol-count '(b a)) '((b 1) (a 1))
Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...
. Write a Scheme program for each of the following. Which takes in two lists “lst1” and “lst2”, both of which are individually sorted (in ascending order), and returns a list containing the elements of both lst1 and lst2 in sorted order. Print the final list. Input to the program are “lst1” and “lst2”. For instance, lst1 = (1 3 5 7) and lst2 = (2 4 6 8) output: (1 2 3 4 5 6 7 8)
Write a function which takes as input a matrix and outputs a matrix in which each positive element is doubled. For instance, for the matrix A=[3, -1; -2, 4], and output should be [6,-1; -2,8].
Below is is a scheme function. For your answer, write a comment for this piece of code in valid scheme syntax. (define (factorial n) (if (=n0) (* n (factorial (- n 1))))) The elements to include in your comment that is described in your own w ords (succinctly, such as if you were commenting code instead of a survey) ... 1) the necessary formatting to indicate it is a legal scheme comment 2) expected input 3) expected output 4) what...
SCHEME [3 marks] Define a procedure called days_in_month that takes as arguments two numbers representing a month and a year. The procedure should return the number of days in the given month. Note: the procedure should account for leap years. You may assume valid month and year values are passed in as arguments. E.g. (days_in_month 9 2019) → 30 E.g. (days_in_month 2 2019) → 28 E.g. (days_in_month 2 2020) → 29
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...