Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function sequence that takes 3 arguments low, high, and stride, all assu

ID: 673773 • Letter: W

Question

Write a function sequence that takes 3 arguments low, high, and stride, all assumed to be numbers. Further assume stride is positive. sequenceproduces a list of numbers from low to high (including low and possibly high) separated by stride and in sorted order. Sample solution is 4 lines.

Example 1: (sequence 3 11 2) results in ’(3 5 7 9 11)

Example 2: (sequence 3 8 3) results in ’(3 6)

Example 3: (sequence 3 2 1) results in ’()

Write a function list-nth-mod that takes a list xs and a number n. If the number is negative, terminate the computation with (error "list-nth-mod: negative number"). Else if the list is empty, terminate the computation with (error "list-nth-mod: empty list"). Else return the ith element of the list where we count from zero and i is the remainder produced when dividing n by the list’s length. Library functions length, remainder, car, and list-tailare all useful – see the Racket documentation. Sample solution is 6 lines.

**must be programmed in raccket**

Explanation / Answer

>>>>
function sequence that takes 3 arguments low, high, and stride, all assumed to be numbers
(define (sequence low high stride)
(if (> low high)
null
(cons low (sequence (+ low stride) high stride))))


>>>>>
function list-nth-mod that takes a list xs and a number n
(define (list-nth-mod xs n)
(cond [(< n 0) (error "list-nth-mod: negative number")]
[(null? xs) (error "list-nth-mod: empty list")]
[#t (let ([rem (remainder n (length xs))]) (car (list-tail xs rem)))]))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote