Contest Python: ACSL › Checkpoint 1 — Contest 1 Practice

Questions: Checkpoint 1 — Contest 1 Practice

This is a practice paper modelled on ACSL Contest 1: short-answer questions from the three Contest 1 categories, then one programming problem. Questions 1–6 are a full six-question paper; Question 7 is extra all-constructs practice for Intermediate and Senior.

Questions Category Division
1–2 Computer Number Systems Junior and above
3–4 Recursive Functions Junior and above
5–6 What Does This Program Do? – Branching Junior and above
7 What Does This Program Do? (all constructs) Intermediate and above
8 Programming problem Junior and above

Take it as a timed practice.

  • Put away your notes and set a timer.
  • Give yourself 30 minutes for the short answers, as in the real contest: Questions 1–6 on every path. On the Intermediate or Senior path, add Question 7 as an extra challenge; it goes beyond the real six-question paper. Work with pencil and paper only: no computer, no calculator. Write each answer on paper or in your notebook.
  • Then give yourself about 60 minutes for Question 8. Write a complete program that reads the input with input() and prints exactly the output described. Save it as a .py file and run it from a terminal, typing the sample input or feeding it a file: python my_solution.py < sample.txt. Print nothing extra: no prompts in input(), and no words the problem did not ask for.

These times are a practice pace, not the official rules; the real limits for your division are published by ACSL at acsl.org.

How to write short answers.

  • Give exactly one answer, written the way the question asks for it.
  • For an answer in another base, write only the digits, with capital letters A–F for hex digits, no base subscript and no leading zeros.
  • For a recursive function, write the value as a plain whole number.
  • For a program, write exactly the one line it outputs.

If you follow the Junior path, do Questions 1–6 and 8. If you follow the Intermediate or Senior path, do all eight questions. When you finish, check yourself.

  • Short answers have no sample to test against. Mark the questions you were unsure of, then work each one again by its unit's method: redo the trace or the call table, or check a conversion both ways. Compare with a partner, or with a second attempt made without looking at the first.
  • The programming question is checked against its sample, and against inputs of your own made from its constraints: the smallest cases, the largest, and the tricky ones.

Then go back to the unit for any category that cost you points.

Question 1: Hex to Octal

  • Division: Junior

Convert 3AC₁₆ to base 8.

Write the answer as base-8 digits only.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Question 2: Times Five in Hex

  • Division: Junior

Evaluate 2C7₁₆ × 5, and write the product in base 16.

Write the answer as base-16 digits only.

How this is checked: Checked by comparing your answer with the expected answer, ignoring capital letters.

Answer format: A hexadecimal number: base-16 digits only, with capital letters A–F for the digits after 9 (as in `2D`), no base subscript and no leading zeros. Small letters are accepted too.

For parents and teachers: report a problem

Question 3: Step Down by Four

  • Division: Junior

Find the value of f(23) for the function

        ┌  f(x − 4) + x        if x > 12
f(x) =  ┤
        └  (x mod 5) + 3       if x ≤ 12

Write the answer as a whole number.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Question 4: Skip Two, Skip Three

  • Division: Junior

Find the value of h(9) for the function

        ┌  h(n − 2) + h(n − 3) + 1    if n ≥ 4
h(n) =  ┤
        └  2 × n − 1                  if n < 4

Write the answer as a whole number.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Question 5: Which Branch Runs?

  • Division: Junior
parts = input().split()
a = int(parts[0])
b = int(parts[1])
c = int(parts[2])
if a > b and b > c:
    if a - b > b - c:
        x = a * 2 - c
    else:
        x = b + c
elif a > c or c % 2 == 0:
    x = a + b + c
else:
    x = 0
if not x % 3 == 0:
    x = x + 1
print(x)

Input

14 9 5

What exactly does the program print?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Question 6: Pseudocode Branches

  • Division: Junior

This program is written in ACSL pseudocode. % is the remainder, ! is not, && is and, and || is or.

input a, b
c = a % b
if c > 2 && !(a > 50) then
   d = a - b * c
else
   if c == 0 || b > 6 then
      d = a + b
   else
      d = 2 * c - a
   end if
end if
if d < 0 then
   d = -d
end if
output d

What value does the program output when the input values are 62 and 5?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Question 7: All the Constructs

  • Division: Intermediate

This program is written in ACSL pseudocode.

  • A is a 2D array: A(r, c) is the entry in row r, column c.
  • Strings are indexed from 0, and S[p:q] is the ACSL substring from position p through position q (both included), as in Unit 3.
  • / is real division, so it can give a decimal.
  • int(x) is the greatest integer less than or equal to x, abs(x) is the absolute value and sqrt(x) is the square root.
S = "COMPUTERS"
for r = 1 to 3
   for c = 1 to 3
      A(r, c) = r * c - 2
   next c
next r
t = 0
for k = 1 to 3 step 2
   t = t + A(k, 4 - k)
next k
x = int((t - 7) / 2)
y = int(sqrt(A(3, 3) + 2))
while abs(x) < 10
   x = x * y
end while
p = abs(x) % 4
w = S[p:p + 2]
output w

What does the program output?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: Exactly the one line the program outputs: values separated by one space, strings without quotation marks, and letters in the case the program prints them.

For parents and teachers: report a problem

Question 8: One Digit, Repeated

  • Division: Junior

Some numbers are written with one digit, repeated in some base: all of their digits in that base are the same. For example, 26 is 222₃ in base 3, and 400 is 1111₇ in base 7 (343 + 49 + 7 + 1). Such a base always exists: a number from 3 up is written 11 in the base one less than itself.

The input is one line: a decimal whole number N. Find the smallest base B, with B at least 2, in which all the digits of N are the same. Print one line: the base B, the value of that repeated digit, and the number of digits, separated by single spaces. Write the base and the digit's value as decimal numbers, since the base can be larger than 16.

Constraints

  • 1 <= N <= 100000

Sample Input

400

Sample Output

7 1 4

In bases 2 to 6 the digits of 400 are not all the same (in base 6, for example, it is 1504₆). In base 7 it is 1111₇: the digit 1, four times.

How this is checked: Checked by running your program on 10 test inputs (1 sample, 9 hidden) and comparing its output line by line.

For parents and teachers: report a problem

Back to Checkpoint 1 — Contest 1 Practice