12
12
Input: [“we”, “say”, “:”, “yes”] Output: [“we”, “say”, “:”, “yes”] Explanation: One possible encode method is: “we:;say:;:::;yes”
13
13
"""
14
14
15
+ #solution by rubix-coder
16
+ import random
17
+ class SolutionEncodeDecode :
18
+
19
+ def encode (strs ):
20
+ encoded_str = []
21
+ for s in strs :
22
+ encoded_str .append (f"{ random .randint (0 ,len (s ))} { s } { random .randbytes (3 )} { random .choice (strs )} " )
23
+ return encoded_str
24
+
25
+ def decode (strs ):
26
+ decoded_str = []
27
+ for s in strs :
28
+ decoded_str .append (f"{ s .split ("b'" )[0 ][1 :]} " )
29
+ return decoded_str
30
+ ""
31
+ prompts = ["lint" ,"code" ,"love" ,"you" ,"algorithms" ,"ML" ,"!" , "rubix" , "coder" ]
32
+
33
+
34
+
35
+ for _ in range (20 ,200 ):
36
+ msg = [random .choice (prompts ) for _ in range (1 ,random .randint (2 ,len (prompts )))]
37
+ encoded = SolutionEncodeDecode .encode (strs = msg )
38
+ print (f"encoded msg -> { encoded } " )
39
+ decode = SolutionEncodeDecode .decode (encoded )
40
+ print (f"decoded msg -> { decode } \n ############" )
15
41
16
42
class Solution :
17
43
@@ -34,8 +60,8 @@ def decode(self, str):
34
60
return result
35
61
36
62
37
- s = Solution ()
38
- input_list = ["sachin" , "jose" , "python" , "learning" , "leet" , "code" ]
39
- encode_str = s .encode (input_list )
40
- print (encode_str )
41
- print (s .decode (encode_str ))
63
+ # s = Solution()
64
+ # input_list = ["python", "learning", "leet", "code"]
65
+ # encode_str = s.encode(input_list)
66
+ # print(encode_str)
67
+ # print(s.decode(encode_str))
0 commit comments