CS 111 Quiz 2 GOD HELP ME

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

30 Terms

1
New cards

(iterated-above (lambda (i) (circle 20 "solid" "blue")) 4)

Give an example of an iterated image function

2
New cards

(lambda (n) immediately after the iterated function itself

What MUST be included in (iterated-above/below/overlay) for it to be valid?

3
New cards

Bullseye, starts at 0 with an invisible circle. (* 10 (+ i 1)) calculates the radius, making it dependent on the iteration index i

What does this produce, and which part of the function allows that?

(iterated-overlay

(lambda (i) (circle (* 10 (+ i 1)) "solid" "purple"))

5)

4
New cards

(interpolate-colors (color 255 0 0) (color 0 0 255) 0.6)

Use interpolate-colors to write a mix of 40% red and 60% blue

5
New cards

Defining the radius to be dependent on a input variable n, multiplying it by 10 and then adding 10 to it.

What is this function doing:

(define (ring-radius n)

(+ 10 (* 10 n)))

6
New cards

(check-expect (function-call...) expected-result)

Give the general format of a check expect function

7
New cards

To store multiple values together under one name

What is the purpose of a list?

8
New cards

Define only accepts one expression for the value. Therefore, we must wrap the several elements inside one element (list).

(define num-list (list 2 3 4 5 6))

(check-expect num-list (list 2 3 4 5 6))

Identify, explain, and fix the mistake in this list

(define num-list 2 3 4 5 6)

9
New cards

List is not a function, hence no parenthesis. (list num-list) is a function to create a new list.

(check-expect (list? num-list) true)

Identify, explain, and fix the mistake

(check-expect (list num-list) true)

10
New cards

Applying a function to every element in a list. Produces a new list. Maps everything to a new list.

What is the purpose of the map function?

11
New cards

(map (lambda (x) (expression using x) list)

Give the general syntax of the map function, which returns a new list after a function has been applied to every element in a list.

12
New cards

Multiplication is a function, hence needs to be preceded by parenthesis.

(map (lambda (x) (* 5 x)) (list 1 2 3))

Fix and explain the mistake with the "map" function that returns a new list after a function is applied to every element in the list

(map * 5 (list 1 2 3))

13
New cards

Multiplication cannot multiply a number by an entire list. The first argument must be a function like lambda, or something else which can take multiple arguments.

Fix and explain the mistake with the "map" function that returns a new list after a function is applied to every element in the list

(map (* 5 (list 1 2 3)))

14
New cards

Map must ALWAYS have list as the last argument. The function is defined but there is no new list created, since 1 2 3 are not defined as lists. They are just numbers floating around, and lambda cannot be called with all of them as the input for x.

(map (lambda (x) (* x 5)) (list 1 2 3))

Fix and explain the mistake

(map (lambda (x) (* x 5)) 1 2 3)

15
New cards

To modify a pre-existing list, to keep only list elements for which a condition is true

Define the purpose of the filter function?

16
New cards

(filter (lambda (x) insert-boolean-expression-here, either mathematically or true?) (list elements of list))

Write the general syntax for a filter function

17
New cards

The boolean function does not define what is being compared to 3.

(filter (lambda (x) (> x 3)) (list 1 2 3 4)

Explain and fix

(filter (lambda (x) (> 3)) (list 1 2 3 4))

18
New cards

Lambda only takes one boolean and only one input. If multiple booleans are inserted, they must be combined and wrapped with and or.

(filter (lambda (x) (or (= x 2) (> x 5))) (list 1 2 3 4 6))

Explain and fix

(filter (lambda (x) (= x 2) (> x 5)) (list 1 2 3 4 6))

19
New cards

To combine all the elements of a list into a single value

What is the purpose of foldl

20
New cards

(foldl (lambda function start-value (initial list))

Give the general format of foldl

21
New cards

(foldl + 0 (list 1 2 3 )) outputs 6

Give a correct syntax example of foldl

22
New cards

No start value is provided. 0 is the start value for sums, 1 is the start value for products.

(foldl + 0 (list 1 2 3))

Fix and explain

(foldl + (list 1 2 3))

23
New cards

No parenthesis necessary when passing a function as an argument to another function, which is meant to take in a function. Only necessary when nesting another function as an input.

Why no parenthesis before the plus?

(foldl + (list 1 2 3))

24
New cards

10, since 4 is the start value aka the accumulator

What would this produce?

(foldl + 4 (list 1 2 3))

25
New cards

Foldl always accepts 2 arguments: current list element, and accumulator. The lambda in this only takes 1 argument. Acc is undefined, since it isn't defined as a parameter of lambda. Acc means accumulator, where it starts, and the value it combines with x.

(foldl (lambda x acc) (+ x acc)) 5 (list 1 2 3))

x = 5

accumulator = (list 1 2 3)

Fix and explain

(foldl (lambda (x) (+ x acc)) 0 (list 1 2 3))

26
New cards

To test if all the elements of a list satisfy a condition

What is the purpose of the function andmap?

27
New cards

(andmap (lambda (x) (< x 3)) (list 1 2))

Write a correct example of andmap

28
New cards

One boolean value, true or false

What is the output of an andmap function?

29
New cards

Passing 3 separate arguments to lambda when it only accepts 1. Needs to combine 1 2 and 3 into a list.

(andmap (lambda (x) (< x 3)) (list 1 2 3))

Fix this andmap mistake

(andmap (lambda (x) (< x 3)) 1 2 3)

30
New cards

Only one expression can be passed for lambda.

(andmap (lambda (x) (and ( x 0)) (list 1 2 3))

Fix this andmap mistake

(andmap (lambda (X) (< x 3) (> x 0)) (list 1 2 3))