Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien 4.2 TrustPilot
logo-home
Autre

CPSC110 problem set 8 solution

Note
-
Vendu
2
Pages
9
Publié le
05-01-2024
Écrit en
2023/2024

complete solution for problem set 8

Établissement
Cours









Oups ! Impossible de charger votre document. Réessayez ou contactez le support.

École, étude et sujet

Établissement
Cours
Cours

Infos sur le Document

Publié le
5 janvier 2024
Nombre de pages
9
Écrit en
2023/2024
Type
Autre
Personne
Inconnu

Sujets

Aperçu du contenu

(@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))
7,43 €
Accéder à l'intégralité du document:

Garantie de satisfaction à 100%
Disponible immédiatement après paiement
En ligne et en PDF
Tu n'es attaché à rien

Faites connaissance avec le vendeur
Seller avatar
skye3

Faites connaissance avec le vendeur

Seller avatar
skye3 UBC
S'abonner Vous devez être connecté afin de pouvoir suivre les étudiants ou les formations
Vendu
5
Membre depuis
1 année
Nombre de followers
1
Documents
9
Dernière vente
1 année de cela

0,0

0 revues

5
0
4
0
3
0
2
0
1
0

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions