1. Homepage
  2. Exam
  3. CS440 Programming Languages - Midterm Exam - Part 1: Recursion and lists

CS440 Programming Languages - Midterm Exam - Part 1: Recursion and lists

This question has been solved
Engage in a Conversation

CS 440 Midterm Exam (Take-Home) CourseNana.COM

This midterm exam consists of 7 separate exercises --- 3 on recursion and lists, 3 on higher order functions, and 1 involving an addition to an interpreter. They are described below: CourseNana.COM

Part 1: Recursion and lists CourseNana.COM

flatten-1: takes a list and "flattens" any nested lists by one level. E.g., > (flatten-1 '(a (b c) d))
'(a b c d)
CourseNana.COM

> (flatten-1 '((a) (b ((c) (d))) ((e f)))) '(a b ((c) (d)) (e f)) CourseNana.COM

> (flatten-1 (flatten-1 '((a) (b ((c) (d))) ((e f))))) '(a b (c) (d) e f) CourseNana.COM

> (flatten-1 (flatten-1 (flatten-1 '((a) (b ((c) (d))) ((e f)))))) '(a b c d e f) CourseNana.COM

CourseNana.COM

riffle takes one or more lists and "riffles" (shuffles) their contents together in CourseNana.COM

alternating fashion into one single list. E.g., CourseNana.COM

> (riffle '(a b) '(1 2 3 4) '(u v w x y z)) '(a 1 u b 2 v 3 w 4 x y z) CourseNana.COM

> (riffle (range 5) (range 6 10) (range 10 15)) '(0 6 10 1 7 11 2 8 12 3 9 13 4 14) CourseNana.COM

CourseNana.COM

wordle takes two strings -- a solution and guess (a la Wordle) -- and returns a list of clues that indicate which characters in the guess are in the correct spot (*), which match a character from the solution but are in the incorrect spot (+), and which don't match any solution characters at all (_).
Correct-spot characters are given precedence, and incorrect-spot characters are matched from left to right. You should assume that the solution and guess are the same
CourseNana.COM

length. E.g., CourseNana.COM

> (wordle "CATCH" "PARCH") '(_ * _ * *) CourseNana.COM

> (wordle "FASTER" "STREAK") '(+ + + + + _) CourseNana.COM

> (wordle "SWEETLY" "TWENTYS") '(_ * * _ * + +) CourseNana.COM


You may find it useful to use the
string->list function, which takes a string and returns a list of characters (which you can compare using eq?). You may also find for (or a variant) helpful, though not necessary. CourseNana.COM


CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
IIT代写,US代写,CS440代写,CS 440代写,Programming Languages代写,Racket代写,IIT代编,US代编,CS440代编,CS 440代编,Programming Languages代编,Racket代编,IIT代考,US代考,CS440代考,CS 440代考,Programming Languages代考,Racket代考,IIThelp,UShelp,CS440help,CS 440help,Programming Languageshelp,Rackethelp,IIT作业代写,US作业代写,CS440作业代写,CS 440作业代写,Programming Languages作业代写,Racket作业代写,IIT编程代写,US编程代写,CS440编程代写,CS 440编程代写,Programming Languages编程代写,Racket编程代写,IITprogramming help,USprogramming help,CS440programming help,CS 440programming help,Programming Languagesprogramming help,Racketprogramming help,IITassignment help,USassignment help,CS440assignment help,CS 440assignment help,Programming Languagesassignment help,Racketassignment help,IITsolution,USsolution,CS440solution,CS 440solution,Programming Languagessolution,Racketsolution,