回答編集履歴

3

修正

2020/06/25 18:10

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -40,13 +40,7 @@
40
40
 
41
41
  def decode(codes):
42
42
 
43
- for code in codes:
44
-
45
- val = (code[0] - 1) * 5 + code[1]
46
-
47
- print(codedict.get(val),end="")
43
+ print(''.join((codedict.get((code[0] - 1) * 5 + code[1]) for code in codes)))
48
-
49
- print()
50
44
 
51
45
 
52
46
 
@@ -54,11 +48,11 @@
54
48
 
55
49
  message = "PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS"
56
50
 
57
- codes = ((3, 5),(1, 1),(1, 3),(1, 3),(3, 2),(5, 4),(1, 2),(3, 4),(5, 3),(5, 2),(2, 4),(4, 4),(2, 3),(2, 1),(2, 4),(5, 1),(1, 5),(1, 4),(3, 4),(5, 5),(1, 5),(3, 3),(3, 1),(2, 4),(4, 1),(4, 5),(3, 4),(4, 2),(2, 5),(4, 5),(2, 2),(4, 3))
51
+ encode(message)
58
52
 
59
53
 
60
54
 
61
- encode(message)
55
+ codes = ((3, 5),(1, 1),(1, 3),(1, 3),(3, 2),(5, 4),(1, 2),(3, 4),(5, 3),(5, 2),(2, 4),(4, 4),(2, 3),(2, 1),(2, 4),(5, 1),(1, 5),(1, 4),(3, 4),(5, 5),(1, 5),(3, 3),(3, 1),(2, 4),(4, 1),(4, 5),(3, 4),(4, 2),(2, 5),(4, 5),(2, 2),(4, 3))
62
56
 
63
57
  decode(codes)
64
58
 

2

修正

2020/06/25 18:10

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -28,15 +28,13 @@
28
28
 
29
29
 
30
30
 
31
+
32
+
31
33
  def encode(message):
32
34
 
33
- for char in message:
35
+ print(tuple(knockdict.get(char) for char in message if char!=" "))
34
36
 
35
- if char!=" ":
37
+
36
-
37
- print(str(knockdict.get(char)),end="")
38
-
39
- print()
40
38
 
41
39
 
42
40
 
@@ -72,7 +70,9 @@
72
70
 
73
71
  ```
74
72
 
75
- (3, 5)(1, 1)(1, 3)(1, 3)(3, 2)(5, 4)(1, 2)(3, 4)(5, 3)(5, 2)(2, 4)(4, 4)(2, 3)(2, 1)(2, 4)(5, 1)(1, 5)(1, 4)(3, 4)(5, 5)(1, 5)(3, 3)(3, 1)(2, 4)(4, 1)(4, 5)(3, 4)(4, 2)(2, 5)(4, 5)(2, 2)(4, 3)
73
+ ((3, 5), (1, 1), (1, 3), (1, 3), (3, 2), (5, 4), (1, 2), (3, 4), (5, 3), (5, 2), (2, 4), (4, 4), (2, 3), (2, 1), (2, 4), (5, 1), (1, 5), (1, 4), (3, 4), (5, 5), (1, 5), (3, 3), (3, 1), (2, 4), (4, 1), (4, 5), (3, 4), (4, 2),
74
+
75
+ (2, 5), (4, 5), (2, 2), (4, 3))
76
76
 
77
77
 
78
78
 

1

修正

2020/06/25 18:07

投稿

sfdust
sfdust

スコア1137

test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  knockdict['K'] = knockdict['C']
26
26
 
27
- codedict = {(knockdict[char][0]-1)*5 + knockdict[char][1]:char for char in knockdict.keys()}
27
+ codedict = {(v[0] - 1) * 5 + v[1]: k for k, v in knockdict.items()}
28
28
 
29
29
 
30
30