Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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))))) )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is a concept test?

Answered: 1 week ago

Question

=+Trainers from headquarters? Local trainers? Independent trainers?

Answered: 1 week ago