# Perl Weekly Challenge: Broken Keyboard and Reverse Prefix ## Task 1: Broken Keyboard ### Description Given a string containing English letters and a list of broken keys, return the count of words that can be typed completely without using any broken keys. The check is case-insensitive. ### Solution - **Perl (ch-1.pl)**: The `broken_keyboard` function splits the input string into words and checks each word against a hash of broken keys. If a word contains no broken keys, it increments a counter. The function uses `split` for word separation and a hash for O(1) key lookup. - **Python (ch-1.py)**: The `broken_keyboard` function uses a set for broken keys lookup, splits the string into words, and counts words that don't contain any broken keys. It uses `str.split()` and a set for efficient lookup. ### Test Cases 1. Input: "Hello World", ['d'] → Output: 1 2. Input: "apple banana cherry", ['a', 'e'] → Output: 0 3. Input: "Coding is fun", [] → Output: 3 4. Input: "The Weekly Challenge", ['a', 'b'] → Output: 2 5. Input: "Perl and Python", ['p'] → Output: 1 ## Task 2: Reverse Prefix ### Description Given a string and a character, reverse the prefix of the string up to and including the first occurrence of the character, and return the new string. If the character is not found, return the original string. ### Solution - **Perl (ch-2.pl)**: The `reverse_prefix` function uses `index` to find the character's position, extracts the prefix with `substr`, reverses it, and appends the remaining string. - **Python (ch-2.py)**: The `reverse_prefix` function uses `str.find` to locate the character, slices the prefix, reverses it using slice notation `[::-1]`, and concatenates the rest of the string. ### Test Cases 1. Input: "programming", "g" → Output: "gorpramming" 2. Input: "hello", "h" → Output: "hello" 3. Input: "abcdefghij", "h" → Output: "hgfedcbaij" 4. Input: "reverse", "s" → Output: "srevere" 5. Input: "perl", "r" → Output: "repl"