Hello! Are you ready for an exciting journey into the world of strings and frequency analysis? Today, we’ll assist Alice, an aspiring cryptographer, with a fascinating task involving string transformations and calculations. Alice has developed a unique encoding scheme that shifts letters in the alphabet and analyzes their occurrences.
This should be a fun and insightful challenge that hones your problem-solving and coding skills. Let’s dive in!
Alice's encoding scheme involves two steps. First, she takes a word and shifts each character to the next one alphabetically. For example:
'a'
becomes'b'
'z'
becomes'a'
Next, Alice analyzes the frequency of each character in the transformed string. For each unique character, she calculates a product of its ASCII value and its frequency. Finally, she sorts these products in descending order.
Your task is to implement a Ruby method, character_frequency_encoding(word)
, that performs Alice’s encoding and returns the sorted list of products.
For example:
The method should return:
Here’s how the process works:
- Transform
"banana"
into .
