Ch 02 Quiz 6
-
(
cm
) Given a list of letters and a list of words, total of 1 for each element in the first list that appears in somewhere the corresponding word from the second list.cm ['a','p','e','s'] ["apple","grade","reach","bonus"] == 3
Explanation I:
The letter
'a'
corresponds to the word"apple"
, so contributes one to the total. The letter'p'
does not appear in the corresponding word"grade"
, contributes zero to the total.Explanation II:
Letter Word Contribution a apple 1 p grade 0 e leech 1 s bonus 1 The final result is 1 + 0 + 1 + 1 = 3.
-
(
rmake
) Given a list of strings (“colors”) and a list of strings (“modes”), produce a list of strings of the form(rectangle 100 20 MODE COLOR)
.rmake ["orange","blue"] ["outline","solid"] == ["(rectangle 100 20 outline orange)", "(rectangle 100 20 solid ornage)", "(rectangle 100 20 outline blue)", "(rectangle 100 20 solid blue)"]
-
(
s20
) Given a list of Int, produce the shortest sub-list you can, starting at the beginning and ending as soon as the total is above 20. If the total is never above 20, the result is the whole list.s20 [1,2,3] == [1,2,3] s20 [1,2,3,10,7,13,14,15] == [1,2,3,10,7] s20 [0,20,1,2,3] == [0,20,1]
Explanation: In the second example, 1+2+3+10 = 16, but adding the next number gives 16+7=23. In the third example, 0+20 is not above 20, so it takes one more number.