Operation Early Finish
____
_
_____
_____
0 / 15 LOCKS OPEN
LOCKDOWN: HIGHER EDITION

Operation Early Finish

It is the last double period before the break. Somebody has locked down the Computing corridor and Mr Docherty is stuck behind three locked doors. Every lock takes a code, and every code comes from a Python program that you write. Fifteen locks. Get everybody out.

Nobody is marking you. You have the full double period, so pace yourself: the Staff Room is the warm-up, the Server Room is the main event and the Vault is the stretch.

How to play

  1. Download the evidence bag below, extract it, and open the folder in PyCharm (File > Open).
  2. Pick a lock. Write a program that works out the answer and prints it.
  3. Test your program on the small example first. If it is wrong on the example, it is wrong on the real thing.
  4. Type the answer on the keypad. Right answer: the lock opens and you get a key fragment letter.
  5. Open enough locks in a room to unlock the next door (the door tells you how many). Collect all 15 fragments to get the exit code.
  6. Write it the way you would write your assignment: meaningful variable names, a sub-program with parameters for anything you do more than once, and a comment where the code is not obvious.

Evidence bag

The data files for the Staff Room, Server Room and Vault, plus an offline answer checker in case the internet fails.

escape-pack.zip
This is a zip file. You must extract it before you can use it.
  1. Find escape-pack.zip in your Downloads folder.
  2. Right-click it, choose Extract All…, then click Extract.
  3. A normal folder called escape-pack opens. Open that folder in PyCharm (File > Open).

Do not work from inside the zip, because PyCharm cannot read the data files from there. On a Mac, just double-click the zip.

Room 1

Staff Room

Warm-up. Familiar territory, so aim to be through within 35 minutes.

DOOR OPEN
A1

Fire drill sums

LOCKED

The fire alarm goes off and the door only opens for the right number. The rule on the sign: add up every whole number from 1 to 1000 that is a multiple of 7 or a multiple of 13, but is not a multiple of 5.

Your task: Use a loop and MOD to build the total. Be careful with the brackets around your OR.

Test your code on this first: From 1 to 40 the numbers are 7, 13, 14, 21, 26, 28, 39 (35 is a multiple of 5, so it is out) → total 148.

Answer format: A whole number
Skills: fixed loop, MOD, AND / OR with brackets, running total

A2

Mirror, mirror

LOCKED

The staff room door has a mirror lock. It wants the number of palindromes (words that read the same forwards and backwards, ignoring capitals) in this sentence. Single letters and two-letter words do not count: a palindrome here has 3 or more letters.
Anna and Bob saw a level racecar near the radar while Hannah noted that Otto painted a kayak and a madam asked about the refer button on the noon timetable but Eve ignored the stats

Your task: Store the sentence in a variable, split it into words and test each one. Write the palindrome test as a function that takes a word and returns True or False.

Test your code on this first: Anna saw a racecar has 2 palindromes (Anna and racecar; saw is not one and a is too short).

Answer format: A whole number
Skills: string handling, split, slicing / reversing, function with a parameter and a return value

A3

The late bell

LOCKED

The bell system has crashed. The times of the day’s bells are in data/bells.txt (24-hour times like 09:40, one per line, in order).

Your task: Find the longest gap between two bells next to each other in the file. Give the gap in minutes and the time of the bell where that gap starts.

Test your code on this first: Bells 09:00, 09:50, 10:05, 11:15, 12:00 have gaps of 50, 15, 70 and 45 minutes → 70-10:05

Answer format: minutes-time, e.g. 70-10:05
Skills: reading a file into a 1-D array, parsing text into numbers, comparing neighbouring elements, find the maximum

Evidence file: bells.txt (also in the evidence bag)

A4

Combination dial

LOCKED

The dial only turns for numbers whose digits add up to exactly 20. For example 389 works (3 + 8 + 9 = 20) but 390 does not.

Your task: Write a function digit_sum(number) that returns the sum of the digits of a number. Then use it to look at every whole number from 1 to 5000. Give how many numbers have a digit sum of 20 and the largest one.

Test your code on this first: Test digit_sum(1234) gives 10. For a digit sum of 10 between 1 and 100 you get 19, 28, 37, 46, 55, 64, 73, 82, 91 → 9-91

Answer format: count-largest, e.g. 9-91
Skills: sub-program with a parameter and return value, loop, MOD and integer division, count, maximum

A5

Urn temperature

LOCKED

The staff room tea urn has been logging its temperature in data/urn.txt (48 readings in °C, one per line, each with one decimal place). Somebody needs to know how bad it got.

Your task: Find the highest reading, the lowest reading and how many readings are above the average (mean) of all 48.

Test your code on this first: Readings 70.0, 90.5, 65.0, 80.5 have a mean of 76.5, so 90.5 and 80.5 are above it → 90.5-65.0-2

Answer format: highest-lowest-count, with the temperatures to 1 decimal place, e.g. 90.5-65.0-2
Skills: reading a file, converting text to real numbers, standard algorithms (max, min, running total), counting

Evidence file: urn.txt (also in the evidence bag)

Room 2

Server Room

Data files, records and sub-programs. This is where most of the time goes.

DOOR LOCKED

The Server Room door is locked. Open 4 of the 5 locks in the Staff Room to get through.

B1

Staff records

LOCKED

HR has dumped the staff list into data/staff.csv (90 staff). The first line is a heading. Each line is staff_id,department,years_service,salary.

Your task: Store each member of staff as a record in a 1-D array of records. Only staff with 5 or more years’ service count. Which department has the highest total salary for those staff, and what is that total?

Test your code on this first: S1 maths 10 years 30000, S2 art 2 years 90000, S3 maths 6 years 20000, S4 art 7 years 45000 → maths-50000 (maths 30000 + 20000 = 50000; art only counts S4 = 45000)

Answer format: department-total in lower case, e.g. maths-50000
Skills: records, reading a CSV file into an array of records, selection, totals per category, find the maximum

Evidence file: staff.csv (also in the evidence bag)

B2

Password patrol

LOCKED

The IT office has dumped 132 passwords into data/passwords.txt (one per line, a few contain spaces). A password is valid only if it follows every rule:

  • at least 10 characters
  • at least one capital letter and at least one lower case letter
  • at least one digit
  • at least one of these symbols: ! # $ % & * (a dash, full stop or underscore does not count)
  • no spaces
  • must not contain the word password, in any mix of capitals and lower case

Your task: Count how many passwords are valid. Write one function that checks a single password and returns True or False, then call it for each line.

Test your code on this first: Harbour#2024 is valid. Not valid: harbour#2024 (no capital), Harbour2024x (no symbol), Harbour #2024 (space), MyPassWord#12 (contains “password”), Tiger#24 (too short).

Answer format: A whole number
Skills: validation, sub-program with a parameter returning a Boolean, string handling, counting

Evidence file: passwords.txt (also in the evidence bag)

B3

Intruder log

LOCKED

Somebody has been guessing passwords on the school server. The log is data/access.log: a heading line, then lines like 07:15:02,10.0.4.23,FAIL (time, IP address, result). The result is OK or FAIL, but the logging software is sloppy: a failure can be written FAIL, Fail or fail.

Your task: Find the IP address with the most failed logins and say how many it had.

Test your code on this first: Failures: 10.0.1.5, 10.0.1.9, 10.0.1.5, plus one OK for 10.0.1.9 → 10.0.1.5-2

Answer format: ip-count, e.g. 10.0.1.5-2
Skills: reading a file, splitting lines, counting occurrences per category, case-insensitive comparison, find the maximum

Evidence file: access.log (also in the evidence bag)

B4

Locker lottery

LOCKED

150 lockers and their 4-digit combinations are in data/lockers.csv (lines look like L001,0517). Careful: some combinations start with a 0. A combination is rising if every digit is bigger than the digit before it, so 0358 and 1469 are rising but 1233 and 5731 are not.

Your task: Count the lockers with a rising combination, and give the locker number of the last one in the file. Write a function that takes a combination and returns True or False.

Test your code on this first: L001,1234   L002,1224   L003,0589   L004,9871 → 2-l003

Answer format: count-locker in lower case, e.g. 2-l003
Skills: reading a file, splitting strings, text vs number, comparing neighbouring characters, sub-program returning a Boolean

Evidence file: lockers.csv (also in the evidence bag)

B5

Tuck shop takings

LOCKED

The tuck shop has written its week into data/tuckshop.csv: a heading line, then item,category,price_pence,sold (an item that did not sell has 0 sold). Revenue for an item is price × number sold.

Your task: Which category made the most money in total, and how many pence was that? Write a function that takes the array of records and a category name and returns that category’s total revenue, then call it for each category.

Test your code on this first: juice drinks 90p × 8 = 720, cola drinks 100p × 3 = 300, crisps snacks 60p × 10 = 600, bar snacks 45p × 15 = 675 → snacks-1275 (drinks only reach 1020)

Answer format: category-pence in lower case, e.g. snacks-1275
Skills: records, parameter passing (array and string), totals per category, find the maximum

Evidence file: tuckshop.csv (also in the evidence bag)

Room 3

The Vault

Real problem-solving. Opening all five is the stretch.

DOOR LOCKED

The The Vault door is locked. Open 3 of the 5 locks in the Server Room to get through.

C1

Secret message

LOCKED

An encrypted message is in data/secret.txt. Every letter was shifted forward through the alphabet by an amount taken from a repeating keyword: VAULT. The first letter of the message moves by V (21 places, since A = 0), the second by A (0), the third by U (20), then L (11), T (19), and then the keyword starts again. Spaces and full stops are left alone and do not use up a keyword letter.

Your task: Decrypt the message. The passphrase is hidden inside it.

Test your code on this first: With keyword BAD, IEOMO decrypts to HELLO

Answer format: The passphrase in lower case
Skills: ASCII codes (ord and chr), modular arithmetic, keeping a separate position in the keyword, string building

Evidence file: secret.txt (also in the evidence bag)

C2

Sensor tape

LOCKED

A sensor on the vault wall records temperature changes as 8-bit two’s complement binary numbers. The tape is in data/sensor.txt (64 readings, one per line, such as 11111100). The leftmost bit is the sign bit.

Your task: Convert every reading to the signed denary number it stores. Give the total of all the readings and how many are negative. (Do not just use int(reading, 2) on its own: that treats the sign bit as an ordinary bit.)

Test your code on this first: 00001010 = 10, 11111100 = −4, 10000000 = −128, 01111111 = 127 → 5-2

Answer format: total-negatives, e.g. 5-2 (the total can be negative: write it as -12-30)
Skills: two’s complement, binary to denary conversion, reading a file, running total, counting

Evidence file: sensor.txt (also in the evidence bag)

C3

Prime suspects

LOCKED

The vault’s inner door only opens for twin primes: two prime numbers that differ by exactly 2, like 11 and 13.

Your task: Count the pairs of twin primes where both numbers are below 10000, and give the smaller number of the largest pair.

Test your code on this first: Both below 30: (3,5), (5,7), (11,13), (17,19) → 4-17 (29 and 31 do not count because 31 is not below 30)

Answer format: count-smaller, e.g. 4-17
Skills: sub-program to test for a prime, nested loops, efficient algorithm design

C4

Minefield

LOCKED

data/board.txt is a 20 × 20 minesweeper board: * is a mine, . is a safe square.

Your task: Every safe square shows how many of its (up to 8) neighbours are mines. Give the total of all the numbers on safe squares and the largest single number on the board.

Test your code on this first:
*..
...
..*
shows 1,0 / 1,2,1 / 0,1 so the total is 6 and the largest is 2 → 6-2

Answer format: total-largest, e.g. 6-2
Skills: 2-D arrays, nested loops, boundary checking, standard algorithms

Evidence file: board.txt (also in the evidence bag)

C5

Pipework

LOCKED

The vault is full of old pipework. data/vault.txt is a 14 × 14 map: . is open pipe and # is a blockage. Water starts in the top-left corner and must reach the bottom-right corner, moving only right or down one square at a time, never through a #.

Your task: How many different routes can the water take?

Test your code on this first:
..#
...
#..
has 4 routes.

Answer format: A whole number (it will be big, so do not try to list every route)
Skills: 2-D arrays, nested loops, algorithm design (build up the answer square by square)

Evidence file: vault.txt (also in the evidence bag)

You escaped!

All 15 locks open. Say the exit code to the person at the door:

HAVE A GREAT BREAK
Name:Date: