Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;EJERCICIO 1:
- (check-expect (pares (list 0 1 2 3 4 5 6 7 8 9)) (list 0 2 4 6 8))
- (check-expect (pares (list 1 3 5)) empty)
- (define (pares l) (cond [(empty? l) empty]
- [(= (remainder (first l) 2) 0) (cons (first l) (pares (rest l)))]
- [else (pares (rest l))]))
- ;EJERCICIO 2:
- (check-expect (cortas (list "Lista" "de" "palabras" "sin" "sentido")) (list "de" "sin"))
- (define (cortas l) (cond [(empty? l) empty]
- [(< (string-length (first l)) 5) (cons (first l) (cortas (rest l)))]
- [else (cortas (rest l))]))
- ;EJERCICIO 3:
- (define MAX 5)
- (define (dist-origen n) (sqrt (+ (sqr (posn-x n)) (sqr (posn-y n)))))
- (check-expect (cerca (list (make-posn 3 5) (make-posn 1 2) (make-posn 0 1) (make-posn 5 6))) (list (make-posn 1 2) (make-posn 0 1)))
- (define (cerca l) (cond [(empty? l) empty]
- [(< (dist-origen (first l)) MAX) (cons (first l) (cerca (rest l)))]
- [else (cerca (rest l))]))
- ;EJERCICIO 4:
- (check-expect (positivos (list -5 37 -23 0 12)) (list 37 12))
- (define (positivos l) (cond [(empty? l) empty]
- [(> (first l) 0) (cons (first l) (positivos (rest l)))]
- [else (positivos (rest l))]))
- ;EJERCICIO 5:
- (check-expect (raices (list 9 16 4)) (list 3 4 2))
- (define (raices l) (cond [(empty? l) empty]
- [else (cons (sqrt (first l)) (raices (rest l)))]))
- ;EJERCICIO 6:
- (define (dist-origen n) (sqrt (+ (sqr (posn-x n)) (sqr (posn-y n)))))
- (check-expect (distancias (list (make-posn 3 4) (make-posn 0 4) (make-posn 12 5))) (list 5 4 13))
- (define (distancias l) (cond [(empty? l) empty]
- [else (cons (dist-origen (first l)) (distancias (rest l)))]))
- ;EJERCICIO 7:
- (check-expect (anchos (list (circle 30 "solid" "red") (rectangle 10 30 "outline" "blue"))) (list 60 10))
- (define (anchos l) (cond [(empty? l) empty]
- [else (cons (image-width (first l)) (anchos (rest l)))]))
- ;EJERCICIO 8:
- (define (sgn2 x) (cond [(< x 0) -1]
- [(= x 0) 0]
- [else 1]))
- (check-expect (signos (list 45 32 -23 0 12)) (list 1 1 -1 0 1))
- (define (signos l) (cond [(empty? l) empty]
- [else (cons (sgn2 (first l)) (signos (rest l)))]))
- ;EJERCICIO 9:
- (check-expect (prod (list 1 2 3 4 5)) 120)
- (define (prod l) (cond [(empty? l) 1]
- [else (* (first l) (prod (rest l)))]))
- ;EJERCICIO 10:
- (check-expect (pegar (list "Las " "lis" "tas " "son " "complicadas" ".")) "Las listas son complicadas.")
- (define (pegar l) (cond [(empty? l) ""]
- [else (string-append (first l) (pegar (rest l)))]))
- ;EJERCICIO 11:
- (check-expect (maximo (list 23 543 325 0 75)) 543)
- (define (mayor a b) (if (> a b) a b))
- (define (maximo l) (cond [(empty? l) 0]
- [else (mayor (first l) (maximo (rest l)))]))
- ;EJERCICIO 12:
- (check-expect (sum-dist (list (make-posn 3 4) (make-posn 0 4) (make-posn 12 5))) 22)
- (define (dist-origen n) (sqrt (+ (sqr (posn-x n)) (sqr (posn-y n)))))
- (define (sum-dist l) (cond [(empty? l) 0]
- [else (+ (dist-origen (first l)) (sum-dist (rest l)))]))
- ;EJERCICIO 13:
- (check-expect (sumcuad (list 1 2 3)) 14)
- (define (sumcuad l) (cond [(empty? l) 0]
- [else (+ (sqr (first l)) (sumcuad (rest l)))]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement