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.

10 line
439B

  1. ans1 = ans2 = 0
  2. for line in text.splitlines():
  3. seqs = [frozenset(seq) for seq in re.findall(r'\w+', line)]
  4. _1,_7,_4, *pending,_8 = sorted(set(seqs), key=len)
  5. sorter = lambda x: [len(x &_8), len(x &_4), len(x &_1)]
  6. _2,_5,_3,_6,_0,_9 = sorted(pending, key=sorter)
  7. ns = [_0,_1,_2,_3,_4,_5,_6,_7,_8,_9]
  8. ans1 += sum(x in {_1, _7, _4, _8} for x in seqs[-4:])
  9. ans2 += int(''.join(str(ns.index(x)) for x in seqs[-4:]))