American Computer Science League Intermediate Division Solutions 2007 - 2008 Contest #1
American Computer Science League Intermediate Division Solutions 2007 - 2008 Contest #1
1. Recursive Functions
f (32) = f (32/2) − 1) + 3 = f (15) + 3 = 7 + 3 = 10
1. 10
f (15) = 2 * f (15-3) – 5 = 2 * f (12) – 5 = 2 * 6 – 5 = 7
f (12) = f (12/2 − 1) + 3 = f (5) + 3 = 3 + 3 = 6
f (5) = 2 * f (5 − 3) –5 = 2 * f (2) – 5 = 2 * 4 – 5 = 3
f (2) = f (2/2 − 1) + 3 = f (0) + 3 = 1 + 3 = 4
f (0) = f (0/2 − 1)) + 3 = f (−1) + 3 = −2 + 3 = 1
f (−1) = ( −1)2 – 3 = 1 – 3 = −2
2. 68
2. Recursive Functions
f (1) = 8 Þ f (2) =2* f (1) – 4 = 12
f (2) = 12 Þ f (3) = 2* f (2) – 4 = 20
f (3) = 20 Þ f (4) = 2* f (3) – 4 = 36
f (4) = 36 Þ f (5) = 2* f (4) – 4 = 68
5. LISP 5. 24