# Perl Weekly Challenge Solutions This repository contains solutions for the Perl Weekly Challenge tasks in both Perl and Python. Below is a summary of the tasks and the implemented solutions. ## Task 1: Zero Friend ### Description Given a list of numbers, find the number closest to zero and return its distance to zero. If zero is present in the list, it is considered the closest, and the distance is 0. ### Solution - **Perl (`ch-1.pl`)**: The `zero_friend` function iterates through the list of numbers, computing the absolute value of each to find the minimum distance to zero. If the list is empty, it returns 0. - **Python (`ch-1.py`)**: The `zero_friend` function uses a list comprehension with `min` and `abs` to find the smallest absolute value in the list. Returns 0 for an empty list. - **Test Cases**: - `(4, 2, -1, 3, -2)` → `1` - `(-5, 5, -3, 3, -1, 1)` → `1` - `(7, -3, 0, 2, -8)` → `0` - `(-2, -5, -1, -8)` → `1` - `(-2, 2, -4, 4, -1, 1)` → `1` ## Task 2: Champion Team ### Description Given a matrix `grid` where `grid[i][j] == 1` means team `i` is stronger than team `j`, and `grid[i][j] == 0` means team `j` is stronger, find the champion team with the most wins. If multiple teams tie for the most wins, return the one that beats the others. ### Solution - **Perl (`ch-2.pl`)**: The `champion_team` function counts wins for each team by summing the rows of the grid (excluding self-comparisons). It identifies teams with the maximum wins and, if multiple, checks which one beats the others based on the grid. - **Python (`ch-2.py`)**: Similar to the Perl solution, it counts wins per team, finds those with the maximum wins, and selects the champion by checking which team beats all other top teams. - **Test Cases**: - `[[0, 1, 1], [0, 0, 1], [0, 0, 0]]` → `Team 0` - `[[0, 1, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 0]]` → `Team 3` - `[[0, 1, 0, 1], [0, 0, 1, 1], [1, 0, 0, 0], [0, 0, 1, 0]]` → `Team 0` - `[[0, 1, 1], [0, 0, 0], [0, 1, 0]]` → `Team 0` - `[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 1, 0, 0, 0], [1, 1, 0, 1, 0]]` → `Team 2` ## Running the Solutions - **Perl**: Run `perl ch-1.pl` or `perl ch-2.pl` to execute the tests. - **Python**: Run `python3 ch-1.py` or `python3 ch-2.py` to execute the tests. - The solutions have been validated with `flake8`, `pyupgrade`, `bandit` (Python), and `Perl::Critic` (Perl) to ensure code quality.