A seven-segment display1 is a form of electronic device for displaying decimal numerals (sometimes also hexadecimal letters). Calculator spelling2 is an unintended characteristic of the seven-segment display, in which the digits resemble letters of the Latin alphabet when read upside-down. As a result each digit is mapped onto a letter, creating a limited but functional subset of the alphabet, sometimes referred to as beghilosz.
The basic step of calculator spelling consists of mapping each digit onto a letter, resulting in the representation of words on a calculator display whose letters are taken from a subset of the alphabet. This is the default mapping of digits onto letters:
digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|---|---|
letter | O | I | Z | E | h | S | g | L | B |
The graphic below illustrates the term BEghILOSZ constructed from the inverted sequence 250714638:
Certain calculators omit the topmost stem on the digit 6 and the bottom-most stem on the 9. In such cases, 6 renders a lowercase q when turned upside-down, and 9 appears as a lowercase b. Extending the available alphabet to hexadecimal notation3 (generally available on lower-end scientific calculators, though not on basic models), b and d correspond to q and p respectively.
digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | b | C | d | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
letter | O | I | Z | E | h | S | g | L | B | b | Y | q | J | P | 3 | j |
Placing a calculator in front of a mirror produces the following mapping:
digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | b | C | d | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
letter | O | I | S | E | y | Z | a | r | B | e | A | d | J | b | 3 | z |
An alphabet is represented as a string in which each character occurs at most once. Your task:
Write a function digits2letters that takes two alphabets of equal length. The function must return a dictionary that maps each character in the first alphabet onto the character at the same position in the second alphabet.
Write a function beghilosz2text that takes two arguments: a string and a dictionary that maps characters onto characters. You may assume that each character in the given string occurs as a key in the given dictionary. The function must use the given dictionary to replace each character in the given string by its corresponding character in the dictionary. The resulting string must be reversed and this reversed string must be returned by the function.
Write a function letters2digits that takes a dictionary mapping the letters in a first alphabet onto the letters at the corresponding positions in a second alphabet. You may assume that both alphabets have equal length and that there's a one-to-one correspondence between the letters of both alphabets. The function must return the inverted mapping as a dictionary that maps the characters in the second alphabet onto the corresponding characters in the first alphabet.
Write a function text2beghilosz that takes two arguments: a string and a dictionary that maps characters onto characters. You may assume that each character in the given string occurs as a key in the given dictionary, or if the character is a letter, that at least one of its uppercase and lowercase versions occurs as a key in the alphabet. The function must use the given dictionary to replace each character in the given string by its corresponding character in the dictionary. If a character is a letter that does not occur as a key in the alphabet, the character must be replaced by the mapping of its corresponding uppercase/lowercase letter. The resulting string must be reversed and this reversed string must be returned by the function.
>>> c2l = digits2letters('012345678', 'OIZEhSgLB')
>>> c2l
{'1': 'I', '0': 'O', '3': 'E', '2': 'Z', '5': 'S', '4': 'h', '7': 'L', '6': 'g', '8': 'B'}
>>> beghilosz2text('250714638', c2l)
'BEghILOSZ'
>>> beghilosz2text('3722145', c2l)
'ShIZZLE'
>>> beghilosz2text('53177187714', c2l)
'hILLBILLIES'
>>> l2c = letters2digits(c2l)
>>> l2c
{'B': '8', 'E': '3', 'g': '6', 'I': '1', 'h': '4', 'L': '7', 'O': '0', 'S': '5', 'Z': '2'}
>>> text2beghilosz('BEghILOSZ', l2c)
'250714638'
>>> text2beghilosz('SHIZZLE', l2c)
'3722145'
>>> text2beghilosz('hillbillies', l2c)
'53177187714'
In the November 2010 Word Ways4, Mike Keith notes a striking coincidence:
Bible's Machine and Welding
6499 Blue Springs Pkwy
Mosheim, TN 37818
That' the address of a machine shop5 in eastern Tennessee (US), presumably owned by a family named Bible. Enter the zip code in a calculator and turn it upside down.