Advertisement
icarussiano

day 1 Python/Julia

Dec 1st, 2024 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #Python
  2. left, right = map(sorted, zip(*[map(int, line.split()) for line in open("input.txt)]))
  3. print(sum(abs(i-j) for i,j in zip(left,right)))
  4. print(sum(i*right.count(i) for i in left))
  5.  
  6. #Julia
  7. using DelimitedFiles
  8. left, right = map(x -> sort(readdlm("input.txt", Int)[:, x]), 1:2)
  9. println(sum(abs, left-right))
  10. println(sum(i * count(x -> x == i, right) for i in left))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement