Robbie Hatley's Solutions To The Weekly Challenge #291 (Middle Index and Poker)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-10-13 through 2024-10-19 is #291. The tasks for challenge #291 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 291-1: "Middle Index" Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to find the leftmost middle index (MI) i.e. the smallest amongst all the possible ones. A "middle index" is an index where ints[0] + ints[1] + ... + ints[MI-1] == ints[MI+1] + ints[MI+2] + ... + ints[ints.length-1]. If MI == 0, the left side sum is considered to be 0. Similarly, if MI == ints.length - 1, the right side sum is considered to be 0. Return the leftmost MI that satisfies the condition, or -1 if there is no such index. Example 1: Input: @ints = (2, 3, -1, 8, 4)