100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Otro

CPSC110 problem set 8 solution

Puntuación
-
Vendido
2
Páginas
9
Subido en
05-01-2024
Escrito en
2023/2024

complete solution for problem set 8

Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
5 de enero de 2024
Número de páginas
9
Escrito en
2023/2024
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

(@problem 1)
;;
;; Complete the design of a func:on called sum-squares that consumes a list
;; of natural numbers and produces the sum of squaring all of the naturals
;; in the list.
;;
;; For example: (sum-squares (list 5 2 4)) produces 45.
;;
;; Your func:on defini:on must use built-in abstract func:ons.
;; For full marks it must be a composi:on of exactly 2 built-in
;; abstract func:ons.
;;

(@htdf sum-squares)
(@signature (listof Natural) -> Natural)
;; produce sum of squaring all of naturals in lon
(check-expect (sum-squares empty) 0)
(check-expect (sum-squares (list 1 2 3))
(+ (sqr 1) (sqr 2) (sqr 3)))

;(define (sum-squares lon) empty)

(@template-origin fn-composi:on
use-abstract-fn)

(define (sum-squares lon)
(foldr + 0 (map sqr lon)))


(@problem 2)
;;
;; Complete the design of the following func:on.
;;
;; Your func:on defini:on must use built-in abstract func:ons.
;; For full marks it must be a composi:on of exactly 2 built-in
;; abstract func:ons.
;;
;; NOTE: Looking up the func:on string-contains? in the help desk
;; might be helpful...

(@htdf all-a-contain?)
(@signature (listof String) String -> Boolean)
;; determine if all strings that begin with the leUer 'a' contain word w
(check-expect (all-a-contain? empty "word") true)

, (check-expect (all-a-contain? (list "bicycle" "car" "train" "walk")
"transporta:on")
true)
(check-expect (all-a-contain? (list "assignment") "eight") false)
(check-expect (all-a-contain? (list "aUend" "radio" "antenna" "listen" "study")
"ten")
true)
(check-expect (all-a-contain? (list "art" "bin" "ac:on" ":n") "in") false)
(check-expect (all-a-contain? (list "art" "artery" "ban" "ac:on" ":n")
"art")
false)

;(define (all-a-contain? los w) false) ;stub

(@template-origin fn-composi:on
use-abstract-fn)

(define (all-a-contain? los w)
(local [(define (contain-word? s)
(string-contains? w s))
(define (start-with-a? s)
(string=? "a" (string-ith s 0)))]
(andmap contain-word? (filter start-with-a? los))))



(@problem 3)
;;
;; Before comple:ng problems 3, 4, and 5, please familiarize
;; yourself with the provided data defini:on for a Cat.
;; An example (listof Cat) is also provided.
;;

(@htdd Cat)
(define-struct cat (name color age))
;; Cat is (make-cat String Color Natural)
;; interp. a cat with a name, coat color, and age (in years)
(define C1 (make-cat "Whiskers" "brown" 13))
(define C2 (make-cat "Si" "black" 4))
(define C3 (make-cat "Am" "white" 4))
(define C4 (make-cat "Meow" "brown" 7))
(define C5 (make-cat "Garfield" "orange" 8))
(define C6 (make-cat "Sassy" "brown" 6))
$8.48
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
skye3

Conoce al vendedor

Seller avatar
skye3 UBC
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
5
Miembro desde
1 año
Número de seguidores
1
Documentos
9
Última venta
1 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes