advent-of-code/2017/day-2-part-1.py
2019-12-01 15:03:09 -06:00

35 lines
767 B
Python
Executable file

#!/usr/bin/env python3
# usage: cat inputs/day-2.txt | ./$SCRIPTNAME.py
import sys
def spreadsheet_line(line, sep="\t"):
highest = -sys.maxsize
lowest = sys.maxsize
numbers = map(int, line.strip().split(sep))
try:
for x in numbers:
if x < lowest:
lowest = x
if x > highest:
highest = x
except:
return
return highest - lowest
def checksum(spreadsheet_text, line_sep="\n"):
total = 0
lines = spreadsheet_text.split(line_sep)
for line in lines:
line_diff = spreadsheet_line(line)
try:
total += line_diff
except:
pass
return total
if __name__ == "__main__":
print(checksum(sys.stdin.read()).strip())