Contest Python: ACSL › Checkpoint 4 — Contest 4 Practice

Questions: Checkpoint 4 — Contest 4 Practice

This is a practice paper modelled on ACSL Contest 4: short-answer questions from the four Contest 4 categories, then one programming problem. The Junior paper and the Intermediate/Senior paper share their first four questions, so this checkpoint holds both six-question papers. It is the last practice paper of the season.

Questions Category Division
1–2 Graph Theory Junior and above
3–4 Digital Electronics Junior and above
5–6 What Does This Program Do? – Strings Junior
7–8 Assembly Language Intermediate and above
9 Programming problem Junior and above

Choose your path.

  • Junior: Questions 1–6, then Question 9.
  • Intermediate or Senior: Questions 1–4 and 7–8, then Question 9. Questions 5–6 are optional extra string practice.
  • Classroom (no programming): Questions 1–4 and 7–8. Questions 5–6 are optional, and Question 9 is left out.
  • Elementary (no programming): this checkpoint is not your paper. Your Contest 4 practice test is Exercises 1–6 of Unit 12 (Graph Theory): six questions in 30 minutes.

Take it as a timed practice.

  • Put away your notes and set a timer.
  • Give yourself 30 minutes for the six-question paper on your path, as in the real contest. Work with pencil and paper only: no computer, no calculator. Write each answer on paper or in your notebook.
  • On the Junior, Intermediate or Senior path, then give yourself about 60 minutes for Question 9. 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 a "how many" question, write just the whole number, such as 6.
  • For the inputs that make a circuit TRUE, write each as a bracketed tuple in the order of the INPUTS line with no spaces inside, such as (1,0,1), list them in ascending binary order, and separate them with a comma and a space; write NONE if there are none.
  • For a simplified circuit, write a sum of products in the book's notation: ~ NOT, * AND, + OR, with a single space around * and +. Use the fewest terms, and then the fewest letters. Inside a term, put the literals in alphabetical order of their variables; order the terms the same way, with X before ~X, and a shorter term first when one term runs out. Write 1 or 0 alone if the circuit is always TRUE or always FALSE.
  • For a program, write exactly the one line it outputs: values separated by one space, and strings without quotation marks.
  • For an assembly program, write the value in the location asked for as a whole number, or every printed number in order, on one line, separated by single spaces.

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 truth table, the matrix or the trace, or list the cycles and walks a second way. 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: Round the One-Way Streets

  • Division: Junior

A directed graph has vertices {A, B, C, D, E} and edges {AB, AE, BC, CA, CD, DA, DE, EB}. The edge AB goes from A to B.

How many different cycles does the graph contain? A cycle must follow the direction of the edges and visits no vertex twice, except that it ends where it started. Each cycle is counted once, whichever vertex it is written from: ABCA, BCAB and CABC are the same cycle.

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: Three Steps Along the Matrix

  • Division: Junior

A directed graph has this adjacency matrix, where the entry in row i and column j is 1 when there is an edge from i to j:

M A B C D E
A 0 1 0 1 0
B 0 0 1 0 1
C 1 0 0 1 0
D 0 1 0 0 1
E 1 0 0 0 0

How many paths of length 3 go from C to E? A path follows the direction of the edges and may repeat vertices and edges, as the entries of M³ count them.

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 3: Which Rows Light Up?

  • Division: Junior

Find all ordered triples (A,B,C) that make this circuit TRUE.

INPUTS A B C
p = XOR(A, B)
q = NOT(C)
r = NAND(p, q)
out = AND(r, B)

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

Answer format: Tuples with the inputs in the order of the `INPUTS` line and no spaces inside, listed in counting-up order with a comma and a space between tuples, as in `(0,1,0), (1,1,1)`; `NONE` if there are none.

For parents and teachers: report a problem

Question 4: Fewer Letters, Same Light

  • Division: Junior

Write the expression of this circuit, and simplify it as a sum of products with the fewest terms and then the fewest letters.

INPUTS A B C
p = NOR(A, B)
q = AND(A, C)
r = OR(p, q)
out = XNOR(r, C)

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

Answer format: A sum of products: `~` NOT, `*` AND, `+` OR, with one space around each `*` and `+`; the fewest terms, then the fewest letters; letters in alphabetical order inside each term, and the terms in alphabetical order too, with a plain letter before its `~` form (as in `A * B + ~A * C`); `1` or `0` if it is always TRUE or always FALSE.

Also check yourself

The automatic check cannot see these, so tick each one when your work does it.

For parents and teachers: report a problem

Question 5: Slices of Melon

  • Division: Junior

This program is written in ACSL pseudocode. Remember ACSL's substring rules: S[:n] is the first n characters, S[n:] is the last n characters, and S[a:b] is positions a through b, both included. Positions start at 0, and a FOR loop includes its end value.

S = "WATERMELON"
T = S[:1]
FOR j = 1 TO 3
   T = T + S[j:j + 1] + S[j:]
NEXT j
OUTPUT T, len(T)

What exactly is 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 6: A Growing Shift

  • Division: Junior

This program is in Python, so Python's slicing rules apply. % is the remainder.

A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
S = "ZEBRA"
T = ""
for j in range(len(S)):
    k = 0
    while A[k] != S[j]:
        k = k + 1
    T = T + A[(k + j) % 26]
print(T, T[1:4])

What exactly does the program print?

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 7: Down to the Remainder

  • Division: Intermediate

ACC starts at 0, and every DC line sets its location before the program runs. After this program runs, what number is in the location Z?

X     DC    -23
Y     DC    4
Z     DC    0
      LOAD  X
      DIV   Y
      STORE Z
      MULT  Y
      SUB   X
      MULT  =-1
      ADD   Z
      STORE Z
      END

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 8: Small Ones Add Up

  • Division: Intermediate

The input numbers are 7, 15, 3, 10, 22 and −1, in that order. What does this program print?

C     DC    0
LOOP  READ  N
      LOAD  N
      BL    DONE
      SUB   =10
      BG    BIG
      LOAD  C
      ADD   N
      STORE C
      BU    LOOP
BIG   PRINT N
      BU    LOOP
DONE  PRINT C
      END

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

Answer format: Every printed number in order, on one line, separated by single spaces, as in `13 8 3`.

For parents and teachers: report a problem

Question 9: What Kind of Route?

  • Division: Junior

The vertices of a directed graph are capital letters, and the edge AB goes from A to B. A route is a list of vertices written together, such as ABCA. Using the words of Unit 12, every route is exactly one of these kinds:

  • NOT A PATH: somewhere in the route, a vertex is not joined to the next one by an edge going that way.
  • CYCLE: a path that ends at the vertex where it started, with no other vertex appearing twice. In a directed graph a cycle may have just two vertices: ABA is a cycle when AB and BA are both edges.
  • SIMPLE PATH: a path in which no vertex appears twice.
  • PATH: any other path, which visits some vertex more than once.

The first line of input holds the vertex letters, in alphabetical order, run together (such as ABCDE). The second line holds the edges, separated by single spaces, each written as two letters. The third line holds R, the number of routes. Each of the next R lines holds one route.

Print one line for each route, in order: its kind, written exactly as above.

Constraints

  • There are between 2 and 26 vertices: different capital letters, in alphabetical order. They need not start at A.
  • There are between 1 and 200 edges, and every edge joins two vertices of the first line.
  • No edge joins a vertex to itself, and no edge appears twice. AB and BA may both appear: they are two different edges.
  • 1 <= R <= 400, and every route has between 2 and 30 letters, each a vertex of the first line.

Sample Input

ABCDE
AB BC CA CD DB DE EA
6
ABCA
DEAB
ABCDBC
ACDE
ABCABCA
CDEABC

Sample Output

CYCLE
SIMPLE PATH
PATH
NOT A PATH
PATH
CYCLE

ABCDBC follows the edges but visits B and C twice, so it is a path but not a simple path. ACDE fails at its first step: the edge between A and C is CA, which goes the other way. ABCABCA ends where it started, but it goes round the triangle twice, so it is a path, not a cycle.

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

For parents and teachers: report a problem

Back to Checkpoint 4 — Contest 4 Practice