CS 3 Midterm 1 Review

Similar documents
Introduction to Probability Exercises

PROFESSOR: I'd like to welcome you to this course on computer science. Actually, that's a terrible way to start.

Introduction. Survey. elllo.org

The basics I have been studying for hours!

Tell me more about yourself

Math 81 Graphing. Cartesian Coordinate System Plotting Ordered Pairs (x, y) (x is horizontal, y is vertical) center is (0,0) Quadrants:

Histograms and Frequency Polygons are statistical graphs used to illustrate frequency distributions.

A1 Personal (Subject) Pronouns

Splendid Speaking Podcasts

Time out. Module. Discuss: What do you usually do in your free time? What kind of music/films do you like? What s in this module?

Emma Heyderman, Fiona Mauchline. Workbook

KEY ENGLISH TEST for Schools. Reading and Writing 0082/01 SAMPLE TEST 3. Time. 1 hour 10 minutes

EXPRESSIONS FOR DISCUSSION AND DEBATE

On the weekend UNIT. In this unit. 1 Listen and read.

Yearbook Critique Assignment

Jay Carmen Amy Bob Joseph Cameron. average build average height fair hair long dark hair old overweight short gray hair slim tall young

All About the Real Me

Doing Things. Warm-up exercises. Exercise 1. Exercise 2. Exercise 3. What s John doing? What s Mary doing? What are you doing?

READ THE TEXT AND FOCUS ON SIGNAL WORDS

eats leaves. Where? It

A Fourth Grade Nevada Sparkler

Programs. onevent("can", "mousedown", function(event) { var x = event.x; var y = event.y; circle( x, y, 10 ); });

Ten-Minute Grammar VERBALS. LITERATURE: This unit contains example selections from the novel Fallen Angels by Walter Dean Meyers.

Maths Join up the numbers from 1 to 20

Ratios. How are the numbers in each ad compared? Which ads are most effective?

EPISODE 8: CROCODILE TOURISM. Hello. Welcome again to Study English, IELTS preparation. I m Margot Politis.

Quiz 4 Practice. I. Writing Narrative Essay. Write a few sentences to accurately answer these questions.

1 Unit friendship TEST. Vocabulary. 6. A:... is the party going to start? B: At three.

BBC LEARNING ENGLISH 6 Minute English Football songs

LISTENING COMPREHENSION

Food Idioms WHICH IDIOM BEST DESCRIBES THESE PEOPLE?

BBC to put programs online

Units 1 & 2 Pre-exam Practice

Student Involvement Worksheet Lesson 1: Voiced and Voiceless

Teenagers. board games considerate bottom of the ninth inning be supposed to honest lessons study habits grand slam be bummed out work on

Lists: A list, or series, needs three or more items before a comma is necessary

MATH 195: Gödel, Escher, and Bach (Spring 2001) Notes and Study Questions for Tuesday, March 20

01- Read the article about adaptive technology and write T for true, F for false and DS for doesn't say. Text 1

Let s Be Friends. I have difficulty remembering people s names. I usually wait for others to introduce themselves to me first.

In the questions below you must rearrange the words so that each sentence makes sense.

Back to School Themed

Sentences. A sentence is a group of words that tells a complete thought. A sentence always tells who or what

What He Left by Claudia I. Haas. MEMORY 2: March 1940; Geiringer apartment on the terrace.

Hook: Attention Grabber. General Information: Title, Author, Genre. Book Content: (describe main characters, setting, conflict)

REVIEW: SENTENCE ADVERBS

Studium Języków Obcych

Look at the pictures. Correct the three mistakes in each description.

Go BEARS~ What are Machine Structures? Lecture #15 Intro to Synchronous Digital Systems, State Elements I C

Reading On The Move. Reasoning and Logic

Lesson 12: Infinitive or -ING Game Show (Part 1) Round 1: Verbs about feelings, desires, and plans

Support materials. Elementary Podcast Series 02 Episode 05

Written by Judy Blume Illustrated by Sonia O. Lisker Packet by Kiley and Anisa Kyrene de las Brisas Elementary School April 2001

Connected TV Definitions. A new set of terms for a new type of channel

ENGL 1302: CH. 3 & 5; INTRO. TO EXPLAINING ISSUE ESSAY

LearnEnglish Elementary Podcast Series 02 Episode 08

CPSC 121: Models of Computation. Module 1: Propositional Logic

TRUE+WAY ASL Workbook Unit 6.1

Man angry at English on Japanese TV

1 I don t watch television. (often) 2 There are sports programmes on, and I hate sport! (always) 3 I watch films, but only once or twice a week.

Lesson 13 Teens online

MITOCW mit-6-00-f08-lec17_300k

ENGLISH FILE Pre-intermediate

ENGLISH FILE Beginner

1. According to the video are these sentences true or false?

Same and Different. Think and Discuss

Elementary Podcast 2-5 Transcript

UNIT 3 3º E.S.O. MATCH THE FIRST PART OF A SENTENCE IN A WITH THE END OF A SENTENCE IN B. A

TROPHIES & INSERTS. Blaze Trophies $16.95 $19.95 $17.95 $12.95 $16.95 $32.95 $ Also available in: TKB " TKB " TKB "

MIT Alumni Books Podcast The Proof and the Pudding

************************************************

Google delays book scanning

The 50 must-see children s films

examples describing a person essay example essay

Algebra I Module 2 Lessons 1 19

DIRECTIONS: Answer the questions I N COMPLETE SENTENCES on your own paper.

Use these toppers with trophy styles on pages 3-7 of this catalogue series, (pages 53-55, 85-86).

Copyright 2013 Pearson Education, Inc.

Getting Graphical PART II. Chapter 5. Chapter 6. Chapter 7. Chapter 8. Chapter 9. Beginning Graphics Page Flipping and Pixel Plotting...

Voices of Lebanon Valley College 150th Anniversary Oral History Project. Lebanon Valley College Archives Vernon and Doris Bishop Library

English File 3. File Test 1. American. 3 Complete the sentence. Use be going to, will, or the present continuous and the verb in parentheses.

Gerunds & Infinitives. Week 14, Mon 11/23/15 Todd Windisch, Fall 2015

BBC to put programs online

Let s Chat. Unit In this unit you will learn how to carry out a conversation in English by using a conversation structure.

CRONOGRAMA DE RECUPERAÇÃO ATIVIDADE DE RECUPERAÇÃO

Module 1 Our World. Ge Ready. Brixham Youth Club Come and join us! 1 Look at the information about a Youth Club. Write the words for activities.

BOOKS TO TREASURE 2014 GRADE LEVEL: 2. Books to Treasure PAGE 1 OF 12 GRADE LEVEL: 2

S3 Long Term Curriculum Plan

Relationships Between Quantitative Variables

Grammar: Comparative adjectives Superlative adjectives Usage: Completing a report

The Language Revolution Russell Marcus Fall Class #7 Final Thoughts on Frege on Sense and Reference

Topics in Linguistic Theory: Propositional Attitudes

superlative adjectives e + er or est consonant + er or est (after one vowel + one consonant) y to i + er or est

COMP sequential logic 1 Jan. 25, 2016

Note: Please use the actual date you accessed this material in your citation.

She really likes him!

Romeo. Juliet. and. When: Where:

STYLE. Sample Test. School Tests for Young Learners of English. Form A. Level 1

Favorite Things Nouns and Adjectives

UNIT 13: STORYTIME (4 Periods)

Anna is at her office today where a report about a pop concert. 5 On Friday Anna was at a concert to listen to a new group. Her brother phoned her.

Transcription:

CS3 Sp07- MT1-review Solutions CS 3 Midterm 1 Review 1. Quick Evaluations Indicate what each of the following would return if typed into STK. If you think it would error, then please write ERROR. If you think that it would loop forever, write LOOPS. (count (sentence I am (sentence) at a cs3 review)) 7 (count (word I am (sentence) at a cs3 review)) ERROR (define (mystery wd) (or (and (vowel? (first wd)) (mystery (bf wd))) (empty? wd))) (mystery aeiou) ERROR (appearances at atbtatbtat) 0 (equal? (or this cannot be right) (and neither can this)) #t (member? bat (sentence (word bat mouse) (sentence bat mouse))) #t

(item 4 (a b c d e f g)) d (define (both-even? sent) (and (even? (first sent)) (even? (bf sent)))) (both-even? (2 4)) ERROR 2. More Celebrity Questions Recall the celebrity quiz from lab. Here is the definition, incase you have forgotten: Assume that you are working with a "celebrity" program that someone else wrote. This package gives you accessors (or selectors) to work with a "celebrity". You won't change (or even look at) those procedures, but will use them. Some of these accessors include * name, which takes a single celebrity and returns the name as a single word. For example, if you have stored a celebrity in the variable cel, (name cel) might return the word Joe. * hair-color which takes a celebrity and returns one of the words blond, brown, black, or red * the procedure movies, which returns a sentence of movies that the celebrity has been in * and many other procedures A variable that "is" a celebrity is a number that, by itself, doesn't contain any of the information (like name, etc). For instance, cel above might simply be the number 5. Only by using the accessors can the information about a celebrity be pulled out. One of the accessors written is height. It returns the height of the celebrity, in inches. For example, given a certain cel, we might find that (height cel) 68

Write a procedure average-height which takes a sentence of celebrities and returns a single number: the average height of the celebrities in the sentence. Remember, average is computed as the sum divided by total number. It is ok to use a helper procedure (define (average-height celebrities-sent) (/ (total-height celebrities-sent) (count celebrities-sent) )) (define (total-height celebrities-sent) (if (empty? celebrities-sent) 0 (+ (height (first celebrities-sent)) (total-height (bf celebrities-sent)) ))) 3. Valentines Day Matchmaking We have come up with a brilliant new method of deciding if people would be a good match for each other. We simply need four pieces of information, three of which is stored in a sentence, and those things are favorite movie, favorite sport, and favorite color. The favorite sport is stored as a single word. The favorite color is the second word of the sentence. The movie is the rest. The final piece of information is the age of each person, stored simply as a number. We need a simple predicate procedure that, given six sentences, returns true if these two people would be a good match for each other, false otherwise. A good match is defined simply as if exactly two of the three subjects are equal. If all three match, they are too similar and it won t work. If only one or none match, then they don t have enough in common and again it won t work. In any case where a good match has been found, we must make sure that the two ages are within 3 years of each other. You may find the (abs) function useful, which takes two numbers and returns the absolute value. An example call would be (good-match? (soccer blue top gun) (football green top gun) 21 23) #f (define (good-match? subjects1 subjects2 age1 age2) (cond ((> (abs (- age1 age2) 3) #f) ((and (equal? (movie subjects1) (movie subjects2)) (equal? (sport subjects1) (sport subjects2)) (equal? (color subjects1) (color subjects2))) #f) ((equal? (movie subjects1) (movie subjects2)) (or (equal? (sport subjects1) (sport subjects2)) (equal? (color subjects1) (color subjects2)))) ((equal? (sport subjects1) (sport subjects2)) (equal? (color subjects1) (color subjects2)))

)) (else #f) (define (movie subject) (bf (bf subject))) (define (sport subject) (first subject)) (define (color subject) (first (bf subject))) 4. Debugging a Biologists Work A Biologist friend of yours wrote a procedure to check if two strands of DNA of the same length have more than 2 differences in their Genetic Code. Recall that DNA can be written out as a sequence of A T G and C. (Don t worry, you don t have to remember what this means). Thus, strands with two differences might be (A T G C) (A T A T). These two strands would be considered similar. The following code was written, taking each strand as a sentence. The strands are guaranteed not to be empty when starting. a) Attempt 1 - (define (similar-strands? strand1 strand2) (and (equal? (count strand1) (count strand2)) (empty? strand1) (and (equal? (first strand1) (first strand2)) (similar-strands? (bf strand1) (bf strand2))))) The Biologist knows that this procedure doesn t allow for one error in the strands, however, whenever the biologist enters ANY strands, the program returns #f. What is wrong with this procedure? The empty? check fails because of the AND. We don t need to write the Correct Code since the Problem Didn t Ask for it. But, it is important to note that using and/or is useful for recursion. b) Attempt 2 After helping (define (similar-strands? strand1 strand2) (if (not (equal? (count strand1) (count strand2))) #f (similar-strands-helper strand1 strand2 0)))

(define (similar-strands-helper strand1 strand2 num-errors) (cond 1. ((empty? strand1) #t) 2. ((> num-errors 2) #f) 3. ((equal? (first strand1) (first strand2)) (similar-strands-helper strand1 strand2 num-errors)) 4. (else (similar-strands-helper (bf strand1) (bf strand2) 1)))) For each Line Tell whether it is a Base Case or Recursive Case, The correction to the Code if it needs to be fixed, otherwise NOTHING, and What line it should be swapped with, if Any, otherwise write NONE. Base or Recursive? New Code Swap with line? 1. BASE NOTHING 2 2. BASE NOTHING 1 3. RECURSIVE (similar-strands-helper (bf strand1) (bf NONE strand2) num-errors) 4. RECURSIVE (similar-strands-helper (bf strand1) (bf strand2) (+ 1 num-errors)) NONE 5. The Truth about Sports We are writing a sports survey program for a company, but we are a little biased. The company asks, in its survey, for a person to give, in a sentence, his/her three favorite sports. There are four possible options for these sentences. Either they have three sports listed, as in (football is my favorite followed by hockey and tennis) in the precise format of (* sport* is my favorite followed by *sport * and *sport *) or else, they only have one overwhelming favorite and give (basketball is my favorite in all the world and I love it and nothing else) (basketball is my favorite and nothing else) in the precise format of (* sport* is my favorite *extra nonsense words* and nothing else). (namely, we don t know how long this sentence might be). the third options is they may not like any sport much (well I do not really like anything but I would have to pick basketball) (well I do not really like much but I suppose basketball)

in the precise format of (well I do *extra nonsense words* *sport *) and finally, if they despise all sports, then they would respond with (well I hate sports but if I had to pick I would say cricket possibly) (well I hate them all but I guess tennis maybe) in the precise format of (well I hate *extra nonsense words * * sport* *extra word*) We want to write a survey program that, given such a sentence, replaces all the instances of any of the sports with the sport soccer. We do NOT want to get rid of any of the other words in the sentence or our boss will know we ve tampered with something. Call this procedure survey-correction. Assume first, second, and third are all defined. (define (survey-correection sports-survey) (cond ((equal? (se (first sports-survey) (second sports-survey) (third sports-survey)) (well I hate)) (se (bl (bl sports-survey)) soccer (last sports-survey))) ((equal? (se (first (sports-survey) (second sports-survey) (third sports-survey)) (well I do)) (se (bl sports-survey)) soccer (last sports-survey))) ((equal? (last sent) else) (se soccer (bf sports-survey))) (else (soccer is my favorite followed by soccer and soccer))))