What word is hidden in this block tower?
The hidden word is ALUMINIUM. The block tower of this puzzle is constructed as follows. Start with the uppercase letters in alphabetic order and give the vowels a red color.
Cut the alphabet after each letter that appears in the hidden word.
In this case we cut after the letters A, I, L, M, N and U, leaving the following fragments.
Use these fragments to construct a block tower by stacking the fragments from the shortest (top) to the longest (bottom). Fragments having the same length are stacked in alphabetical order (from top to bottom).
As a last step, the letters are removed from the block tower and the puzzle is ready to be solved.
A block tower from the above puzzle can be described by the following two data structures:
a tuple containing the lengths (int) of the rows in the tower (listed from top to bottom)
a set containing the positions of the vowels in the tower; the rows of the tower are numbered from top to bottom, and the columns from left to right, each time starting from zero; as such, the position of a block in the tower can be represented as a tuple $$(r, c)$$, with $$r$$ (int) the number of the row and $$c$$ (int) the number of the column where the block occurs in the tower
Determine these two data structures for the block tower corresponding to a given hidden word. This is done in the following way:
Write a function letters that takes a word (str). The function must return a list containing all letters (str) that appear in the word, uppercased and listed in alphabetic order. If the same letter appears more than once in the word, it must be listed only once. If the word contains characters that are no letters, they should not be included in the list.
Write a function fragments that takes a word (str). The function must return a list containing all fragments (str) that are obtained by cutting the alphabet after each letter in the given word. The fragments must be listed in alphabetic order.
Write a function block_tower that takes a word (str). The function must return a tuple containing all fragments (str) that are obtained by cutting the alphabet after each letter in the given word. The fragments must be listed from the shortest to the longest, with fragments having the same length listed in alphabetic order.
The tuple returned by the function is called the tuple representation of the block tower that hides the given word.
Write a function row_lengths that takes the tuple representation of a block tower that hides a word. The function must return a tuple containing the lengths (int) of the rows in the given block tower (listed from top to bottom).
Write a function vowel_positions that takes the tuple representation of a block tower that hides a word. The function must return a set containing the positions of all vowels in the given block tower.
>>> letters('ALUMINIUM')
['A', 'I', 'L', 'M', 'N', 'U']
>>> fragments('ALUMINIUM')
['A', 'BCDEFGHI', 'JKL', 'M', 'N', 'OPQRSTU', 'VWXYZ']
>>> tower = block_tower('ALUMINIUM')
>>> tower
('A', 'M', 'N', 'JKL', 'VWXYZ', 'OPQRSTU', 'BCDEFGHI')
>>> row_lengths(tower)
(1, 1, 1, 3, 5, 7, 8)
>>> vowel_positions(tower)
{(0, 0), (6, 7), (5, 6), (6, 3), (5, 0)}