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

I have spent close to 10 hours trying to figure this out and I literally just gi

ID: 3703773 • Letter: I

Question

I have spent close to 10 hours trying to figure this out and I literally just give up at this point. Please help! FYI this is in DrRacket

3. diginlist - takes a list and returns the “diggedin” version of the list. “diggingin” a list

( this is not a recognized function for list ) means surrounding the rightmost and leftmost elements in

parenthesis, and repeating the process inwards until the entire list is “diggedin”. For example:

(diginlist '(4 5 3 2 8)) would return (4 (5 (3) 2) 8).

You can assume that the input list is "flat", meaning that it doesn't contain any lists. If the input

list has an odd number of elements, the center element should be in a list by itself, as shown in

the example above. If the input list has an even number of elements, then there should be an

empty list in the middle. For example:

(diginlist '(4 5 2 8) would return (4 (5 () 2) 8)).

Here is as far as I got:

(define (diginlistHelper N L NL)
          (cond
          ((= N 0) '()
          ((= N 1) (cons (list (car L)) NL))
          (else (cons (cons (car L) (list (lastItem L))) NL)
                (remove 1 L)
                )
          )
        )
)

(define (diginlist L)
        (define length (listLength L))   
        (define L2 (diginlistHelper length L '() ))
        (define L3 (diginlistHelper (- length 2) L L2 ))
        L3
)

(define (lastItem L)
        (if (null? (cdr L))(car L)
            (lastItem (cdr L)))
)

(define (remove N L)
(cond ((eq? N 0) (cdr L))
        (else (cons (car L) (remove (- N 1)(cdr L)))))
)

Explanation / Answer

Although I don't have knowledge of DrRacket so I can't help directly with the code but heres the logic/algorithm you need to follow:

1. Let "i" be the starting index and "j" be the end index.

2. Now keep on putting a '(' after i and increment "i" by 1.

3. Keep on putting a ')' before j and decrement "j" by 1.

4. Repeat the process till j>=i.

-------

This might not be the answer you were looking for but your desperate call for help made me answer this :P