a guest Dec 7th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import sys
- # The spreadsheet consists of rows of apparently-random numbers.
- # To make sure the recovery process is on the right track, they need
- # you to calculate the spreadsheet's checksum. For each row, determine
- # the difference between the largest value and the smallest value; the
- # checksum is the sum of all of these differences.
- # For example, given the following spreadsheet:
- # 5 1 9 5
- # 7 5 3
- # 2 4 6 8
- # The 1st row's max and min values are 9 and 1, and the difference is 8.
- # The second row's max and min values are 7 and 3, and their difference is 4.
- # The third row's difference is 6.
- # In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
- def min_max(inp):
- arr = [int(num) for num in inp.split()]
- return max(arr) - min(arr)
- if __name__ == "__main__":
- ret = 0
- with open(sys.argv) as data:
- for line in data:
- ret += min_max(line)
RAW Paste Data