We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8c998a6 commit 4aa8854Copy full SHA for 4aa8854
2022/13.py
@@ -1,8 +1,4 @@
1
#!/usr/bin/env python
2
-from math import prod
3
-from functools import cmp_to_key
4
-
5
6
def cmp(left, right):
7
match left, right:
8
case int(), list():
@@ -18,22 +14,19 @@ def cmp(left, right):
18
14
return cmp(len(left), len(right))
19
15
20
16
21
-# fmt:off
22
-packets = [
17
+# fmt:off
+s1, two, six, packets =0, 1, 2, [
23
eval(line)
24
for line in open(0).read().splitlines()
25
if len(line)
26
]
+# fmt:on
+for i, (left, right) in enumerate(zip(packets[::2], packets[1::2])):
+ if cmp(left, right) <= 0:
+ s1 += i + 1
27
+ for x in left, right:
28
+ two += cmp(x, [[2]]) <= 0
29
+ six += cmp(x, [[6]]) <= 0
30
-print(sum(
- i + 1
- 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
37
- for i, packet in enumerate(sorted(packets + two_six, key=cmp_to_key(cmp)))
38
- if packet in two_six
39
+print(s1)
+print(two * six)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments