2025-11-20 Basics Quiz
Culmination of review. Takes 25 minutes.
-
Define a new data type
Plantthat can hold either (Thistle) or (Dandelionwith anIntfield callednumand aStringfield calledflavor). -
A field contains a list of
Plant. EachThistlesubtracts 0.50 from the value of the field.Dandelionsadd 1.25 times the num of each.landValue :: [Plant] -> Double- Write a recursive version.
- Write a version that uses list comprehension.
-
In springtime, thistles double in number and dandelions triple. Write a recursive function to make a new list:
spring :: [Plant] -> [Plant] d = Dandelion 4 "bitter" check_spring = [ spring [Thistle] == [Thistle, Thistle] ,spring [d] == [d,d,d]] -
(Refers to work from 2021 AoC 4.) True if any row (inner list) has all negative numbers.
hwin :: [Int] -> Bool check_hwin = [ hwin [[1,3,2],[-4,-5,-6]] == True ,hwin [[-1,1,-1]] == False ] -
Get feedback on question 4 and write it another way. Recursion, list comprehension, higher order function.