CPSC 121: Models of Computation 2018 Summer Term 1
Introduction & Motivation Cinda Heeren, based on notes by Steve Wolfman, Patrice Belleville and
- thers
1
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
CPSC 121: Models of Computation 2018 Summer Term 1 Introduction - - PowerPoint PPT Presentation
CPSC 121: Models of Computation 2018 Summer Term 1 Introduction & Motivation Cinda Heeren, based on notes by Steve Wolfman, Patrice Belleville and others 1 This work is licensed under a Creative Commons Attribution 3.0 Unported License.
1
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
;; Model in math, translate to Racket. (define (introductions n) (* n (- n 1))) ;; Model as “I know what happens ;; a) in a group of 0 people, and ;; b) when someone new enters a group.” ;; Translate to Racket. (define (introductions n) (if (= n 0) _______ ____________________ ; soln on smaller instance ____________________); + the extra intros
20
21
22
23
24
25
(especially induction!)
26
27
28
29
30
31
a) For each item in the main list, in order: Put it at the back of the list indicated by the current digit in that item b) For each digit list, in order: Put the list at the back of the main list.
32
Class Main { public static void main(String[] args) { // Let's add up 4 quarters. System.out.println("4 quarters gives us:"); System.out.println(0.25 + 0.25 + 0.25 + 0.25); // Let's do something a hundred times. int i = 100; do { // Make i one smaller. i--; } while (i > 0); System.out.println("Done!"); System.out.println("i ended up with the value: " + i); System.out.println("It went down by: " + (100 - i)); } }
33
Class Main { public static void main(String[] args) { // Let's add up 10 dimes. System.out.println("10 dimes gives us:"); System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); // Let's try do something a hundred times.. // but accidentally go forever int i = 100; do { // Make i one LARGER. Oops! i++; } while (i > 0); System.out.println("Done!"); System.out.println("i ended up with the value: " + i); System.out.println("It went down by: " + (100 - i)); } }
34
35
36
37
http://www.ugrad.cs.ubc.ca/~cs121/current/handouts/prop-circuit-xlate.html
38