Midterm #1a Fall minutes

Similar documents
Midterm #2a Fall minutes

Midterm #2a Spring minutes

Midterm #2a Fall minutes DO NOT WRITE IN THIS AREA

Midterm #2a Spring minutes DO NOT WRITE IN THIS AREA

Midterm #1 Fall minutes

Midterm #1a Spring minutes

CS1800 Discrete Structures Final Version A

Midterm Exam 2B Answer key

Midterm Exam Review. CS 2420 :: Fall 2016 Molly O'Neil

CS110 Introduction to Computing Fall 2006 Midterm Exam

Discrete structures - CS Fall 2017 Questions for chapter 2.1 and 2.2

Midterm Exam 2A Principles of Computing Fall November 10, 2014

Integers and Absolute Value. Unit 1 Lesson 5

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

CS 202: Introduction to Computation Fall 2010: Exam #1

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

CPSC 217 Midterm (Python 3 version)

The LC3's micro-coded controller ("useq") is nothing more than a finite-state machine (FSM). It has these inputs:

Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators

Midterm 1. CS Intermediate Data Structures and Algorithms. October 23, 2013

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Structure and Interpretation of Computer Programs

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

Short Answer Questions (40 points)

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1

Structure and Interpretation of Computer Programs

Fundamentals of Programming. Week 1 - Lecture 3: Loops

CSE 131 Introduction to Computer Science Fall Exam II

15-110: Principles of Computing, Spring 2018

1. Fill in the entries in the truth table below to specify the logic function described by the expression, AB AC A B C Z

EECS 270 Midterm Exam

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields.

EE 355 Lab 3 - Algorithms & Control Structures

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

1 Fall 2017 CS 1110/1111 Exam 3

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

CDS130 Mid-term exam: Sample

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators

Note that there are questions printed on both sides of each page!

Grade 7/8 Math Circles Fall November 6/7/8 Boolean Logic

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

CS40-S13: Functional Completeness

Unit 2: Data Storage CS 101, Fall 2018

Computer Science 217

C ONTROL AND H IGHER O RDER F UNCTIONS

CSE 131 Introduction to Computer Science Fall Exam I

Structure and Interpretation of Computer Programs

15-110: Principles of Computing, Spring 2018

Structure and Interpretation of Computer Programs

Introduction to Fall 2008 Artificial Intelligence Midterm Exam

Announcements. Project 2 due next Monday. Next Tuesday is review session; Midterm 1 on Wed., EE 129, 8:00 9:30pm

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Read this before starting!

CSE 20 DISCRETE MATH. Fall

Practice Midterm 1. Problem Points Score TOTAL 50

1.1 The Fifth Trial pages 18 and 25

ENGR 100 Midterm (CSE Part) Winter 2014

STUDENT NUMBER: MATH Final Exam. Lakehead University. April 13, Dr. Adam Van Tuyl

CS 61A Control and Environments Spring 2018 Discussion 1: January 24, Control. If statements. Boolean Operators

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Grade 7/8 Math Circles Fall November 6/7/8 Boolean Logic

Midterm I Practice Problems

Lecture 3: Truth Tables and Logic Gates. Instructor: Joelle Pineau Class web page:

CSE 21 Summer 2017 Homework 4

01 Introduction to Digital Logic. ENGR 3410 Computer Architecture Mark L. Chang Fall 2008

CSE 131 Introduction to Computer Science Fall Exam I

Mill Hill School. 13+ Entrance Examination Mathematics. January Time: 1 hour. School: Mark: Materials required for examination

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 121: MIDTERM 2 Group March 12, 2014

ECE 341 Midterm Exam

Structure and Interpretation of Computer Programs

Computer Science 217

Structure and Interpretation of Computer Programs

e01 EXAM: e01: Midterm Exam CS8 F18 Name: Umail 10/24/2018 e01 - Midterm Exam - Gauchospace Gradescope Piazza

Midterm 1 Written Exam

CS171 Midterm Exam. October 29, Name:

Read this before starting!

CS1800 Discrete Structures Final Version B

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

CSE 131 Introduction to Computer Science Fall Exam I

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

CS/COE 0447 Example Problems for Exam 2 Spring 2011

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

CS 170 Second Midterm ANSWERS 7 April NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt):

RECURSION: n. SEE RECURSION 3

Good Evening! Welcome!

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

UNCA CSCI 255 Exam 1 Spring February, This is a closed book and closed notes exam. It is to be turned in by 1:45 PM.

Structure and Interpretation of Computer Programs

A Constant Rate of Change Name Part 1

CDS Computing for Scientists. Final Exam Review. Final Exam on December 17, 2013

ECE 341 Midterm Exam

SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

CS150 Sample Final. Name: Section: A / B

Exam 2. Name: UVa ID:

4. Write a sum-of-products representation of the following circuit. Y = (A + B + C) (A + B + C)

Programming Project 1

Transcription:

15-110 Midterm #1a Fall 2018 50 minutes Name: Andrew ID: @andrew.cmu.edu Section: You may not use any books, notes, or electronic devices during this exam. You may not ask questions about the exam except for language clarifications. Show your work on the exam (not scratch paper) to receive credit. If you use scratch paper, you must submit it with your andrew id on it, and we will ignore it. All code samples run without crashing. Assume any imports are already included as required. Do not use these post-midterm1 topics: strings, lists, etc. DO NOT WRITE IN THIS AREA Part 1 (CT) Part 2 (Logic Circuits) (xnor) Part 3 (Very Short Answers) Part 4 (FR / CMU-A) Part 5 (FR / primecount) Part 6 (FR / avgofevendigits) Part 7/bonus Total 30 points 10 points 20 points 10 points 10 points 15 points 5 points bonus 95 points (Not on exam: Watch The Imitation Game) 5 points

1. [30 pts; 10 pts each] Code Tracing Indicate what each will print. Place your answer in the boxes below each block of code. Show your work, outside the box, for partial credit. def ct1(n): m = 2*n d = 10 while (n < m): print(n, d) n += d d += 10 return n print(ct1(40)) # prints 7 values # on 4 lines def ct2(lo, hi): result = 0 for z in range(lo, hi): if (z%2 == 1): print(z, result) result += z%10 return result print(ct2(20,24)) # prints 5 values # on 3 lines def ct3(d, m): for x in range(m): for y in range(m): if (x * y == d): print(x, y) print(ct3(5, 6)) # prints 5 values # on 3 lines

2. [10 pts] Logic Circuits: xnor The function xnor is the opposite of xor. So (x xnor y) is True if both x and y are True, or neither x nor y are True. Also, (x xnor y) is False if exactly one of x or y is False. A. [4pts] Write the Truth Table for (x xnor y) Hint: the table should have 4 rows in it. B. [3 pts] Write (x xnor y) in Disjunctive Normal Form (DNF, using only And, Or, and Not) C. [3 pts] Draw a logic circuit that computes (x xnor y) using only And, Or, and Not gates, that matches your DNF expression from the previous step (2B). Each gate should be drawn as a rectangle with the word And, Or, or Not inside.

3. [20 pts; 2.5 pts each] Very Short Answers Answer each of the following very briefly. A. In just a few words, state one topic that the Blums discussed in their guest lecture. B. Multiply 23 * 37 using lattice multiplication. Show your work. C. In just a few words, state one important technical contribution Alan Turing made. D. When we add two 1-bit values x and y, we get a 2-bit result. The high-order bit is (x and y). What logical function of x and y describes the low-order bit (the one's digit)? E. In the number-guessing game from our case study, the user picks a number between 0 and 100, inclusive, and the computer guesses 50. If that is too low, what will the next guess be? Show your work. F. In just a few words, state a winning algorithm for the game of Nim. G. In just a few words, why did we switch from ascii to unicode? H. Multiply 9 * 6 using Egyptian Multiplication. Show your work.

4. [10 pts] Free Response: CMU-A Using the CS Academy drawing functions, draw this image: Notes: * all numbers in your code should be either a single digit or a multiple of 100 * all colors are black or white * the outer 400x400 rectangle is the canvas border, and not part of the drawing

5. [10 pts] Free Response: primecount Note: for this problem, assume you already have the function isprime(n) that returns True if n is prime and False otherwise. Do not write isprime(n) here! Using the isprime(n) function, write the function primecount(n) that takes a possibly-negative integer n and returns the number of primes up to n, inclusive. Note that the first several primes are: 2, 3, 5. So: primecount(1) returns 0 primecount(2) returns 1 primecount(3) returns 2 primecount(4) returns 2 primecount(5) returns 3 Also, since there are no primes smaller than 2, primecount(-10) returns 0.

6. [15 pts] Free Response: averageofevendigits Without using strings, write the function averageofevendigits(n) that takes an integer n and returns the average of the even digits in n. Here are some sample test cases for you: assert(averageofevendigits(12345) == 3) # (2+4)/2 == 6/2 == 3 assert(averageofevendigits(102201) == 1) # (0+2+2+0)/4 == 4/4 == 1 assert(averageofevendigits(1) == None) # no even digits --> None assert(averageofevendigits(0) == 0) # handle 0! assert(averageofevendigits(-2) == 2) # handle negatives! Reminder: do not use strings.

7. Bonus/Optional: [2.5 pts] What will this print? Clearly circle your answer. def bonusct1(n): a = n%10 b = n//10%10 n //= 100 m = 0 while (n > 0): d = n%10 n //= 10 if ((d > a) and (b > d)): m = 10*m + d return m bignumber = 26999500079469942999000081 print(bonusct1(bignumber)) print(bonusct1(bonusct1(bignumber))) Bonus/Optional: [2.5 pts] What will this print? Clearly circle your answer. def bonusct2(n): result = 0 sign = 1 for i in range(n): for j in range(i+1): result += sign * j sign = -sign return result for i in range(100): k = bonusct2(i) if (abs(k)//2 == 10): print(i, k)