Question 1: Padding Strings
Write a function (pad-to-same los) that consumes a (listof Str), and “pads” the values by adding as many “.” as necessary to make all values as long as the
For example,
1 (check-expect (pad-to-same (list
Copyright By PowCoder代写 加微信 powcoder
(check-expect (pad-to-same (list
“TANSTAAFL!”))
“TANSTAAFL!”))
Your solution for this question must use locally defined constants and locally defined functions properly. Your solution should avoid any unnecessary slowdown
such as unnecessary repeated recursive calls. Specifically, your function should be able to run on lists of 10000 (or more) numbers and complete in a very short
amount of time. For example, running
(length (pad-to-same (build-list 10000 number->string)))
should easily finish within 5 seconds. Hint: Concept Check 8.2.2 will be extremely helpful in this regard. You are not allowed to use sort in this question.
Save your code in a file called a07q1.rkt and submit it to MarkUs.
Question 2: Recurrence Relations
Recurrence relations are mathematical functions that have a recursive component to their definitions. One of the most famous recurrence relations is the definition
of a Fibonacci number, which can be defined as follows:
For this question, you will be asked to calculate a Qux number, which we define with the following recurrence relation:
when n > 2 and O (n – 1) is even
when n ≥ 2 and Q (n – 1) is odd
Write a recursive function qux that consumes one natural number and produces the Qux number as defined by the recurrence relation above. The function must be
efficient. Look to use local expressions to ensure this.
For example,
> (remainder (qux 1234) 1000000)
You can test the efficiency by trying different values of n. An inefficient solution will not be able to calculate a Qux number of a 4-digit number in any reasonable
amount of time. In fact, inefficient solutions will take an unreasonable amount of time with much smaller values for n.
Note: For those who have studied recurrence relations in mathematics, do not attempt to find a closed-form solution for the Qux function. Your solution must be
recursive.
Question 3: Sorting
Write a function (even-up-odd-down loi) that consumes a (listof Int), and produces the same items, sorted so it starts with even numbers, in increasing
order, then has odd numbers, in decreasing order. Use the sort function to accomplish this. For example,
> (even-up-odd-down (list 11 7 1 3 10 6 5 2 8))
(list 2 6 8 10 11 7 5 3 1)
You should not use insertion sort or merge sort to solve this problem. Instead, use a single call to the built-in function sort along with a locally defined comparison
Save your code in a file called a07q3.rkt and submit it to MarkUs.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com