You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 satır
678B

  1. import re
  2. from collections import Counter
  3. from itertools import cycle
  4. from math import copysign
  5. sign = lambda n: int(copysign(1, n))
  6. points = {'flat': Counter(), 'diag': Counter()}
  7. for line in open(0):
  8. x1, y1, x2, y2 = [int(n) for n in re.findall(r'\d+', line)]
  9. xs = [*range(x1, x2, sign(x2 - x1)), x2]
  10. ys = [*range(y1, y2, sign(y2 - y1)), y2]
  11. if len(xs) == 1:
  12. points['flat'].update(zip(cycle(xs), ys))
  13. elif len(ys) == 1:
  14. points['flat'].update(zip(xs, cycle(ys)))
  15. else:
  16. points['diag'].update(zip(xs, ys))
  17. print(sum(v > 1 for v in (points['flat']).values()))
  18. print(sum(v > 1 for v in (points['flat'] + points['diag']).values()))