Challenges

Subsets

Easy-Medium

Write a function that finds all the possible sets of a given set (array). E.g. the subsets of \(\{2,5\}\) are \(\{\},\{2\},\{5\},\{2,5\}\). Don't forget to include \(\emptyset\) (the empty set).

Input: array of items (not necessarily of any particular type!). The code should print to standard output or return an array of arrays representing the subsets. Note that 'array' refers to 'list' in languages such as Python or Haskell.

Counting Cards

Medium

Given an array of \(n\) integers representing the values of a fixed sequence of \(n\) cards, find the largest value obtainable by selecting a \(\textbf{consecutive}\) sequence of cards. E.g. for the array \(\{3,-5,2,4,-1\}\) this would be \(6\). The value of any given card \(v \in \mathbb{Z}\) is an integer and can be negative!

Input: array/list of integers. The code should print to standard output or return an integer which is the largest obtainable value.

Maya Calendar

Medium-Hard

The Maya calendar (pictured) is formed of 3 concentric circles with symbols, which need to be rotated by different amounts each. Given a 'calendar' of \(n\) circles represented by a matrix (array of arrays), where each 'layer' of the matrix corresponds to a circle, and an array of \(n\) values representing the amounts by which to rotate each of the \(n\) circles \(\textbf{anti-clockwise}\) from outer to inner, return the calendar after the appropriate rotations have been performed. See the details tab for an example.

With an input array \(\{2,-1\}\): \[ \begin{pmatrix} 1 & 6 & 2 & 0 \\ 4 & 2 & 8 & 4 \\ 1 & 3 & 9 & 7 \\ 0 & 2 & 5 & 11 \end{pmatrix} \longrightarrow \begin{pmatrix} 2 & 0 & 4 & 7 \\ 6 & 3 & 2 & 11 \\ 1 & 9 & 8 & 5 \\ 4 & 1 & 0 & 2 \end{pmatrix} \] You can see that the outer circle (layer) has been rotated anti-clockwise by \(2\) and the inner circle by \(-1\) (same as clockwise by \(1\)). Note that the matrix \(p \times q\) is \(\textbf{not necessarily square}\), but you are guaranteed that \(min(p,q)\) is even, so you will always have a circle to rotate.

Want to hear from us?