100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten
logo-home
CPSC110 problem set 8 solution €8,02
In winkelwagen

Overig

CPSC110 problem set 8 solution

 2 keer verkocht
  • Vak
  • Instelling

complete solution for problem set 8

Voorbeeld 2 van de 9  pagina's

  • 5 januari 2024
  • 9
  • 2023/2024
  • Overig
  • Onbekend
avatar-seller
(@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))

Dit zijn jouw voordelen als je samenvattingen koopt bij Stuvia:

Bewezen kwaliteit door reviews

Bewezen kwaliteit door reviews

Studenten hebben al meer dan 850.000 samenvattingen beoordeeld. Zo weet jij zeker dat je de beste keuze maakt!

In een paar klikken geregeld

In een paar klikken geregeld

Geen gedoe — betaal gewoon eenmalig met iDeal, creditcard of je Stuvia-tegoed en je bent klaar. Geen abonnement nodig.

Direct to-the-point

Direct to-the-point

Studenten maken samenvattingen voor studenten. Dat betekent: actuele inhoud waar jij écht wat aan hebt. Geen overbodige details!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper skye3. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €8,02. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 70113 samenvattingen verkocht

Opgericht in 2010, al 15 jaar dé plek om samenvattingen te kopen

Begin nu gratis

Laatst bekeken door jou


€8,02  2x  verkocht
  • (0)
In winkelwagen
Toegevoegd