← Back to Index

Day 1: Part 2

Problem Description

In this part of the challenge, the task was to find the maximum value from the list of integers and then calculate the average of these numbers. The average is computed by dividing the total sum of the integers by the count of the integers. This requires careful handling of the input data to ensure that all values are correctly processed.

Approach

To tackle this problem, I followed these steps:
1. Reuse Previous Logic: I reused the input reading and processing logic from Part 1 to ensure consistency and reduce redundancy. This included reading the input file and converting the data into a list of integers.
2. Calculate Total and Count: After obtaining the list of integers, I calculated the total sum using the sum() function, as previously implemented. Additionally, I determined the count of integers using the len() function.
3. Average Calculation: The average was computed by dividing the total sum by the count of integers. I included a check to handle the case where the count might be zero to avoid division by zero errors.
4. Maximum Value: I used the built-in max() function to find the maximum value in the list of integers. This function efficiently returns the largest number in the list.
5. Output: Finally, I printed both the average and the maximum value.

This approach is efficient and maintains clarity by reusing existing code.

Key Insights

Concepts and Algorithms Used