90 likes | 215 Views
Lynbrook Computer Science. December 1, 2008. Announcements. USACO this week! (December 5-8) First ACSL: Monday, December 15 Two new competitions: CML (Continental Mathematics League) JAVA Computer Contest IPSC (Internet Problem Solving Contest).
E N D
Lynbrook Computer Science December 1, 2008
Announcements • USACO this week! (December 5-8) • First ACSL: Monday, December 15 • Two new competitions: • CML (Continental Mathematics League) JAVA Computer Contest • IPSC (Internet Problem Solving Contest)
CML (Continental Math League) JAVA Computer Contest • Done in JAVA • Done in teams • Written Contest • Based on AP Computer Science A/B curriculum • 25 Questions • 40 Minutes • Sometime between 4/20 and 5/1
IPSC (Internet Problem Solving Contest) • Online contest • Done in teams of 3 • 5 Hours • Any language can be used • Access to online resources is allowed • USACO-like problems
Tested Material on the ACSL What does this program do? Number Systems (different base operations) Recursive Functions (f(x) = f(x-1) + 1) Boolean Algebra (not A + B = …) Bit String Flicking (right shift, left shift) LISP Evaluation (ADD, SUB, etc.) Digital Electronics (AND, OR, XOR, NAND, NOR, XNOR) Prefix/Infix/Postfix Notation (+ 3 4) Data Structures (heaps, binary trees, stacks, etc.)
Recursive Functions • Find f(15) given the following: • f(x) = • 2 * f(x-3) – 4 [if x is composite] • x2 + x [if x is prime]
Solution • f(15) = 2 * f(12) – 4 • f(12) = 2 * f(9) – 4 • f(9) = 2 * f(6) – 4 • f(6) = 2 * f(3) – 4 • f(3) = 32 + 3 = 12 • Work backwards to get f(6) = 20, f(9) = 36, f(12) = 68, and f(15) = 132
LISP • Evaluate the following: • (CDR (CDR (CAR (CDR ‘(2 ((3 (4 5) 6) 7)))))) • Hint: • CDR ‘((x) y) = y • CAR ‘((x) y) = (x)
Solution • Work from the inside out: • (CDR '(2 ((3 (4 5) 6) 7))) = (((3 (4 5) 6) 7)) • (CAR '(((3 (4 5) 6) 7))) = ((3 (4 5) 6) 7) • (CDR '((3 (4 5) 6) 7)) = (7) • (CDR '(7)) = () • Answer: () or nil PARENTHESIS ARE REQUIRED!!!