Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Autor: Paola Andrea Domínguez Vélez
- ;;Fecha: 8/08/2020
- ;;Contrato: buscar-mayor: lista de numeros--> numero
- ;;Proposito: Tomar una lista de 5 números y retornar el mayor de estos.
- ;;Ejemplo
- ;;(buscar-mayor (cons 3 (cons 4 (cons 5 (cons 6 (cons 1 empty)))))) 6)
- ;;(buscar-mayor (cons 9 (cons 10 (cons 50 (cons 3 (cons 5 empty)))))) 50)
- (define (buscar-mayor lstnum)
- (cond
- [(not (cons? lstnum)) (error "Debe ingresarse una lista de números")]
- [(and (> (first lstnum) (first (rest lstnum)))
- (> (first lstnum) (first (rest (rest lstnum))))
- (> (first lstnum) (first (rest (rest (rest lstnum)))))
- (> (first lstnum) (first (rest (rest (rest (rest lstnum))))))
- ) (first lstnum)]
- [(and (> (first (rest lstnum)) (first (rest (rest lstnum))))
- (> (first (rest lstnum)) (first (rest (rest (rest lstnum)))))
- (> (first (rest lstnum)) (first (rest (rest (rest (rest lstnum))))))
- ) (first (rest lstnum))]
- [(and (> (first (rest (rest lstnum))) (first (rest (rest (rest lstnum)))))
- (> (first (rest (rest lstnum))) (first (rest (rest (rest (rest lstnum))))))
- ) (first (rest (rest lstnum)))
- ]
- [(> (first (rest (rest (rest lstnum)))) (first (rest (rest (rest (rest lstnum))))))
- (first (rest (rest (rest lstnum))))
- ]
- [else (first (rest (rest (rest (rest lstnum)))))]
- ))
- (check-expect (buscar-mayor (cons 3 (cons 4 (cons 5 (cons 6 (cons 1 empty)))))) 6)
- (check-expect (buscar-mayor (cons 9 (cons 10 (cons 50 (cons 3 (cons 5 empty)))))) 50)
- (check-expect (buscar-mayor (cons 10 (cons 20 (cons 40 (cons 60 (cons 3 empty)))))) 60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement