You can order nine kinds of cocktails at the bar. Yet there seems to be only eight cocktails on the drinks menu. Can you find out the ninth kind of cocktail that is hidden in the drinks menu?

drinks menu
You can order nine kinds of cocktails at the bar. Yet there seems to be only eight cocktails on the drinks menu. Can you find out the ninth kind of cocktail that is hidden in the drinks menu?

Answer: Shirley Temple Black1

To find the name of the hidden cocktail, first sort the cocktails on the drinks menu in ascending order by the number after the decimal comma in their price:

Sex on the beach (09)
Cuba libre (44)
Bramble (51)
Mary Pickford (56)
Tuxedo (68)
Cosmopolitan (69)
Suffering bastard (86)
Black Russian (88)

In the price of a cocktail, the number before the decimal comma then determines which characters should be selected from the name of the cocktail. This selection is based on a conversion of the (decimal) number into its binary representation. Reverse that binary representation and fill it with zeros at the end until it has the same length as the name of the cocktail. Then select the corresponding character from the name of the cocktail wherever there is a 1 in the reverse binary representation.

2571000000011000000010000000Sex on the beachSh
3201010000000000001010Cuba libreir
9611000000000011Bramblele
24110000001100000000Mary Pickfordy␣
91001100100TuxedoTe
16810101000000101010000Cosmopolitanmpl
528100001000000001000010000000Suffering bastarde␣
31111111111100000000Black RussianBlack

The name of the hidden cocktail is now obtained by concatenating all selected characters: Shirley Temple Black.

Assignment

A drinks menu is a text file with UTF-82 character encoding that contains prices for a list of cocktails. This is an example drinks menu that corresponds to the image in the introduction (cocktails.txt3):

Black Russian...............€31,88
Bramble.....................€96,51
Cosmopolitan...............€168,69
Cuba libre.................€320,44
Mary Pickford...............€24,56
Sex on the beach...........€257,09
Suffering bastard..........€528,86
Tuxedo.......................€9,68

Each line of the text file contains the description of a cocktail. The description starts with the name of the cocktail, which never contains any dots (.). This is followed by one or more dots (.), a euro symbol () and the price of the cocktail. The price is always represented with two digits after a decimal comma (,). A drinks menu never contains cocktails that have the same two digits after the decimal comma in their price.

Your task is to extract the name of the hidden cocktail from a drinks menu. This is done in the following way:

Example

In the following interactive session we assume that the text file cocktails.txt6 is located in the current directory.

>>> read_cocktail('Black Russian...............€31,88')
('Black Russian', 31, 88)
>>> read_cocktail('Cosmopolitan...............€168,69')
('Cosmopolitan', 168, 69)

>>> read_menu('cocktails.txt7')
[('Sex on the beach', 257, 9), ('Cuba libre', 320, 44), ('Bramble', 96, 51), ('Mary Pickford', 24, 56), ('Tuxedo', 9, 68), ('Cosmopolitan', 168, 69), ('Suffering bastard', 528, 86), ('Black Russian', 31, 88)]

>>> mask('Black Russian', 31)
'1111100000000'
>>> mask('Cosmopolitan', 168)
'000101010000'

>>> select('Black Russian', 31)
'Black'
>>> select('Cosmopolitan', 168)
'mpl'

>>> extract('cocktails.txt8')
'Shirley Temple Black'

Epilogue

Shirley Jane Temple9 (April 23, 1928 – February 10, 2014) was an American actress and diplomat. As a child with a diminutive stature, sparkling eyes, dimpled smile, and fifty-six blond curls, she became one of the most famous child stars in film history. Between 1932 and 1949 she appeared in more than fifty American movies and remains the youngest ever winner of an Academy Juvenile Award10. As an adult she adopted the name Shirley Temple Black and built a successful career as an ambassador.

Shirley Temple
Shirley Temple in 1938.

Her name is further immortalized by the mocktail named after her: the Shirley Temple11. This non-alcoholic mixed drink is traditionally made with ginger ale and a splash of grenadine, garnished with a maraschino cherry12. It is often served to children dining with adults in lieu of real cocktails. If dark rum is added, it is called a Sherley Temple Black13 as an homage to her married surname.