Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4aa8854

Browse files
simplified
1 parent 8c998a6 commit 4aa8854

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

‎2022/13.py‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#!/usr/bin/env python
2-
from math import prod
3-
from functools import cmp_to_key
4-
5-
62
def cmp(left, right):
73
match left, right:
84
case int(), list():
@@ -18,22 +14,19 @@ def cmp(left, right):
1814
return cmp(len(left), len(right))
1915

2016

21-
# fmt:off
22-
packets = [
17+
# fmt:off
18+
s1, two, six, packets =0, 1, 2, [
2319
eval(line)
2420
for line in open(0).read().splitlines()
2521
if len(line)
2622
]
23+
# fmt:on
24+
for i, (left, right) in enumerate(zip(packets[::2], packets[1::2])):
25+
if cmp(left, right) <= 0:
26+
s1 += i + 1
27+
for x in left, right:
28+
two += cmp(x, [[2]]) <= 0
29+
six += cmp(x, [[6]]) <= 0
2730

28-
print(sum(
29-
i + 1
30-
for i, (left, right) in enumerate(zip(packets[::2], packets[1::2]))
31-
if cmp(left, right) <= 0
32-
))
33-
34-
two_six = [[[2]], [[6]]]
35-
print(prod(
36-
i + 1
37-
for i, packet in enumerate(sorted(packets + two_six, key=cmp_to_key(cmp)))
38-
if packet in two_six
39-
))
31+
print(s1)
32+
print(two * six)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /