0% found this document useful (0 votes)
357 views

ACSL Intermediate

The document contains 5 short programming problems and their solutions. Problem 1 asks to convert a hexadecimal number to octal. Problem 2 asks to evaluate an expression and output the answer in hexadecimal. Problem 3 asks about the number of segments in a recursively defined figure. Problem 4 gives a recursive function definition and asks to evaluate it. Problem 5 gives a program and asks what it prints when run.

Uploaded by

erican0614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
357 views

ACSL Intermediate

The document contains 5 short programming problems and their solutions. Problem 1 asks to convert a hexadecimal number to octal. Problem 2 asks to evaluate an expression and output the answer in hexadecimal. Problem 3 asks about the number of segments in a recursively defined figure. Problem 4 gives a recursive function definition and asks to evaluate it. Problem 5 gives a program and asks what it prints when run.

Uploaded by

erican0614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

American Computer Science League

2017-2018 Contest #1
Intermediate Division Short Problems

1. Computer Number Systems

Convert to octal: 3A9B16

2. Computer Number System:

Evaluate and express the answer in hex:

328 + 10112 + 35210 + AF16

3. Recursive Functions

Begin with a capital T consisting of 2 congruent segments.


At the end of each segment place a segment half as long and perpendicular
to it. Continue this process for an additional 5 times. How many segments
are in the resulting figure?

4. Recursive Functions

Find f( 12,7 ) given:


ì f ( x - 1, y + 2) + 3 if x > y
ï
f(x, y) = í2 * f ( x + 1, y - 1) - 5 if x < y
ïx * x + y if x = y
î

5. What Does This Program Do?

What is printed when this program is run?

a = 1: b = 2: c = 3: d = 4: e = 4: f = 6
if (d / b) < (f / a) then d = d / b
a = f ↑ b / c ↑ (d / b)
if (a <= f) && (b > e) then a = f else b = e
if abs(c - f) != int(f / c) then c = f / c else f = f / c
if (a = = b) | | (c = = d) then a = a + b
c=c+d
output (b * c) * (f + d) / a / 2 * d - c + e ↑ (b - 2 * d)
American Computer Science League
2017-2018 Contest #1
Intermediate Division – Solutions to Short Problems

1. Computer Number Systems


1. 352338 or 35233
3A9B16 = 0011 1010 1001 10112
= 0 011 101 010 011 0112 grouping by three
= 3 5 2 3 38

2. Computer Number Systems


2. 23416 or 234
328 = 26
10112 = 11
35210 = 352
AF16 = 175
So 328 + 10112 + 35210 + AF16
= 26 + 11 + 352 + 175
= 564
But 564 = 23416

3. Recursive Functions
3. 191
The original T has 2 segments. The next step adds 3 more segments for a
total of 5. The next step adds 6 segments for a total of 11. Next 12
segments are added for 23. The sequence formed is:

2, 5, 11, 23, 47, …, 3*2n-1-1, …

The 7th term would be 3*26-1 = 191

4. Recursive Functions
4. 525
f( 12,7 ) = f(12 - 1,7 + 2 ) + 3 = f(11,9 ) + 3 = 522 + 3 = 525
f(11,9 ) = f( 11 - 1,9 + 2 ) + 3 = f(10,11 ) + 3 = 519 + 3 = 522
f( 10,11 ) = 2 * f(10 + 1,11 - 1 ) - 5 = 2 * f( 11,10 ) - 5 = 2*262−5 = 519
f( 11,10 ) = f( 11 - 1,10 + 2 ) + 3 = f( 10,12 ) + 3 = 259 + 3 = 262
f(10,12 ) = 2 * f(10 + 1,12 - 1 ) - 5 = 2 * f( 11,11 ) - 5 = 2*132−5 = 259
f( 11,11 ) = 11*11+11= 132 Now substitute backwards.
American Computer Science League
2017-2018 Contest #1
Intermediate Division – Solutions to Short Problems

5. What Does This Program Do?


5. 5
The following table contains the values of a, b, c, d, e, and f after each line:

a b c d e f
1 2 3 4 4 6
1 2 3 2 4 6
12 2 3 2 4 6
12 4 3 2 4 6
12 4 2 2 4 6
16 4 2 2 4 6
16 4 4 2 4 6

(b * c) * (f + d) / a / 2 * d - c + e ↑ (b - 2 * d)
= (4 * 4) *(6 + 2) / 16 / 2 * 4 - 4 + 4 ↑ (4 - 2 * 2)
= 16 * 8 / 16 / 2 * 4 - 4 + 40
= 128 / 16 / 2 * 2 - 4 + 1 = 8 / 2 * 2 - 4 + 1 = 5

You might also like