Computer Science Warmups: Level 5 Challenges

There is reason to believe that this text was not encrypted with the sophisticated German Enigma machine but instead used a Vigenère cipher with a simple pass phrase. Thus, it is vulnerable to frequency analysis.

Decode this message and find out where the Germans are sending their bombers so we can evacuate the civilians. You will enter the number of the district (as shown in this list) to submit your answer.

Details and assumptions

A Vigenère cipher is a more complicated shift cipher. For example, rather than shifting every character in a word by two letters like this:

SECRET -> UGETGV

you would instead choose a pass phrase (e.g., "CAT"), which would then tell you to shift each of the letters in your plain text by the letter in the passphrase ("C" is a shift of 2 character, "A" is a shift of none, etc. ) :

A toy model for a growing network is the recursive tree. The tree starts as a single node and at each step in the growth process, one new node is added which makes a single connection, at random, to an existing node.

Assume that the network has grown large enough so that its statistical properties are effectively constant. The fractions of nodes that have connections to exactly 7 other nodes is given by some fraction ab\dfrac abba​, where aaa and bbb are positive coprime integers. What is the value of a+ba + ba+b?

Consider the 2×2×22\times 2\times 22×2×2 cube puzzle, shown above. It consists of 8 pieces that start out in the solved orientation and can be transformed into alternative orientations by rotating any of the six faces.

To start, let us consider the two moves R2\mbox{R}_2R2​ and U2\mbox{U}_2U2​. When R2\mbox{R}_2R2​ is performed, the right side of the cube is spun two quarter rotations clockwise. Similarly, U2\mbox{U}_2U2​ indicates that the top layer (U=\mbox{U}=U=Up) is spun two quarter rotations clockwise. Whenever a face gets two quarter turns, each piece in that face ends up diagonal to its original position on the face.

We start transforming the cube by performing R2\mbox{R}_2R2​ followed by U2\mbox{U}_2U2​. We call this sequence of events the R2U2\mbox{R}_2\mbox{U}_2R2​U2​ permutation. How many R2U2\mbox{R}_2\mbox{U}_2R2​U2​ permutations do we go through before the 2×2×22\times 2\times 22×2×2 cube is back to its original state?

Note:
The R2\mbox{R}_2R2​ and U2\mbox{U}_2U2​ moves are displayed below on a 3×3×33\times3\times33×3×3 cube.

Consider an N×NN \times NN×N grid of lights, each one either on or off. The grid can be manipulated by pressing any one light on the grid, toggling the light - however, when a given light is pressed, all lights that are edge-wise adjacent to the pressed light also get toggled.

Given an initial configuration, one might be interested in a sequence of moves that turns all of the lights on the board off, or more simply, whether such a sequence exists or not. For example, the following 5×55 \times 55×5 grid can be solved by pressing the five numbered squares in their labeled order:

As surprising as it may seem, this second board is provably unsolvable. There is no sequence of moves in existence that turns all of the lights off:

Grid configurations will be represented as a series of lines in a text file. The first line will be a single integer, NNN, specifying the size of the grid. The following NNN lines will specify the contents of the grid, where '#\text{\#}#' characters indicate lights that are on, and '.\text{.}.' characters indicate lights that are off. The two grid configurations above would be encoded as:

1
2
3
4
5
6
7
8
9
10
11
12

5
.#..#
#..#.
#.#..
.####
...#.
5
.#...
.##..
#....
.....
.....

Clicking lights.txt will trigger a download of a ~300KB zip file, which contains a text file named "lights.txt". The text file contains, in the specified format, 100001000010000 light grids, with sizes 5≤N≤165 \leq N \leq 165≤N≤16. Precisely XXX of these grids are solvable.

Find XXX.

Note: An efficient program can find XXX in well under one minute. If your program is taking hours to complete, you may need to rethink your approach.

In the world of pencil puzzles, there are many puzzle types where you have to draw a loop on a lattice grid, including Country Road, Masyu, Pure Loop, Slalom, and Yajilin. In most of these puzzles (and all of the linked above), the loop visits some of the cells, passing through the cells' centers, and may not use a cell more than once (which also means no intersections, no touching itself, etc).

Formally, on a polyomino PPP, a loop is a sequence of n≥4n \ge 4n≥4 squares (a1,a2,a3,…,an)(a_1, a_2, a_3, \ldots, a_n)(a1​,a2​,a3​,…,an​) such that all squares aia_iai​ are in PPP, aia_iai​ and ai+1a_{i+1}ai+1​ share a side for all valid iii, ana_nan​ and a1a_1a1​ also share a side, and all squares in the loop are distinct. Loops are cyclic (it can start from any square in the loop) and don't have any orientation (reversing the loop doesn't matter), thus (a1,a2,a3,a4),(a2,a3,a4,a1),(a4,a3,a2,a1)(a_1, a_2, a_3, a_4), (a_2, a_3, a_4, a_1), (a_4, a_3, a_2, a_1)(a1​,a2​,a3​,a4​),(a2​,a3​,a4​,a1​),(a4​,a3​,a2​,a1​) all describe the same loop.