2. Write a scheme function get-even-nums that accepts a list of numbers and returns a new list that contains only the even numbers. (Hint: use reminder function) Sample runs: (get-even-nums ‘(1 2 3 4 5 6 7 8 9)) should return (8 6 4 2). (get-even-nums ‘(1 3 5 7 9)) should return ’( ).
Answer:-
*** The list may not be simple,nested lists can occur and you need to find the even numbers inside those list then we will write this scheme.
(define (evenlist numberlist)
(cond ((null? numberlist) '())
((not (pair? numberlist))
(if (even? numberlist) (list numberlist) '()))
(else
(append (evenlist (car numberlist))
(evenlist (cdr numberlist))))))
*** If it is a simple list.
(define (evenlist numberlist)
(cond
((null? numberlist) '())
(else(not (= 0 (modulo (numberlist) 2))(evenlist(car numberlist))))
))
2. Write a scheme function get-even-nums that accepts a list of numbers and returns a new...
PYTHON CODE
In a program, write a function that accepts two arguments: a
list, and a number n. Assume that the list contains numbers. The
function should display all of the numbers in the list that are
greater than the number n. Output should look like:
Number: 5 List of numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List of numbers that are larger than 5: [6, 7, 8, 9, 10]
Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list identical to the parameter except the last element has been deleted. For example, (DEL-LELEMENT '(8 2 3 7 6)) should return (8 2 3 7) *Please explain your code and submit the source code. Please test the function with the provided example and submit a screen shot of the testing result.
Problem 5 in python, write a function called sequencelength that accepts two input arguments: a list of integers (called mylist here) and an integer (called x here). The function should return True if mylist contains an increasing sequence with a length of at least x values. Otherwise, the function should return False. An increasing sequence of numbers is one in which each number is larger than the one before it. For example, [4, 8, 13, 14, 21] is an increasing...
Python3: Write the function findLongestStreak(lst) which takes a list of numbers, lst, and returns the longest streak of numbers which occur in the list. A streak of numbers is a list of numbers where each number is one greater than the one that occurred before it- for example, [4, 5, 6, 7]. So findLongestStreak([3, 4, 8, 2, 3, 4, 5, 7, 8, 9]) would return [2, 3, 4, 5]. If there is more than one streak with the longest length,...
Create a program that will determine the even number(s) from a list of numbers. Your program should create and call a function FindEven that accepts a list of numbers and returns a list of only the even numbers in sorted order. Note that the original list is given in the starter code. def body(): numberlist = [1, 1000, 5, -3, 2, 16 # Write your code here and notice level # Do NOT include: if __name__ == been provided for...
Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers. The number n to test the file numbers. Output to the console: The...
FOR PYTHON: Write a function findMinRow() that
takes a two-dimensional list of numbers as a parameter. It
returns the index of the minimum row in the list.
The minimum row is the row with the smallest sum of elements. If
the list has multiple rows that achieve the minimum value, the last
such row should be returned. If the list is empty the function
should return -1. The following shows several sample runs of the
function:
Python 3.4.1 Shell File...
*****In SML/NJ****** 1. Write a function count_list with type int list -> int that returns the number of items in a list. An item that is repeated is counted each time it appears in the list. 2. Write an ML function sum_list with type int list -> int that returns the sum of all the elements within a list 3. Write a function countdown with the type int -> int list that returns a list of numbers from its argument...
Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...