Geschrieben von Student*innen, die bestanden haben Sofort verfügbar nach Zahlung Online lesen oder als PDF Falsches Dokument? Kostenlos tauschen 4,6 TrustPilot
logo-home
Prüfung

CPSC110 Pset8 solution

Bewertung
-
Verkauft
-
seiten
8
Klasse
A
Hochgeladen auf
16-11-2025
geschrieben in
2025/2026

This is the correct and the latest solution for pset 8.

Hochschule
Kurs

Inhaltsvorschau

;​; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS​
​FILE.​
​;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU.​
​;;​
​(require spd/tags)​

​(@assignment psets/pset-08); Do not edit or remove this tag​

;​; These problems will be autograded. NOTE that, for problems 1-5, all of the​
​;; following are required. Violating one or more will cause your solution to​
​;; receive 0 marks.​
​;;​
​;; - Files must not have any errors when the Check Syntax button is pressed.​
​;; Press Check Syntax and Run often, and correct any errors early.​
​;;​
​;; - The function definition MUST call one or more built-in abstract functions.​
​;;​
​;; - For maximum credit the function definition should use the most clear​
​;; and expressive combination of abstract functions. In particular, while​
​;; it is possible to just use foldr for these problems that is not always​
​;; correct. If what is happening is a filter, then it is not correct to​
​;; just implement filtering with foldr.​
​;;​
​;; - The function definition MUST NOT be recursive.​
​;;​
​;; - The function definition MUST NOT use any part of the recursive Natural​
​;; template or the (listof X) template.​
​;;​
​;; - it must not include (cond [(empty? ... anywhere​
​;; - it must not include (cond [(zero? ... anywhere​
​;; - it must not include (if (empty? ... anywhere​
​;; - it must not include (if (zero? ... anywhere​
​;;​
​;; - The result of the function must directly be the result of one of the​
​;; built-in abstract functions. So, for example, the following is not​
​;; a valid function body:​
​;;​
​;; (define (foo x)​
​;; (empty? (filter ...)))​
​;;​
​;; - You MUST NOT change or comment out any check-expects, but you are free​
​;; to add new ones.​

(​ @problem 1)​
​;;​
​;; Design a function called sum-squares that consumes a list of naturals,​
​;; and produces the sum of squaring all of the naturals in the list.​
​;;​

, ;​; For example: (sum-squares (list 5 2 4)) produces 45.​
​;;​
​;; Your function definition must use built-in abstract functions.​
​;; For full marks it must be a composition of exactly 2 built-in​
​;; abstract functions.​
​;;​

(​ @htdf sum-squares)​
​(@signature (listof Natural) -> Natural)​
​;; produce the sum of squaring all of the numbers in lon​
​(check-expect (sum-squares empty) 0)​
​(check-expect (sum-squares (list 5 2 4))​
​(+ (sqr 5) (sqr 2) (sqr 4)))​

​(@template-origin fn-composition use-abstract-fn)​

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


(​ @problem 2)​
​;;​
​;; Complete the design of the following function.​
​;;​
​;; Your function definition must use built-in abstract functions.​
​;; For full marks it must be a composition of exactly 2 built-in​
​;; abstract functions.​
​;;​
​;; NOTE: Looking up the function 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 letter 'a' contain word w​
​(check-expect (all-a-contain? empty "word") true)​
​(check-expect (all-a-contain? (list "bicycle" "car" "train" "walk")​
​"transportation")​
​true)​
​(check-expect (all-a-contain? (list "assignment") "eight") false)​
​(check-expect (all-a-contain? (list "attend" "radio" "antenna" "listen" "study")​
​"ten")​
​true)​
​(check-expect (all-a-contain? (list "art" "bin" "action" "tin") "in") false)​
​(check-expect (all-a-contain? (list "art" "artery" "ban" "action" "tin")​
​"art")​
​false)​

​(@template-origin fn-composition use-abstract-fn)​

Schule, Studium & Fach

Hochschule
Studium
Kurs

Dokument Information

Hochgeladen auf
16. november 2025
Anzahl der Seiten
8
geschrieben in
2025/2026
Typ
Prüfung
Enthält
Fragen & Antworten

Themen

$10.32
Vollständigen Zugriff auf das Dokument erhalten:

Falsches Dokument? Kostenlos tauschen Innerhalb von 14 Tagen nach dem Kauf und vor dem Herunterladen kannst du ein anderes Dokument wählen. Du kannst den Betrag einfach neu ausgeben.
Geschrieben von Student*innen, die bestanden haben
Sofort verfügbar nach Zahlung
Online lesen oder als PDF

Lerne den Verkäufer kennen
Seller avatar
06shyun1211

Lerne den Verkäufer kennen

Seller avatar
06shyun1211 University of British Columbia
Folgen Sie müssen sich einloggen, um Studenten oder Kursen zu folgen.
Verkauft
1
Mitglied seit
4 Jahren
Anzahl der Follower
0
Dokumente
8
Zuletzt verkauft
3 Jahren vor

0.0

0 rezensionen

5
0
4
0
3
0
2
0
1
0

Beliebte Dokumente

Kürzlich von dir angesehen.

Warum sich Studierende für Stuvia entscheiden

on Mitstudent*innen erstellt, durch Bewertungen verifiziert

Geschrieben von Student*innen, die bestanden haben und bewertet von anderen, die diese Studiendokumente verwendet haben.

Nicht zufrieden? Wähle ein anderes Dokument

Kein Problem! Du kannst direkt ein anderes Dokument wählen, das besser zu dem passt, was du suchst.

Bezahle wie du möchtest, fange sofort an zu lernen

Kein Abonnement, keine Verpflichtungen. Bezahle wie gewohnt per Kreditkarte oder Sofort und lade dein PDF-Dokument sofort herunter.

Student with book image

“Gekauft, heruntergeladen und bestanden. So einfach kann es sein.”

Alisha Student

Häufig gestellte Fragen