Answered step by step
Verified Expert Solution
Question
1 Approved Answer
use SCHEME program .scm, language R5RS [2 marks] Create a function (repeat x n) that returns a list that contains n copies of the value
use SCHEME program .scm, language R5RS
- [2 marks] Create a function (repeat x n) that returns a list that contains n copies of the value x. E.g.:
(repeat 'a 5) (a a a a a)
- [2 marks] Create a function (alternate list1 list2) that creates a list by alternating elements from the two given input lists. E.g.:
(alternate '(0 0 0 0) '(1 1 1 1 1 1)) (0 1 0 1 0 1 0 1 1 1)
- [2 marks] Create a procedure (count x L) that returns the number of instances of the value x in the list L. E.g.:
(count 3 '(1 4 3 6 2 3 3 1 4 3 5 7)) 4 (count 'b '(4 b a 3 2 c b 1 b 2 d a)) 3
- [4 marks] Create a procedure (mode L) that returns the most common value in the list L. Hint: this question is asking that you find the item with the largest count. In the case of a tie return the value closest to the front of the list (ie the first one encountered). E.g.,
(mode '(a b a c a d d a b c a b)) a (mode '(2 b a 3 2 c b 1 b 2 d a)) 2
- [5 marks] Create a procedure (decreasing L) that returns a list of all of the consecutive decreasing subseqeuences in the input list. E.g.,
(decreasing '(3 6 8 9 7 4 8 6 3)) ((9 7 4) (7 4) (8 6 3) (6 3)) (decreasing '(7 6 5 4 8 5 2 5 1 5 2 1)) ((7 6 5 4)(6 5 4)(5 4)(8 5 2)(5 2)(5 1)(5 2 1)(2 1)) (decreasing '(1 2 3 4 5)) ()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started