Menu

Weekly Challenge: An average reflection
📰

Weekly Challenge: An average reflection

DEV Community: perl·Simon Green·15 days ago
#WOGCCSxI
#devtoperl#devto#dev#ints#average
Reading 0:00
15s threshold

Weekly Challenge 397

Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding.

Challenge , My solutions

Task 1: Absent Smallest Positive

You are given an array of integers.

Write a script to return the smallest absent positive integer such that it is strictly greater than the average of all elements in the given array.

My solution

This is relatively straight forward. I start by calculating the average and storing it in the variable average . The result variable one more than the average or 1 if the average is less than 1.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.