# POTD 15 skel
# Author: <anonymized>
# Date: 05/18/2025
# Description: Writing a function that performs a smoothing operation on a
# list of numbers.

""" Could not figure out how to implement the print_rounded function. Though
    the lists printed are not rounded, the numbers and means returned from the
    smooth function are the right values. """

import sys

def mean(nums):
    """ Return the arithmetic mean (i.e., average) of the list of numbers
    nums. Precondition: nums is not empty and contains only numbers.
    Does not modify its input (nums). """
    num_sum = 0
    d = 0
    for n in nums:
        num_sum += n
        d += 1
    result = num_sum / d
    return result

def smooth(nums):
    """ Return a smoothed copy of nums, where each element in the resulting
    list is the average of its old value and its two neighbors. The neighbor
    relation "wraps": that is, the first element's left neighbor should be the
    last element, and similarly the last element's right neighbor is the first
    element. For example, if we call smooth([a, b, c, d]), it should return a
    list [a', b', c', d'], where:
        a' is the average of d, a, and b
        b' is the average of a, b, and c
        c' is the average of b, c, and d
        d' is the average of c, d, and a
    Preconditions: nums contains only numbers and has length at least 3.
    This function does *not* modify the input list (nums)."""
    result = ""
    for i in range(t):  
        a_short = nums[:2]
        a_short.append(nums[4])
        A = mean(a_short)
        B = mean(nums[:3])
        C = mean(nums[1:4])
        D = mean(nums[2:5])
        e_short = nums[3:5]
        e_short.append(nums[0])
        E = mean(e_short)
        nums = [A, B, C, D, E]
        result += f"{nums} Mean: {mean(nums)}\n"
    return result


def print_rounded(nums, end="\n"):
    """ Prints a list of numbers, rounded to the given number of decimal
    places. Does not modify nums. This function is provided for you
    and is only needed for use in the main program. You are not required
    to understand the details of how it works. """ 
    print("[", end="")
    for i in range(len(nums)-1):
        print(f"{nums[i]:3.2f}", end=", ")
    print(f"{nums[-1]:3.2f}]", end=end)

if __name__ == "__main__":
    
    t = int(sys.argv[1])
    a = int(sys.argv[2])
    b = int(sys.argv[3])
    c = int(sys.argv[4])
    d = int(sys.argv[5])
    e = int(sys.argv[6])
    
    nums = [a, b, c, d, e]

    print(smooth(nums))
    
#    print_rounded(smooth(nums), end="\n")
    
    
    