Guest User

Untitled

a guest
Dec 7th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import sys
  2.  
  3. # The spreadsheet consists of rows of apparently-random numbers.
  4. # To make sure the recovery process is on the right track, they need
  5. # you to calculate the spreadsheet's checksum. For each row, determine
  6. # the difference between the largest value and the smallest value; the
  7. # checksum is the sum of all of these differences.
  8. #
  9. # For example, given the following spreadsheet:
  10. #
  11. # 5 1 9 5
  12. # 7 5 3
  13. # 2 4 6 8
  14. #
  15. # The 1st row's max and min values are 9 and 1, and the difference is 8.
  16. # The second row's max and min values are 7 and 3, and their difference is 4.
  17. # The third row's difference is 6.
  18. # In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
  19.  
  20.  
  21. def min_max(inp):
  22. arr = [int(num) for num in inp.split()]
  23. return max(arr) - min(arr)
  24.  
  25.  
  26. if __name__ == "__main__":
  27. ret = 0
  28. with open(sys.argv[1]) as data:
  29. for line in data:
  30. ret += min_max(line)
  31.  
  32. print(ret)
Add Comment
Please, Sign In to add comment