Question: Problem 4 : [ 1 0 pts ] Define a function interleave - duplicates, which takes a list and returns a new list where each

Problem 4:
[10 pts]
Define a function interleave-duplicates, which takes a list and returns a new list where each number in the original list is duplicated immediately after itself. Nonnumber elements should remain unchanged and not be duplicated. The duplication does not apply to elements within any sublists.
\table[[Sample Input,Sample Output],['(),()],[,(1"a"2(3)),'(11"a"22(3))],['(4"b"5"c"),'(44"b"55"c")],['(1(23)4),'(11(],['(7"x"(8)9),'(77"x"(8)99)]]
Define a function nested-sum, which takes a potentially nested list of elements and returns the sum of all numerical elements. The function should recursively traverse any sublists to include their numerical elements in the sum. Non-number elements should be ignored.
\table[[Sample Input,Sample Output],['(),0],['(123),6],['(1(23)(4(5))),15],["a"(2 #f (34))"b"),10]]
Problem 4 : [ 1 0 pts ] Define a function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!