Question: Using Racket, write a bridgely? function that takes a list of at least 3 numbers and returns #true if it is bridgely, otherwise #false. A

Using Racket, write a bridgely? function that takes a list of at least 3 numbers and returns #true if it is bridgely, otherwise #false. A list of numbers is called "bridgely" if it contains at least 3 numbers, and every number in the list, except for the first and the last, is greater than both the first and the last number.

Thus, these lists are bridgely: (list 1 2 3 4 5 6 5 4 3 2 1) (list 0 4 4 4 4 4 2)

And these are not: (list 1 2 3 4 5) (list 1 1 2 3 4 3 2 1)

HERE IS MY CODE SO FAR BUT IT IS NOT CORRECT

; List of Numbers -> Numbers ; Produces the last number of the given list (define (last-item lon) (cond [(empty? (rest lon)) (first lon)] [else (last-item (rest lon))]))

; List of Numbers -> Boolean ; Produces true if list is a bridgley and false if list is not (define (bridgely? lon) (cond [(empty? (first (first (rest lon)))) #f] [(and (< (first lon) (first (rest lon))) (< (last-item lon) (first (rest lon)))) (bridgely? (cons (first lon) (rest lon)))] [else #f]))

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 Databases Questions!