It is election week in the US, and the result is an unexpectedly huge mandate for reigning in corruption. Breathing a sigh of relief, I can amuse myself with Weekly Challenge 398 . As a hopeful sun rises over the lake on this frosty November morning, the music in the backround is the Spotify playlist This is America
Task 1: Divisible average
Task Description
You are given an array of positive integers. Write a script to return the closest integer to the mean value of all even integers that are divisible by 3. If none is divisible, return 0.
Example 1: Input: @arr = (18, 5, 7, 11)
Output: 18
18 is the only even number and divisible by 3. Average: 18 / 1 = 18.
Example 2: - Input: @arr = (6, 12, 18, 24, 30, 40)
Output: 18
The qualifying numbers are 6, 12, 18, 24, and 30. Average: (6 + 12 + 18 + 24 + 30) / 5 = 90 / 5 = 18
Example 3: - Input: @arr = (3, 9, 15, 21, 27)
Output: 0
None of the elements are even.…