1
0
Fork 0
advent2017/2/2p1.py

35 lines
735 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
inputs = ["part1.txt", "input.txt"]
def solve(filename):
total = 0
with open(filename) as tsv:
for line in csv.reader(tsv, dialect="excel-tab"):
difference = None
big = None
small = None
for item in line:
i = int(item)
if big is None and small is None:
big = i
small = i
if i > big:
big = i
if i < small:
small = i
difference = big - small
total += difference
return int(total)
for puzzle in inputs:
print(puzzle, solve(puzzle))