Welcome back, Puzzlers. Let's take a crack at the latest Sunday Puzzle from NPR:
This week's challenge comes from listener Iva Allen in Canada. Name a make of car. Write it in all capital letters. Rotate one of the letters 90 degrees and another letter 180 degrees to make a woman's name. What is it?
What do we need in order to solve this?
- C: A list of car "makes"; let's assume this means "brands" or "manufacturers";
- G: A list of girl names;
- R90: A dictionary mapping of capital letters that can be rotated 90 degrees to form a new letter;
- {'C': 'U', ...}
- R180: A dictionary mapping of capital letters that can be rotated 180 degrees to form a new letter;
- {'M': 'W', ...}
Now, we iterate through each car maker. Then we'll need to iterate through the letters and determine which ones are in R90 and R180---we make a list of all indices in the string where the letter at that index can be rotated 90 degrees, and another list of indices for 180 degrees. Then we use something like "itertools.product()" to generate all pairs of one 90-degree position and one 180-degree position (where the two positions are not the same---we want to rotate two different letters (indices) in the string). Then we take this "agenda" of pair rotations and apply the rotation mappings to the original string, so we have all possible strings generated from the car maker string. For example:
ACURA --> ['VUURA', 'AUARA', 'VCCRA']
Then, we simply iterate through each of these variants and compare it against G, the list of girls' names and print out the car maker and the girl name when find a match.
Sounds simple enough, right? I'll be back after the Thursday NPR submission deadline to share my solution. Good luck!