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.

20 lines
538B

  1. from collections import Counter
  2. app = eps = ''
  3. for col in zip(*text.splitlines()):
  4. n, *_, m = Counter(col).most_common()
  5. app += n[0]
  6. eps += m[0]
  7. ans1 = int(app, 2) * int(eps, 2)
  8. nums = text.splitlines()
  9. xs = nums[:]
  10. ys = nums[:]
  11. for idx in range(len(nums[0])):
  12. n, _ = Counter(sorted([x[idx] for x in xs])).most_common()[::-1][0]
  13. xs = [x for x in xs if x[idx] == n]
  14. m, _ = Counter(sorted([y[idx] for y in ys])).most_common()[::-1][-1]
  15. ys = [y for y in ys if y[idx] == m]
  16. ans2 = int(xs[0], 2) * int(ys[0], 2)