Advertisement
PaolaD

Untitled

Aug 8th, 2020
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.67 KB | None | 0 0
  1. ;;Autor: Paola Andrea Domínguez Vélez
  2. ;;Fecha: 8/08/2020
  3. ;;Contrato: buscar-mayor: lista de numeros--> numero
  4. ;;Proposito: Tomar una lista de 5 números y retornar el mayor de estos.
  5. ;;Ejemplo
  6. ;;(buscar-mayor (cons 3 (cons 4 (cons 5 (cons 6 (cons 1 empty)))))) 6)
  7. ;;(buscar-mayor (cons 9 (cons 10 (cons 50 (cons 3 (cons 5 empty)))))) 50)
  8.  
  9.  
  10. (define (buscar-mayor lstnum)
  11.   (cond
  12.     [(not (cons? lstnum)) (error "Debe ingresarse una lista de números")]
  13.     [(and (> (first lstnum) (first (rest lstnum)))
  14.           (> (first lstnum) (first (rest (rest lstnum))))
  15.           (> (first lstnum) (first (rest (rest (rest lstnum)))))
  16.           (> (first lstnum) (first (rest (rest (rest (rest lstnum))))))
  17.           ) (first lstnum)]
  18.  
  19.     [(and (> (first (rest lstnum)) (first (rest (rest lstnum))))
  20.           (> (first (rest lstnum)) (first (rest (rest (rest lstnum)))))
  21.           (> (first (rest lstnum)) (first (rest (rest (rest (rest lstnum))))))
  22.           ) (first (rest lstnum))]
  23.    
  24.     [(and  (> (first (rest (rest lstnum))) (first (rest (rest (rest lstnum)))))
  25.            (> (first (rest (rest lstnum))) (first (rest (rest (rest (rest lstnum))))))
  26.            ) (first (rest (rest lstnum)))
  27.              ]
  28.    
  29.     [(> (first (rest (rest (rest lstnum)))) (first (rest (rest (rest (rest lstnum))))))
  30.      (first (rest (rest (rest lstnum))))
  31.      ]
  32.  
  33.     [else (first (rest (rest (rest (rest lstnum)))))]
  34.     ))
  35. (check-expect (buscar-mayor (cons 3 (cons 4 (cons 5 (cons 6 (cons 1 empty)))))) 6)
  36. (check-expect (buscar-mayor (cons 9 (cons 10 (cons 50 (cons 3 (cons 5 empty)))))) 50)
  37. (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