import numpy
import os
import statistics


def small_gauss(n):
    return((n**2 + n) / 2)


def main():
    # Get file in lines and convert to int
    with open("input.txt", "r", encoding="utf-8") as file:
        # strip out the new line
        puzzle_lines = [line.rstrip('\n') for line in file]

    puzzle_lines_arr = puzzle_lines[0].split(",")
    # Convert to int
    puzzle_lines_int = [int(elem) for elem in puzzle_lines_arr]

    # Get median as first idea
    medi = statistics.median(puzzle_lines_int)
    devi = [abs(val - medi) for val in puzzle_lines_int]
    devi_sum = sum(numpy.array(devi))
    # Part 1
    result_p1 = devi_sum
    # Output
    print("Part1: " + str(result_p1))


    mean = int(statistics.mean(puzzle_lines_int))
    wdevi = [abs(val - mean) for val in puzzle_lines_int]
    fdevi = [small_gauss(n) for n in wdevi]
    fdevi_sum = sum(numpy.array(fdevi))
    # Part 2
    result_p2 = fdevi_sum
    # Output
    print("Part2: " + str(result_p2))


if __name__ == "__main__":
    main()

import numpy
import os
import statistics


def small_gauss(n):
    return((n**2 + n) / 2)


def main():
    # Get file in lines and convert to int
    with open("input.txt", "r", encoding="utf-8") as file:
        # strip out the new line
        puzzle_lines = [line.rstrip('\n') for line in file]

    puzzle_lines_arr = puzzle_lines[0].split(",")
    # Convert to int
    puzzle_lines_int = [int(elem) for elem in puzzle_lines_arr]

    # Get median as first idea
    medi = statistics.median(puzzle_lines_int)
    devi = [abs(val - medi) for val in puzzle_lines_int]
    devi_sum = sum(numpy.array(devi))
    # Part 1
    result_p1 = devi_sum
    # Output
    print("Part1: " + str(result_p1))


    mean = int(statistics.mean(puzzle_lines_int))
    wdevi = [abs(val - mean) for val in puzzle_lines_int]
    fdevi = [small_gauss(n) for n in wdevi]
    fdevi_sum = sum(numpy.array(fdevi))
    # Part 2
    result_p2 = fdevi_sum
    # Output
    print("Part2: " + str(result_p2))


if __name__ == "__main__":
    main()

# Get file in lines and convert to int # strip out the new line # Convert to int # Get median as first idea # Part 1 # Output # Part 2 # Output